SetParent() (win32)

问题描述 投票:0回答:1

有什么想法如何使用 SetParent() 吗?

以下似乎不起作用:

fhWnd = FindWindow(_T("Notepad"), NULL);

hWnd = CreateWindowEx(WS_EX_TOPMOST , _T("test"), _T("test"),
        WS_POPUP,
        20, 20, 400, 400, NULL, NULL, hInst, NULL);

 SetParent(hWnd, fhWnd);

 DWORD style = GetWindowLong(hWnd, GWL_STYLE);
 style = style & ~(WS_POPUP);
 style = style | WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
 SetWindowLong(hWnd, GWL_STYLE, style);
 SetWindowLong(fhWnd, GWL_STYLE, GetWindowLong(fhWnd, GWL_STYLE) | WS_CLIPCHILDREN);

使用上面的代码,我必须将父窗口移出屏幕并再次返回,才能查看子窗口上绘制的内容。

知道我做错了什么吗?

windows winapi user-interface
1个回答
0
投票

根据MSDN,请参阅下面的链接,在调用SetParent()之前应更改窗口样式。

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setparent?devlangs=cpp&f1url=%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(WINUSER %252FSetParent)%3Bk(SetParent)%3Bk(DevLang-C%252B%252B)%3Bk(TargetOS-Windows)%26rd%3Dtrue

在 SetParent() 之后,应该为子级和父级更新 UISTATE。我还在想这个问题。成功后我会更新。

SetParent() 之后的代码可选

// Now update the UIState for the child and the parent
WPARAM uistate_child  = LOWORD(UIS_INITIALIZE) + HIWORD(UISF_ACTIVE);
WPARAM uistate_parent = LOWORD(UIS_INITIALIZE) + HIWORD(UISF_ACTIVE);

BOOL result_child = SendMessage(hWnd, WM_CHANGEUISTATE, uistate_child, (LPARAM)0);

BOOL result_parent = SendMessage(fhWnd, WM_CHANGEUISTATE, uistate_parent, (LPARAM)0);

if (result_child != 0) { printf("\n\n Child -> Change UI State Error %i", GetLastError() ); }

if (result_parent != 0) { printf("\n\n Parent -> Change UI State Error %i", GetLastError() ); }
© www.soinside.com 2019 - 2024. All rights reserved.