OBJECTIVE: To realize a form of free switching as a separate window state and as a state of another window body control. Difference: The difference between the two states is as follows:
State-style parent form separate window contains WS_POPUP styleless (NULL) sub-controls containing WS_ChildWindow style
It can be seen that to switch the status of the two needs to change the form style, and if there is no parent window, the interface function used is as follows.
Long_ptr setWindowlong (hwnd hwnd, // handle to window int nindex, // offset of value to set long dwnewlong // new value
); Specify NINDEX for GWL_Style to set the form of form style; 2. CWnd * CWnd :: setParent (CWND * PWndNewParent)
); Setting the form parent window The primary code is as follows: // m_pparentWnd is a member variable, used to save the form parent window pointer CEMBEDDLG :: ONSWitchState () {if (getParent ()! = Null) {// Current status m_pParentWnd = GetParent (); // change the window style, remove WS_CHILDWINDOW style, add WS_POPUP LONG lNewStyle = GetWindowLong (m_hWnd, GWL_STYLE); lNewStyle & = ~ WS_CHILDWINDOW; lNewStyle | = WS_POPUP; SetWindowLong (m_hWnd, GWL_STYLE, lNewStyle); // Set the parent window to null setparent (null);} else {// Currently a stand-alone form status // Change the form style long LNewStyle = getWindowlongPtr (m_hwnd, gwl_style); lnewstyle & = ~ ws_popup; lnewstyle | = ws_childwindow; SetWindowlong (M_HWND, GWL_STYLE, LNEWSTYLE); // Set the parent window setParent (m_pparentWnd);}} PS: If you want to drag the switch to implement the window status, consider handling WM_EXITSIZEMOVE messages, take a break