小编Jac*_*ack的帖子

c ++ WinApi:GetClientRect失败

我正在编写在Windows上运行的屏幕保护程序.

在预览模式下,Windows以这种方式调用程序:
Screensaver.exe /p ParentWindowHandle

但是,当我在我的程序中进行此调用时:
BOOL res = GetClientRect(parentWindowHandle, rect)
res为FALSE,rect为NULL,我得到ERROR_INVALID_WINDOW_HANDLEGetLastError()

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

    // ...
    // ... …
Run Code Online (Sandbox Code Playgroud)

c++ winapi screensaver

3
推荐指数
1
解决办法
4104
查看次数

标签 统计

c++ ×1

screensaver ×1

winapi ×1