有什么想法如何使用 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);
使用上面的代码,我必须将父窗口移出屏幕并再次返回,才能查看子窗口上绘制的内容。
知道我做错了什么吗?
根据MSDN,请参阅下面的链接,在调用SetParent()之前应更改窗口样式。
在 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() ); }