一般来讲,通过函数SHFullScreen就可以实现,如通过如下调用SHFullScreen(hWnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON)即可实现,但有一个注意点,如果你的窗口里有MENU Bar 的话,则需要在全屏幕的时候隐藏MENU Bar可以调用SHGetMenuBar()来获取MENU的句柄,这里不能直接将HMENU用CAST成HWND,然后再使用ShowWindow(hWndMenu, SW_HIDE)来隐藏Menu。这样就是全屏的窗口了,返回非全屏模式,也是调用SHFullScreen()来实现,只是把里面的标志位置换成SHOW的就好。下面是例子代码: BOOL rb; BOOL chgScreen; int rc; RECT rect; HWND hWnd; rb = SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0); if (rb == FALSE) // SystemParametersInfo failed. { rc = MessageBox(NULL, _T("Could not get work area."), _T("Error"), MB_OK); if (rc == 0) // Not enough memory to create MessageBox. return E_OUTOFMEMORY; return E_FAIL; // Replace with specific error handling. } hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if (hWnd == NULL)// CreateWindow failed. { rc = MessageBox(NULL, _T("Could not create main window."), _T("Error"), MB_OK); if (rc == 0) // Not enough memory to create MessageBox. return E_OUTOFMEMORY; return E_FAIL; // Replace with specific error handling. } GetWindowRect(hWnd, &rect); chgScreen = SHFullScreen(hWnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON); if (chgScreen == FALSE); { // SHFullScreen failed. rc = MessageBox(NULL, _T("Could not modify the window."), _T("Error"), MB_OK); if (rc == 0) // Not enough memory to create MessageBox. return E_OUTOFMEMORY; return E_FAIL; // Replace with specific error handling. } MoveWindow( hWnd, rect.left, rect.top - MENU_HEIGHT, rect.right, rect.bottom + MENU_HEIGHT, TRUE);
BOOL CTestDlg::OnInitDialog() { ........ DWORD dwState = ( SHFS_HIDETASKBAR | SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON ); SHFullScreen( m_hWnd, dwState ); CRect rc; SetRect( &rc, 0, 0, GetSystemMetrics( SM_CXSCREEN ), GetSystemMetrics( SM_CYSCREEN ) ); MoveWindow( &rc, TRUE ); ......... } |