Sign in to follow this  
Neonic148

window activation and deactivation

Recommended Posts

Hello, I have a windows fullscreen openGL application and wrote a function called "OnFocusChange(bool a)". When the user presses alt+tab, that function should be called with 'false' as an argument. When the user focusses the window again, the function should be called with the argument 'true'; The "OnFocusChange" function takes care of changing the screen settings (that's all for now). I have the following code in my WindowProc function:
LRESULT CALLBACK App::WndProc(HWND hWnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
bool activating;

if(!pApp) return DefWindowProc(hWnd, msg, wparam, lparam);

switch(msg)
{
case WM_ACTIVATE:

activating = ( (LOWORD(wparam) != WA_INACTIVE) && (HIWORD(wparam) == 0) );

if(activating!=pApp->window.active)pApp->window.OnFocusChange(activating);

return FALSE;
This code does make sure "OnFocusChange" is called on activating and deactivating the window, but there's a bug. "OnFocusChange" is also called when other windows are activated or deactivated, while the state of my application's window doesn't change. Does somebody see what's going wrong and how I could change the code to get what I want?

Share this post


Link to post
Share on other sites
Don't know if this is correct or not but in my code (not full screen) I have

WM_SETFOCUS and WM_KILLFOCUS. According to msdn:

The WM_SETFOCUS message is sent to a window after it has gained the keyboard focus.
The WM_KILLFOCUS message is sent to a window immediately before it loses the keyboard focus.

Perhaps you could try those instead.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this