3

I'm very much newbie to VS Addins.

Although, I subscribed to DocumentEvent.DocumentOpened. But additionally, I need to detect if already opened document got focus and I will read its contents then.

How to get its focused state?

Thanks

Farrukh

skaffman
  • 398,947
  • 96
  • 818
  • 769
Farrukh Waheed
  • 2,163
  • 2
  • 29
  • 59

1 Answers1

2

Luckily, after playing some sample code, I've got what I want. Its actually EnvDTE.WindowEvents.

In VS IDE, every Code Document is also a Window. And it has the Focus event: WindowActivated. Here is my delegate to subscribe for this event:

WinEvents.WindowActivated += new _dispWindowEvents_WindowActivatedEventHandler(WinEvents_WindowActivated);

void WinEvents_WindowActivated(Window GotFocus, Window LostFocus)        
{            
   Debug.WriteLine("GotFocus: " + GotFocus.Caption );            
   //throw new NotImplementedException();        
}

Best regards

Farrukh

Farrukh Waheed
  • 2,163
  • 2
  • 29
  • 59