在现代版本的 Windows 上最小化 window 是否仍将其移动到坐标 (-32000, -32000)?
Does minimizing a window on a modern version of Windows still move it to coordinates (-32000, -32000)?
根据 Raymond Chen 的 this blog entry,Windows NT 通过将它们移动到坐标 (-32000, -32000) 来“最小化”windows,而且,我得到了印象通过阅读它,早期 版本的 Windows NT (3.x, 4...).
就是这种情况
在WindowsNT的现代版本中(如7、8、10),是否仍然如此?
是否可以编写一个程序来在现代 Windows OS 上演示此功能的 presence/absence?
回答我自己的问题...我已经编写了一个小的 C 程序来完成我的要求。基本上,它创建了一个 window 代码,如果 window 的位置在 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),表示window最小化时移动到的地方。
根据 Raymond Chen 的 this blog entry,Windows NT 通过将它们移动到坐标 (-32000, -32000) 来“最小化”windows,而且,我得到了印象通过阅读它,早期 版本的 Windows NT (3.x, 4...).
就是这种情况在WindowsNT的现代版本中(如7、8、10),是否仍然如此?
是否可以编写一个程序来在现代 Windows OS 上演示此功能的 presence/absence?
回答我自己的问题...我已经编写了一个小的 C 程序来完成我的要求。基本上,它创建了一个 window 代码,如果 window 的位置在 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),表示window最小化时移动到的地方。