6

根据Raymond Chen 的这篇博客文章,Windows NT 通过将它们移动到坐标(-32000,-32000)来“最小化”窗口,而且,我从阅读中得到的印象是早期版本的 Windows NT就是这种情况(3.x, 4...)。

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

是否有可以编写的程序来演示现代 Windows 操作系统上此功能的存在/不存在?

4

1 回答 1

4

回答我自己的问题...我已经编写了一个小型 C 程序,可以满足我的要求。基本上,它使用代码创建一个窗口,如果窗口的位置在 x 或 y 维度上更改为负值,它会将静态文本字段的文本设置为新坐标。

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

该程序的输出

#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),表示窗口最小化时移动到的位置。

于 2015-07-31T23:08:25.540 回答