非模态对话框失去焦点后销毁对话框?
这里响应ON_WM_ACTIVATE()事件,
对应的消息处理函数为:afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
nState有三种状态:
-
WA_INACTIVE The window is being deactivated.
-
WA_ACTIVE The window is being activated through some method other than a mouse click (for example, by use of the keyboard interface to select the window).
-
WA_CLICKACTIVE The window is being activated by a mouse click.
当窗口得到或失去焦点时,会触发这个消息.
我们接收到这个消息后,可以判断到底是哪一种状态.
失去焦点当然就得处理WA_INACTIVE消息,然后销毁掉窗口,代码如下:
-
这个函数之后会调用OnCancel消息去处理其它消息.
-
所有源代码如下:(注意,我在对话框模板资源里面添加了一个Slider Control)
-
调用: