Get focus changed event on Windows

I'd like to make something like a callback function which is executed every time the window focus has changed. Specifically, on Windows, ideally, on every platform.

Thank you

On Windows specifically, if your app's window gains or loses focus, you get the WM_SETFOCUS message (I think; it's been a while!)

If you want your app to detect any focus change, across the whole system (even if the user switches from app A to app B, where neither app is yours), then I don't know for sure, but this SO post looks promising: Windows/C++: detect when focus has changed between windows (globally) - Stack Overflow.

As for other operating systems, I don't know. There are lots of portable GUI toolkits (https://www.areweguiyet.com/), but I don't know if they support that event.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.