禁用窗口消息(无WNDPROC呼叫)

时间:2017-03-05 11:28:14

标签: windows winapi

所以我正在尝试为我的游戏编写一个切换全屏功能。

它工作..有点,问题是第一个SetWindowLongPtr()调用导致WM_SIZE消息排队并发送到我的WNDPROC(在MSDN我读取窗口样式的更改只缓存,必须是虽然使用SetWindowPos()应用。

SetWindowLongPtr(m_hWnd, GWL_STYLE, dwStyle);
SetWindowLongPtr(m_hWnd, GWL_EXSTYLE, dwExStyle);
SetWindowPos(m_hWnd, NULL, fullscreen ? 0 : window.left, fullscreen ? 0 : window.top, window.right, window.bottom, SWP_NOZORDER | SWP_FRAMECHANGED);
ShowWindow(m_hWnd, SW_SHOW);

当从窗口模式更改为全屏模式时,客户端区域会调整大小到窗口矩形并更新(因此现在'包含'条形图等)。 除了让我的程序两次破坏Vulkan上下文之外,这使得我保存了错误的窗口尺寸以便稍后恢复到窗口模式(这是在WM_SIZE发生时和游戏处于全屏模式时完成的。)

然后通过SetWindowPos()将其大小调整为正确的尺寸。

我的意思是我当然可以直接破解一个bool来丢弃WM_SIZE消息,但是我正在寻找更好的,也许更少的方法。 是否有暂时禁用窗口消息的功能或只是用户定义WNDPROC?

1 个答案:

答案 0 :(得分:0)

这是我用来打开和关闭全屏的功能。 我从Raymond Chen获得了这个功能。 我不知道它是否与Vulkan混淆,但它适用于OpenGL。

WINDOWPLACEMENT GlobalWindowPosition = {sizeof(GlobalWindowPosition)};
void ToggleFullscreen(HWND WindowHandle)
{
    DWORD Style = GetWindowLong(WindowHandle, GWL_STYLE);
    if(Style & WS_OVERLAPPEDWINDOW)
    {
        MONITORINFO MonitorInfo = {sizeof(MonitorInfo)};
        if(GetWindowPlacement(WindowHandle, &GlobalWindowPosition) &&
           GetMonitorInfo(MonitorFromWindow(WindowHandle, MONITOR_DEFAULTTOPRIMARY),
                          &MonitorInfo))
        {
            SetWindowLong(WindowHandle, GWL_STYLE,
                          Style & ~WS_OVERLAPPEDWINDOW);
            SetWindowPos(WindowHandle, HWND_TOP,
                         MonitorInfo.rcMonitor.left, MonitorInfo.rcMonitor.top,
                         MonitorInfo.rcMonitor.right - MonitorInfo.rcMonitor.left,
                         MonitorInfo.rcMonitor.bottom - MonitorInfo.rcMonitor.top,
                         SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
        }
    }
    else
    {
        SetWindowLong(WindowHandle, GWL_STYLE, Style | WS_OVERLAPPEDWINDOW);
        SetWindowPlacement(WindowHandle, &GlobalWindowPosition);
        SetWindowPos(WindowHandle, NULL, 0, 0, 0, 0,
                     SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
                     SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
    }
}
相关问题