Solution to window cannot be restored

Source: Internet
Author: User

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 );

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.