根据Raymond Chen的this blog entry所述,Windows NT通过将窗口移至坐标(-32000,-32000)来“最小化”窗口,并且,在声明该句子的上下文中,这意味着早期情况就是这种情况。版本的Windows NT(3.x,4 ...)。

在现代版本的Windows NT(例如7、8和10)中,是否仍然如此?

是否可以编写一个程序来演示现代Windows OS上此功能的存在/不存在?

最佳答案

回答我自己的问题...我编写了一个小型C程序,该程序可以完成我所要求的。基本上,它使用代码创建一个窗口,这样,如果窗口的位置在x或y方向上更改为负值,它将把静态文本字段的文本设置为新坐标。

在Windows 10 RTM上此程序的输出:

screen - 在现代版本的Windows上最小化窗口是否还会将其移至坐标(-32000,-32000)?-LMLPHP

#include <Windows.h>
#include <tchar.h>
#include <strsafe.h>

TCHAR g_szClassName[] = _T("CoordReportWnd");

LRESULT CALLBACK WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK EnumChildProc(HWND hWnd, LPARAM lParam);

ATOM RegisterWCEX(HINSTANCE hInstance)
{
    WNDCLASSEX wcex;
    ZeroMemory(&wcex, sizeof(WNDCLASSEX));

    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.lpfnWndProc = WindowProc;
    wcex.hInstance = hInstance;
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = g_szClassName;
    wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.style = 0;

    return RegisterClassEx(&wcex);
}

BOOL CALLBACK EnumChildProc(HWND hWnd, LPARAM lParam)
{
    HFONT hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
    SendMessage(hWnd, WM_SETFONT, (WPARAM)hfDefault, 0);
    return TRUE;
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    HWND hWnd, hStatic;
    MSG Msg;

    if (!RegisterWCEX(hInstance))
    {
        MessageBox(0, _T("Window registration failed!"), _T("Error"), MB_ICONSTOP);
        return -1;
    }

    hWnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, g_szClassName, _T("Minimize Me"), WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX, 100, 100, 200, 150, NULL, NULL, GetModuleHandle(NULL), NULL);
    hStatic = CreateWindow(_T("Static"), _T(""), WS_VISIBLE | WS_CHILD, 10, 10, 180, 20, hWnd, NULL, GetModuleHandle(NULL), NULL);
    ShowWindow(hWnd, SW_SHOW);
    EnumChildWindows(hWnd, EnumChildProc, 0L);
    UpdateWindow(hWnd);

    while (GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}

LRESULT CALLBACK WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
    switch (Msg)
    {
    case WM_CLOSE:
        DestroyWindow(hWnd);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    case WM_WINDOWPOSCHANGED:
    {
        PWINDOWPOS pWP = (PWINDOWPOS)lParam;
        if (pWP->x < 0 || pWP->y < 0)
        {
            TCHAR stTxt[64];
            HWND hStatic = FindWindowEx(hWnd, NULL, _T("Static"), NULL);
            StringCchPrintf(stTxt, 64, _T("(%d, %d)"), pWP->x, pWP->y);
            SetWindowText(hStatic, stTxt);
        }
    }
    default:
        return DefWindowProc(hWnd, Msg, wParam, lParam);
    }
    return 0;
}

运行时,如果将其最小化然后重新最大化,则显示(-32000,-32000),指示将窗口最小化后即移至该位置。

关于screen - 在现代版本的Windows上最小化窗口是否还会将其移至坐标(-32000,-32000)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31755601/

10-12 05:09