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);//显示时隐藏鼠标
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;
- }
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);
- }
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); }以上几种方法需要注意的是在注册窗口类中的菜单项,如果不显示菜单就要把lpszMenuName设为null,否则会在全屏的窗口上显示菜单。