Download demo and source code - 30 Kb
With the class
ISyncActiveImpl, of this article, you can have windows that synchronize the active state with a owner window.
- Windows that can synchronize the active state with a owner window;
- Windows that automatically hide when the application is deactivated and when the owner window is minimized or hidden;
- Windows that are automatically disabled when owner window is disabled.
I will base these examples in the source-code of the demo application included in this article.
Include the ISyncActiveImpl.h header file in your source-file.
Derive your class from
class CMainDlg :
, public ISyncActiveImpl<CMainDlg>
, public CMessageFilter
In your class constructor make sure that you instantiate
ISyncActiveImpl<> class with the right arguments for your type of window.
For example, for creating a dialog or frame window:
: ISyncActiveImpl<CMainDlg>(FALSE, TRUE)
Or for creating a floating or toolbar window:
In the message map of your class add a
NOTE: Make sure that you insert it on the first entry of the message map. This is needed because the
ISyncActiveImpl<> class will need to intercept some general messages (i.e.
Under the hood
The key for synchronizing the active state of a window lies on the
WM_NCACTIVATE message. By handling or sending this message we can force the painting of a window in the active or inactive state.
The automatically hide of a window is archived by handling the
The other two important messages that need to be handled are
WM_SHOWWINDOW, you can find information about them in source-code and at MSDN.
For ending, I just want to say that when implementing this class I have run into two "strange" activation problems, read all about them in the source-code.
Do you have any question or comment? Contact me!