Search code examples
eventsvisual-studio-2012visual-studio-addins

How to detect if the current instance of visual studio is active when writing a VS2012 addin?


I want to be able to detect when the current instance of visual studio is active or in active, but searching through the available hookable events in the _applicationObject.Events. collection has not given me any clues. I can see when a window within the application is activated/deactivated with _applicationObject.Events.WindowEvents.WindowActivated, but this is not going to help. I want to know when the who application is active, not just a document or window.

Any help appreciated.


Solution

  • You can get the DTE.MainWindow.HWnd handle and use the Win32 API.