How to detect a click outside a window

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • How to detect a click outside a window

    Hi,

    in my project I am using some windows as popups. They are half the area of the background window and are displayed centered in the screen. My problem is, I wanna close this popup when the user touches the screen outside the popup area, but I don't know how to detect this event. The best approach in my opinion is close the popup in its own callback, as it can be opened from any window it will be a bad design if I need to insert code in all windows that can be its background.

    Any advice in how to implement this behaviour?
  • Further information

    I have tried to implement the desired behaviour through the WM_TOUCH event. But I have noticed that this event is only received when the touch occurs inside the window. I am still missing the event that allow me to receive a touch performed outside the window.
  • Hi,

    With version 5.38 of emWin we introduced a finction named GUI_PID_SetHook(). This function allows the user to set a hook function which gets called every time a PID/Touch input gets send to emWin.

    Attached is an example how you could check if the touch is outside a specific window.

    If you are using a version before 5.38 you need to find another approach. In the sample I have used the function WM_Screen2hWin() which returns the handle of the window which lies under the input coordinates. Maybe this helps if using a version before 5.38.

    Regards,
    Sven
    Files
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.