gpt4 book ai didi

c++ - WinApi:将键盘焦点置于新线程中的新窗口

转载 作者:搜寻专家 更新时间:2023-10-31 01:48:40 25 4
gpt4 key购买 nike

当用户按下网页上的按钮时,我有一个浏览器插件调用的 dll。这个 dll 包含创建一个窗口(在新的 UI 线程中)的 native 代码,我需要这个窗口来获得键盘对其创建的关注(用户期望的行为)。我并不是想在用户面前弹出不需要的弹出窗口。

我尝试过使用 SetForegroundWindow()、SetFocus()、BringWindowToTop()、AttachThreadInput()、最小化/恢复窗口,随便你怎么说,我都试过了。我取得的最大进步是让新窗口在任务栏中闪烁。

我需要这样做的原因是因为我需要考虑键盘的可访问性,并允许用户使用我的新窗口而无需使用 alt-tab 键。

有没有人对如何在此处获得键盘焦点有任何建议?

最佳答案

如果窗口在任务栏上闪烁,那么您的代码不符合 SetForegroundWindow() documentation 中列出的要求:

A process can set the foreground window only if one of the following conditions is true:

The process is the foreground process.

The process was started by the foreground process.

The process received the last input event.

There is no foreground process.

The foreground process is being debugged.

The foreground is not locked (see LockSetForegroundWindow).

The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).

No menus are active.

An application cannot force a window to the foreground while the user is working with another window. Instead, Windows flashes the taskbar button of the window to notify the user.

关于c++ - WinApi:将键盘焦点置于新线程中的新窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17475717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com