如何在 WTL 应用程序中设置 CWindowImpl FullScreen?

How to set CWindowImpl FullScreen in WTL application?

我正在查看 MFC SDI Cview 全屏示例应用程序:

https://www.codeproject.com/Articles/9632/Views-in-Full-Screen-Mode

我用WTL应用程序测试了全屏设置源代码,但是没有用。

我必须使用 SetWindowPlacement()/GetWindowPlacement() 函数吗?

void toggle_fullscreen()
{
  if (b_fullscreen == false)
  {
    b_fullscreen = true;
    save_window = this->GetParent();
    const HWND hwnd = GetDesktopWindow();
    this->SetParent(hwnd);
    RECT rect;
    ::GetWindowRect(hwnd, &rect);
    //m_view.SetWindowPos(hwnd, rect.left, rect.top, rect.right, rect.bottom, SWP_SHOWWINDOW);
    //m_view.SetWindowPos(HWND_TOPMOST, 0, 0, 4096, 2000, SWP_SHOWWINDOW);
    //m_view.ShowWindow(SW_MAXIMIZE);
    this->SetWindowPos(HWND_TOPMOST, 0, 0, 1920, 1080, SWP_SHOWWINDOW);
  }
  else
  {
    b_fullscreen = false;
    //m_view.SetParent(save_window);
    this->SetParent(save_window);
  }
}

编辑:

谢谢!其实我找到了源代码。 (感谢 Czarek Tomczak)

Win32: full-screen and hiding taskbar

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
  switch (msg)
  {
  case WM_CLOSE:
    DestroyWindow(hwnd);
    break;
  case WM_RBUTTONDOWN:
    printf("full screen\n");
    break;
  case WM_DESTROY:
    PostQuitMessage(0);
    break;
  default:
    return DefWindowProc(hwnd, msg, wParam, lParam);
  }
  return 0;
}

HWND CreateFullscreenWindow(HWND hwnd)
{ 

  WNDCLASSEX wc;
  wc.cbSize = sizeof(WNDCLASSEX);
  wc.style = 0;
  wc.lpfnWndProc = WndProc;
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hInstance = (HINSTANCE)::GetModuleHandle(NULL); 
  wc.hIcon = NULL;
  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1); // (HBRUSH)(COLOR_WINDOW + 1);
  wc.lpszMenuName = NULL;
  wc.lpszClassName = L"fullscreen";
  wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  RegisterClassEx(&wc);

 HMONITOR hmon = MonitorFromWindow(hwnd,
                                   MONITOR_DEFAULTTONEAREST);
 MONITORINFO mi = { sizeof(mi) };
 if (!GetMonitorInfo(hmon, &mi)) return NULL;
 return CreateWindowEx(NULL,
       TEXT("fullscreen"),
       TEXT(""),
       WS_POPUP | WS_VISIBLE,
       mi.rcMonitor.left,
       mi.rcMonitor.top,
       mi.rcMonitor.right - mi.rcMonitor.left,
       mi.rcMonitor.bottom - mi.rcMonitor.top,
       hwnd, NULL, wc.hInstance, 0);
}

Should i have to use SetWindowPlacement()... function?

可以,但不是必须。这和 SetWindowPos 以及其他 API 函数都是关于同一件事的:修改 window 的位置,使其完全覆盖对应于特定监视器的坐标,并将 window 设置为最顶层.这会创建一个 "full screen effect".

您找到的代码使用桌面 window 句柄并将您的 window 作为 child 停靠到它。这可能有效,但我不会这样做 - 我会创建一个标准的弹出窗口 window,无边框和无标题,而不需要 re-parent。我宁愿 re-parent child window 在 "normal" UI 和全屏弹出框架助手 window.

之间