窗口在ShowWindow之后不接受按键(browserPtr,3)

Window do not accept key press after ShowWindow(browserPtr, 3)

本文关键字:browserPtr ShowWindow 之后 不接受 窗口      更新时间:2023-10-16

我的目标是从另一个进程停靠浏览器窗口进入我的应用程序。

我有一个面板hwnd,它将是一个父面板,以及浏览器窗口的hwnd。

这是一个代码:

ShowWindow(browserPtr, 3);
SetParent(browserPtr, browserContainerPanel.Handle);
MoveWindow(browserPtr, 0, 0, browserContainerPanel.Width, browserContainerPanel.Height, true);

在这种情况下,浏览器窗口变成了一个子窗口,并正确放置。但它停止接受键盘输入,无法集中焦点。

如果我不调用ShowWindow,除了窗口的位置和大小之外,所有操作都正常。Wihout ShowWindow我无法设置大小和位置。MoveWindow刚刚被忽略。

为什么停靠窗口不接受用户输入?我做错了什么?

更新

当前我的代码:

/// Attach container app input thread to the running app input thread, so that
///  the running app receives user input.
FAppThreadID = GetWindowThreadProcessId(window, new IntPtr());
AttachThreadInput(GetCurrentThreadId(), FAppThreadID, true);
/// Changing parent of the running app to our provided container control
SetParent(window, container);
SendMessage(container, WM_UPDATEUISTATE, UIS_INITIALIZE, 0);
UpdateWindow(window);
/// Make the running app to fill all the client area of the container
SetWindowPos(window, 0, 0, 0, 1000, 1000, SWP_NOZORDER);
SetForegroundWindow(window);

但在这种情况下,由于某些原因,窗口大小被忽略。然而,只要专注和投入,一切都可以。如何固定尺寸?

您还应该在浏览器窗口上调用SetFocus,以便向其发送用户输入。