from:http://blog.csdn.net/leolee82/article/details/6992615
windows編程 全屏窗口的創建總結
第一種:較簡單的方法
在ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);前加如下代碼:
- LONG style = GetWindowLong(hwnd,GWL_STYLE);//獲得窗口風格
- style = &~WS_CAPTION & ~WS_SIZEBOX;//窗口全屏顯示且不可改變大小
- SetWindowLong(hwnd,GWL_STYLE,style); //設置窗口風格
- int screenX = GetSystemMetrics(SM_CXSCREEN);//獲取整個屏幕右下角X坐標
- int screenY = GetSystemMetrics(SM_CYSCREEN);//屏幕Y坐標
- SetWindowPos(hwnd, NULL,0,0,screenX,screenY,SWP_NOZORDER);//改變窗口位置、尺寸和Z序
- ShowCursor(FALSE);//顯示時隱藏鼠標
第二種:在按下esc后實現全屏
- switch (message)
- {
- case WM_KEYDOWN:
- switch(wParam)
- {
- case VK_ESCAPE:
- {
- HWND hDesk;
- RECT rc;
- hDesk = GetDesktopWindow();
- GetWindowRect( hDesk, &rc );
- SetWindowLong( hWnd, GWL_STYLE, WS_BORDER );
- SetWindowPos( hWnd, HWND_TOPMOST,0,0, rc.right, rc.bottom,
- SWP_SHOWWINDOW);
- }
- break;
- }
- return 0;
- }
第三種:在消息中加入一下代碼
- static int cx, cy, cxDib, cyDib;
- hdc=::GetDC(NULL);
- switch (message)
- {
- case WM_CREATE:
- cx = GetDeviceCaps(hdc,HORZRES) +
- GetSystemMetrics(SM_CXBORDER);
- cy = GetDeviceCaps(hdc,VERTRES) +
- GetSystemMetrics(SM_CYBORDER);
- ::ReleaseDC(0,hdc);
- //去除標題和邊框
- SetWindowLong(hWnd, GWL_STYLE,
- GetWindowLong(hWnd, GWL_STYLE) &
- (~(WS_CAPTION | WS_BORDER)));
- // 置對話框為最頂端並擴充到整個屏幕
- ::SetWindowPos(hWnd, HWND_TOPMOST,
- -(GetSystemMetrics(SM_CXBORDER)+1),
- -(GetSystemMetrics(SM_CYBORDER)+1),
- +1,cy+1, SWP_NOZORDER);
- }