Give focus to a Window launched from a system service using CreateProcessAsUser

扶醉桌前 提交于 2019-12-02 08:51:07

问题


I have a System service that launch an application using the method CreateProcessAsUser.

This service uses impersonation to launch the app in the active session. The Application is launching as it should, I managed to make the window appears on the front by using :

SetWindowPos( &this->wndTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE );

But I don't know what to do so the app can have the keyboard focus. Even if the app is on top, as long as the user hasn't clic on the window, the keyboard input goes to the application below my app.


回答1:


Let your application register a (carefully chosen) HotKey via RegisterHotKey and then simulate the key via SendInput

In the processing of the WM_HOTKEY message, you should be able to "steal the focus".

Remenber: It's BAD to steal focus, but I fully understand the "what my client is asking!" part.



来源:https://stackoverflow.com/questions/17451033/give-focus-to-a-window-launched-from-a-system-service-using-createprocessasuser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!