Programming Tips - MFC: Do something when my window is shown or hidden.

Date: 2018dec11 Framework: MFC OS: Windows Platform: win32 Language: C++ Q. MFC: Do something when my window is shown or hidden. A. You can want the WM_SHOWWINDOW message In your .h add:
//{{AFX_MSG(CMyWindow) ... afx_msg void OnShowWindow(BOOL bShow, UINT nStatus); //}}AFX_MSG
In your .cpp add:
BEGIN_MESSAGE_MAP(CMyWindow, CMyBaseClass) //{{AFX_MSG_MAP(CMyWindow) ... ON_WM_SHOWWINDOW() //}}AFX_MSG_MAP END_MESSAGE_MAP()
And
void CMyWindow::OnShowWindow(BOOL bShow, UINT nStatus) { if (bShow) { // We are being shown } else { // We are being hidden } }
nStatus is the parameter that was passed to ShowWindow. Such as SW_HIDE, SW_SHOW, etc. https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-showwindow