我正在编写一个在 Windows 上运行的屏幕保护程序。
在预览模式下,Windows 以这种方式调用程序:
Screensaver.exe /p ParentWindowHandle
但是,当我在我的程序中进行此调用时:
BOOL res = GetClientRect(parentWindowHandle, rect)
res 为 FALSE,rect 为 NULL,我得到ERROR_INVALID_WINDOW_HANDLE
了GetLastError()
GetWindowRect
给了我同样的结果。
但是,如果我改为调用BOOL res = IsWindow(parentWindowHandle)
,我会得到 res == TRUE。这不意味着我有一个有效的窗口句柄吗?
代码如下所示:
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
unsigned int handle = GetHandleFromCommandLine(pCmdLine); // Custom function (tested and approved :) )
HWND parentWindowHandle = (HWND) handle;
LPRECT rect = NULL;
BOOL res = GetClientRect(parentWindowHandle, rect);
// here, rect == NULL, res == FALSE and GetLastError() returns ERROR_INVALID_WINDOW_HANDLE
// ...
// ...
}