C#: Detecting which application has focus

前端 未结 3 1780
星月不相逢
星月不相逢 2020-11-28 08:27

I\'m looking to create a C# application that changes content according to which application currently has focus. So if the user is using Firefox, my app would know that. Sam

3条回答
  •  情深已故
    2020-11-28 08:36

    Grrr. As is often the way, I spent some time Googling before posting this question.

    Once I finally posted the question, my next Google search revealed the answer.

    I've yet to test it, but it looks as though GetForegroundWindow() is the key.

    Rather than me rewrite what's already written, here's a link to the page that provided the information:

    http://www.csharphelp.com/2006/08/get-current-window-handle-and-caption-with-windows-api-in-c/

    Appologies for anyone's time I've wasted by asking a Googalable (?) answer.

提交回复
热议问题