Windows全屏代码--摘自Chrome
2021-01-24 05:14
标签:method task tps 浏览器 man eth multi 一个 resize 变量定义: 实现代码: 参考: 1. https://stackoverflow.com/questions/2382464/win32-full-screen-and-hiding-taskbar,第一个高赞回答。 2.https://github.com/chromium/chromium/blob/master/ui/views/win/fullscreen_handler.cc, chromium 浏览器源代码。 Windows全屏代码--摘自Chrome 标签:method task tps 浏览器 man eth multi 一个 resize 原文地址:https://www.cnblogs.com/2018shawn/p/12054413.html typedef struct SCREEN_INFO
{
DWORD dwStyle;
DWORD dwExStyle;
CRect rect;
bool bMaximized;
}SreenInfo;
SreenInfo m_screenInfo;
bool m_bFullScreen = false;
if (!m_bFullScreen)
{
// Save current window information. We force the window into restored mode
// before going fullscreen because Windows doesn‘t seem to hide the
// taskbar if the window is in the maximized state.
m_screenInfo.bMaximized = !!::IsZoomed(this->m_hWnd);
// if (m_screenInfo.bMaximized)
// ::SendMessage(this->m_hWnd, WM_SYSCOMMAND, SC_RESTORE, 0);
m_screenInfo.dwStyle = GetWindowLongPtr(this->m_hWnd, GWL_STYLE);
m_screenInfo.dwExStyle = GetWindowLongPtr(this->m_hWnd, GWL_EXSTYLE);
GetWindowRect(m_screenInfo.rect);
}
m_bFullScreen = !m_bFullScreen;
if (m_bFullScreen)
{
// Set new window style and size.
SetWindowLongPtr(this->m_hWnd, GWL_STYLE,
m_screenInfo.dwStyle & ~(WS_CAPTION | WS_THICKFRAME));
SetWindowLongPtr(this->m_hWnd, GWL_EXSTYLE,
m_screenInfo.dwExStyle & ~(WS_EX_DLGMODALFRAME |
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE));
// On expand, if we‘re given a window_rect, grow to it, otherwise do
// not resize.
bool for_metro = false;
if (!for_metro)
{
MONITORINFO monitor_info;
monitor_info.cbSize = sizeof(monitor_info);
GetMonitorInfo(MonitorFromWindow(this->m_hWnd, MONITOR_DEFAULTTONEAREST), & monitor_info);
CRect window_rect(monitor_info.rcMonitor);
SetWindowPos(NULL, window_rect.left, window_rect.top,
window_rect.Width(), window_rect.Height(),
SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
}
}
else
{
// Reset original window style and size. The multiple window size/moves
// here are ugly, but if SetWindowPos() doesn‘t redraw, the taskbar won‘t be
// repainted. Better-looking methods welcome.
SetWindowLongPtr(this->m_hWnd, GWL_STYLE, m_screenInfo.dwStyle);
SetWindowLongPtr(this->m_hWnd, GWL_EXSTYLE, m_screenInfo.dwExStyle);
// On restore, resize to the previous saved rect size.
CRect new_rect(m_screenInfo.rect);
SetWindowPos(NULL, new_rect.left, new_rect.top,
new_rect.Width(), new_rect.Height(),
SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
}
文章标题:Windows全屏代码--摘自Chrome
文章链接:http://soscw.com/index.php/essay/46187.html