Win32 中在正常模式和全屏模式之间切换

问题描述 投票:0回答:1

我创建了一个在正常模式和全屏模式之间切换窗口的函数。如果宽度参数等于0,窗口将处于全屏模式。否则,它将处于正常屏幕模式,并且将取决于其高度和宽度参数中的大小。

// width equle 0 = fullscreen, other 0 = normal window
void CL_fulscrn(HWND hwnd, const unsigned short W, const unsigned short H) {
    if (!W) {
        SetWindowLongPtr(hwnd, GWL_EXSTYLE, 0);
        SetWindowLongPtr(hwnd, GWL_STYLE, WS_VISIBLE | WS_POPUP);
        MoveWindow(hwnd, 0, 0, GetDeviceCaps(GetDC(NULL), HORZRES), GetDeviceCaps(GetDC(NULL), VERTRES), 0);
    }
    else {
        SetWindowLongPtr(hwnd, GWL_EXSTYLE, WS_EX_APPWINDOW);
        SetWindowLongPtr(hwnd, GWL_STYLE, WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_THICKFRAME | WS_VISIBLE | WS_OVERLAPPED);
        MoveWindow(hwnd, (GetDeviceCaps(GetDC(NULL), HORZRES) - W) / 2, (GetDeviceCaps(GetDC(NULL), VERTRES) - H) / 2, W, H, 0);
    }
}

在全屏模式下,窗口很好,但切换到正常模式时:在此处输入图像描述

那为什么?

我尝试将MoveWindow函数更改为SetWindowPos函数:

// width equle 0 = fullscreen, other 0 = normal window
void CL_fulscrn(HWND hwnd, const unsigned short W, const unsigned short H) {
    if (!W) {
        SetWindowLongPtr(hwnd, GWL_EXSTYLE, 0);
        SetWindowLongPtr(hwnd, GWL_STYLE, WS_VISIBLE | WS_POPUP);
        SetWindowPos(hwnd, 0, 0, 0, GetDeviceCaps(GetDC(NULL), HORZRES), GetDeviceCaps(GetDC(NULL), VERTRES), SWP_NOZORDER);
    }
    else {
        SetWindowLongPtr(hwnd, GWL_EXSTYLE, WS_EX_APPWINDOW);
        SetWindowLongPtr(hwnd, GWL_STYLE, WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_THICKFRAME | WS_VISIBLE | WS_OVERLAPPED);
        SetWindowPos(hwnd, 0, (GetDeviceCaps(GetDC(NULL), HORZRES) - W) / 2, (GetDeviceCaps(GetDC(NULL), VERTRES) - H) / 2, W, H, SWP_NOZORDER);
    }
}

但是同样的问题。

c windows winapi fullscreen
1个回答
0
投票

正如@Raymond Chen所说,你需要在

SWP_FRAMECHANGED
中传递
SetWindowPos
来表明你已经改变了非客户区。 enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.