void CSkinBase::InitSysMenu(HMENU hMenu, HWND hWnd) { // iterate all the menu items looking for something resembling a sys menu item int nItem = GetMenuItemCount(hMenu); CWindow cWnd; cWnd.Attach( hWnd ); while (nItem--) { UINT uID = GetMenuItemID(hMenu, nItem); if (uID >= 0xF000) { BOOL bEnable = TRUE; switch (uID & 0xFFF0) { case SC_MINIMIZE: bEnable = (cWnd.GetStyle() & WS_MINIMIZEBOX) && !cWnd.IsIconic(); break; case SC_MAXIMIZE: bEnable = (cWnd.GetStyle() & WS_MAXIMIZEBOX) && !cWnd.IsZoomed(); break; case SC_RESTORE: bEnable = cWnd.IsIconic() || cWnd.IsZoomed(); break; case SC_MOVE: case SC_SIZE: bEnable = !cWnd.IsIconic() && !cWnd.IsZoomed(); break; } EnableMenuItem(hMenu, uID, bEnable ? MF_ENABLED : MF_GRAYED); } } // set close as default item SetMenuDefaultItem(hMenu, SC_CLOSE, FALSE ); }
//The following example attaches an HWND to the CWindow object and //calls CWindow::GetStyle() to retrieve the styles of the window CWindow myWindow; myWindow.Attach(hWnd); DWORD dwStyles = myWindow.GetStyle();