After the program is minimized, it cannot be restored because at least one popup window exists in the program, because the child window of the popup type is hidden even because of the hidden parent window, its ws_visible attribute is still visible. When you click the program icon in the taskbar again, the popup window will intercept system (Restore) messages so that the main program framework cannot receive system messages, as a result, the main program cannot be restored normally. If you change it to a child-type window, the function of minimizing and restoring the main program will be normal. However, in actual projects, a popup window is often required as a subwindow (a popup window can also have a parent window ), so how can we solve the problem that the program cannot be restored after being minimized? According to the above analysis principle, as long as the main program is minimized, the popup window (showwindow (sw_hide) is also hidden, so that the system message can be correctly transmitted; when the main program is restored, the hidden popup window is displayed, so that the display effect of the program is not affected and the problem can be solved! The specific method is as follows:
First, you must intercept system messages in the main program (such as mainframe) (where the response is maximized, minimized, restored, and closed ). The message is wm_syscommand. For example, add afx_msg void onsyscommand (uind NID, lparam) to the mainframe. cpp header file, and add on_wm_syscommand between begin_map and end_map of mainframe. cpp. The response function is
Void cmainframe: onsyscommand (uind NID, lparam ){}.
Then, the popup window is hidden and displayed based on the system message. The Code is as follows:
Cwnd * m_ppopupwnd; // window pointer of the popup type
Void cmainframe: onsyscommand (uind NID, lparam)
{
Static bool s_bdialogvisible = false;
/// If the message is minimized
If (SC _minimize = NID)
{
If (null! = M_ppopupwnd &: iswindow (m_ppopupwnd-> m_hwnd ))
{
If (: iswindowvisible (m_ppopupwnd-> m_hwnd ))
{
S_bdialogvisible = true;
/// Hide the popup window
M_ppopupwnd-> showwindow (sw_hide );
}
}
}
Else
{
If (null! = M_ppopupwnd &: iswindow (m_ppopupwnd-> m_hwnd ))
{
If (true = s_bdialogvisible)
{
S_bdialogvisible = false;
/// Display the popup window
M_ppopupwnd-> showwindow (sw_show );
}
}
}
Cwnd: onsyscommand (NID, lparam );
}