Article ID: 129224
Article Last Modified on 11/21/2006
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT & cs)
{
// Call the base class version of PreCreateWindow, replace
// CMDIFrameWnd with CFrameWnd in the following line
// for an SDI application
if (!CMDIFrameWnd::PreCreateWindow(cs))
return FALSE;
// Remove the system menu style bit from the window
cs.style &= ~WS_SYSMENU;
return TRUE;
}
// In an SDI application CMainFrame will be derived from CFrameWnd
class CMainFrame : public CMDIFrameWnd
{
public:
BOOL sys_menu_enabled;
.
. // Existing class declarations
.
}
CMainFrame::CMainFrame()
{
//default the system menu to be enabled
sys_menu_enabled = TRUE;
.
. // Continue with normal constructor code, if any
.
}
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
// declare a local variable to hold the window style
long window_style;
//call base class's OnSize function,
//If SDI application call CFrameWnd::OnSize()
CMDIFrameWnd::OnSize(nType, cx, cy);
//if user is minimizing or iconizing the application
if (nType == SIZE_MINIMIZED)
{
// Get the main frame window's style
window_style = GetWindowLong(m_hWnd, GWL_STYLE);
//Remove the system menu from the window's style
window_style &= ~WS_SYSMENU;
//toggle the boolean data member to show sys menu disabled
sys_menu_enabled = FALSE;
//set the style attribute of the main frame window
SetWindowLong(m_hWnd, GWL_STYLE, window_style);
}
else
{
//if user is restoring the application and his system menu
//is disabled,
if ((nType == SIZE_RESTORED) || nType == SIZE_MAXIMIZED) &&
(!sys_menu_enabled))
{
window_style = GetWindowLong(m_hWnd, GWL_STYLE);
//Add the system menu to the window's style
window_style |= WS_SYSMENU;
//toggle the boolean data member to show sys menu enabled
sys_menu_enabled = TRUE;
SetWindowLong(m_hWnd, GWL_STYLE, window_style);
SendMessage(WM_NCACTIVATE,TRUE);
}
}
}Keywords: kbcode kbhowto kbmenu kbuidesign KB129224