Show and hide of the title bar

xiaoxiao2021-03-06  66

Show and hide of the title bar

Author:

Rockieyung

Sometimes the title strip is hidden or displayed for some reason for the actual display area or some reason. This article uses a simple example to explain how to implement it in the framework of the MFC application. The method of using the API can also be used in other Windows application development environments.

The CWnd class provides a function modifyStyle (), which is used to change the style of the window. The prototype is as follows: BOOL ModifyStyle (DWORD DWREMOVE, DWORD DWADD, UINT NFLAGS = 0); in which the parameter dwremove is the desired window style, the parameter dWadd is hope plus The window style, parameter nflags is used to determine the size and location of the window.

The following uses an MFC MDI application as an example: (function and code are not separated, feel can't be 1, 2, 3) 1. Add a menu item, ID_view_title_bar, and use the class wizard to generate the message function onViewTitlebar and OnUpdateViewTitlebar with the class wizard. 2. Add a BOOL-type member variable M_bviewTitlebar to CMAINFRAME and assign true3 in the constructor. Add the following implementation for OnViewTitlebar

Void CMAINFRAME :: OnViewTitlebar ()

{

m_bviewtitlebar =! m_bviewtitlebar;

IF (m_bviewtitlebar == false) {// Hide Titlebar

ModifyStyle (WS_CAPTION, 0, SWP_FRAMECHANGED);

}

Else {// Show Titlebar

ModifyStyle (0, WS_CAPTION, SWP_FRAMECHANGED);

}

}

4. Add the following implementation for OnUpdateViewTitlebar

Void CMAINFRAME :: OnUpdateViewTitlebar (ccmdui * pcmdui)

{

PCMDUI-> SetCheck (M_BViewTitlebar);

}

ModifyStyle actually calls three API functions internally, and onviewTitlebar can also use the API to be implemented.

Void CMAINFRAME :: OnViewTitlebar ()

{

m_bviewtitlebar =! m_bviewtitlebar;

Long LStyle = :: getWindowlong (this-> m_hwnd, gwl_style);

IF (m_bviewtitlebar == false) {// Hide Titlebar

:: setwindowlong (this-> m_hwnd, gwl_style, lstyle & ~ ws_caption);

:: SetWindowPos (this-> m_hwnd, null, 0, 0, 0, 0,

SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE |

SWP_FRAMECHANGED);

}

Else {// Show Titlebar

:: setwindowlong (this-> m_hwnd, gwl_style, lstyle | ws_caption);

:: SetWindowPos (this-> m_hwnd, null, 0, 0, 0, 0,

SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE |

SWP_FRAMECHANGED);

}

转载请注明原文地址:https://www.9cbs.com/read-90523.html

New Post(0)