1: 用于隐藏、显示任务栏、开始菜单、输入面板,BOOL SHFullScreen( HWND hwndRequester, DWORD dwState)
MSDN里的参考代码:
#include <aygshell.h>
LRESULT CALLBACK SHFullScreenWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static fFullScreen = FALSE; switch (message) { case WM_KEYDOWN: { // Toggle between full screen and normal mode when the user presses the space bar. if (VK_SPACE == wParam) { DWORD dwState; RECT rc; if (fFullScreen) { // To switch to normal mode, first show all of the shell parts. dwState = (SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON); SHFullScreen(hwnd, dwState); // Next resize the main window to the size of the work area. SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, FALSE); MoveWindow(hwnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, TRUE); fFullScreen = !fFullScreen; } else { // To switch to full screen mode, first hide all of the shell parts. dwState = (SHFS_HIDETASKBAR | SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON); SHFullScreen(hwnd, dwState); // Next resize the main window to the size of the screen. SetRect(&rc, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); MoveWindow(hwnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, TRUE); fFullScreen = !fFullScreen; } } } break; } return DefWindowProc(hwnd, message, wParam, lParam); } |
2:获取桌面分辨率,下面2种方法都可以
a:SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, FALSE)
b:GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN)
3:重置窗口,BOOL MoveWindow( HWND hWnd, int X, int Y, int nWidth, int nHeight, BOOL bRepaint );
#include <windows.h> #include <aygshell.h>
LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { WNDCLASS wc; HWND hWnd; MSG msg;
// Register application main window class. wc.style = 0; // Window style wc.lpfnWndProc = MainWndProc; // Callback function wc.cbClsExtra = 0; // Extra class data wc.cbWndExtra = 0; // Extra window data wc.hInstance = hInstance; // Owner handle wc.hIcon = NULL, // Application icon wc.hCursor = LoadCursor (NULL, IDC_ARROW);// Default cursor wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wc.lpszMenuName = NULL; // Menu name wc.lpszClassName = TEXT("MyClass"); // Window class name
if (RegisterClass (&wc) == 0) return -1;
// Create main window. hWnd = CreateWindowEx(WS_EX_NODRAG, // Ex style flags TEXT("MyClass"), // Window class TEXT("Hello"), // Window title // Style flags //WS_VISIBLE | WS_CAPTION | WS_SYSMENU, WS_VISIBLE, CW_USEDEFAULT, // x position CW_USEDEFAULT, // y position CW_USEDEFAULT, // Initial width CW_USEDEFAULT, // Initial height NULL, // Parent NULL, // Menu, must be null hInstance, // Application instance NULL); // Pointer to create // parameters if (!IsWindow (hWnd)) return -2; // Fail code if not created.
// Standard show and update calls ShowWindow (hWnd, nCmdShow); UpdateWindow (hWnd);
// Application message loop while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } // Instance cleanup return msg.wParam; }
LRESULT CALLBACK MainWndProc (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; RECT rect; HDC hdc; RECT rc;
switch (wMsg) { case WM_PAINT: // Get the size of the client rectangle GetClientRect (hWnd, &rect);
hdc = BeginPaint (hWnd, &ps); DrawText (hdc, TEXT ("Hello World!"), -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
EndPaint (hWnd, &ps);
SHFullScreen(hWnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON);
//效果1 // SetRect(&rc, 0, 0, GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN)); // MoveWindow( hWnd,rc.left, rc.top,rc.right, rc.bottom,FALSE);
//效果2 SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, FALSE); MoveWindow(hWnd, rc.left, rc.top, rc.right, rc.bottom, TRUE);
return 0;
case WM_DESTROY: PostQuitMessage (0); break; } return DefWindowProc (hWnd, wMsg, wParam, lParam); }
|
效果1:
效果2:
具体可以参考SDK Samples:/Common/CPP/Win32/FullScreen