C++如何实现窗口全屏显示

窗口全屏,直接上代码:

void FullScreen(HWND hwnd) {
  //去掉所有边框,解决虚拟机win10任务栏显示问题
  DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);
  DWORD style_ex = ::GetWindowLong(hwnd, GWL_EXSTYLE);
  SetWindowLong(hwnd, GWL_STYLE, style & ~(WS_CAPTION | WS_THICKFRAME));
  SetWindowLong(hwnd, GWL_EXSTYLE,
    style_ex & ~(WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE |
      WS_EX_CLIENTEDGE | WS_EX_STATICEDGE));
  MONITORINFO monitor_info;
  monitor_info.cbSize = sizeof(monitor_info);
  GetMonitorInfo(MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST),
    &monitor_info);
  RECT desktop_rect = monitor_info.rcMonitor;
  SetWindowPos(hwnd, NULL, desktop_rect.left, desktop_rect.top,
    desktop_rect.right - desktop_rect.left,
    desktop_rect.bottom - desktop_rect.top,
    SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
}

本文为@艺文笔记原创文章,转载请注明出处:https://www.xuwenyan.com/archives/463,非常感谢!
上一篇:  下一篇: