WM_NCACTIVATE

By handling this message we can make an active window's frame appear to be inactive and vice versa.

MSDN (May 2011) suggests handling the message by returning true or false. For example:

case WM_NACTIVATE:
   if ( FALSE == wParam )
      return TRUE;

Each of the red words can be TRUE or FALSE. Here are the effects of the four possible combinations (tested on Vista):


 Effect on messaged window  Effect on child window
 if TRUE... TRUE;  Always looks inactive  Normal
 if TRUE... FALSE;
"
"
 if FALSE... TRUE;  Always looks active
"
 if FALSE... FALSE
"
 Never activates

Here's what happens when the "if" is omitted:

 Effect on messaged window  Effect on child window
 Always return TRUE  Always looks inactive  Normal
 Always return FALSE
"
 Never activates

That's one way to handle the message. Other sources (including Raymond Chen) suggest handling it by passing the message to DefWindowProc with a changed wParam:

case WM_NACTIVATE:
   if ( FALSE == wParam )
      return DefWindowProc ( hwnd, msg, TRUE, lParam );

Here are the effects of the four possible combinations (tested on Vista):


 Effect on messaged window  Effect on child window
 if TRUE... TRUE;  Normal  Normal
 if TRUE... FALSE;  Always looks inactive
 Normal
 if FALSE... TRUE;  Always looks active  Normal
 if FALSE... FALSE
 Normal
 Normal

Here's what happens when the "if" is omitted and TRUE or FALSE is passed unconditionally to DefWindowProc:

 Effect on messaged window  Effect on child window
Always pass TRUE  Always looks active  Normal
Always pass FALSE  Always looks inactive
 Normal

The second way of handling the message, as summarized in the final table above, seems most useful.

Links

WM_NCACTIVATE on MSDN
WM_NCACTIVATE on Raymond Chen's Old New Thing
Catch 22

This page was last updated on May 24, 2011

Copyright 2009–2011 Robert Sacks