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?
  • 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