我正在研究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);
}
答案 0 :(得分:1)
我是否必须使用SetWindowPlacement()... function?
你可以,但你不必。这和SetWindowPos以及其他API函数大致相同:修改窗口的位置,使其完全覆盖与特定监视器对应的坐标,并将窗口设置为最顶层。这会产生“全屏效果”。
您找到的代码使用桌面窗口句柄,并将您的窗口作为子项停靠。这可能有用,但我不会这样做 - 我会创建一个标准的弹出窗口,无边框和无标题,而无需重新设置它。我宁愿在“普通”UI和全屏弹出框架帮助窗口之间重新设置子窗口。