Determine Whether Program is the Active Window in .NET

前端 未结 3 1109
你的背包
你的背包 2020-12-11 10:27

I have a C#/.NET app and I want to implement the following behavior:

I have a popup menu. Whenever the user clicks on anything within the application that

3条回答
  •  一向
    一向 (楼主)
    2020-12-11 10:45

    You could P/Invoke into GetForegroundWindow(), and compare the HWND returned to the application's form.Handle property.

    Once you have the handle, you can also P/Invoke GetAncestor() to get the root owner window. This should be the handle of your application's main, startup window, if this is in your application.

提交回复
热议问题