Bringing Window to the Front in C# using Win32 API

前端 未结 6 1705
生来不讨喜
生来不讨喜 2020-12-09 01:46

I am writing an application that needs to bring window of an external app to the foreground, and not necessarily steal focus (there is a setting the user can toggle to steal

6条回答
  •  春和景丽
    2020-12-09 02:27

    SetForegroundWindow is supposed to steal focus and there are certain cases where it will fail.

    The SetForegroundWindow function puts the thread that created the specified window into the foreground and activates the window. Keyboard input is directed to the window

    Try capturing the focus with SetCapture prior to making the call. Also look into different ways of bringing the window to the front: SetForeGroundWindow, SetActiveWindow, even simulating a mouse click can do this.

提交回复
热议问题