views:

1352

answers:

4

I want to capture events that close editor window (tab) in Visual Studio 2008 IDE. When I use dte2.Application.Events.get_CommandEvents(null, 0).BeforeExecute I successfully captured such events:

  • File.Close
  • File.CloseAllButThis
  • File.Exit
  • Window.CloseDocumentWindow and others.

If code in window is not acceptable, I stop the event (CancelDefault = true).

But if I click "X" button on the right hand side, "Save Changes"; dialog appears, tab with editor window close and I have no any captured events. In this case I can capture WindowClosing event, but can not cancel the event.

Is it poosible to handle "x" button click and stop event?

A: 

No sorry, You should use an x-enabled language such as VB.NET.

VB.NET compiles itself to assmbly language that can be run on any of the following:

  • Windows 2000
  • Windows ME
  • Windows NT
  • Windows XP
  • Sql Server

I suggest you read the manual available here about the VB.NET event handler system.

function enable-unicode(int as string) begin
   capture 'x' as handle code.
   enable-unicode = True
end procedure
Denk Hanners
If you question had better phrasing or english tone to it we might be able to give you a more specific answer sorry :(
Denk Hanners
A: 

If you're willing to use some Windows API code you might be able to set up a hook using the SetWindowsHookEx function to intercept WM_CLOSE, WM_QUIT and WM_DESTROY.

ho1
+1  A: 

In C# it would be something like this: you add Closing event handler and then

void MyWindow_Closing(object sender, CancelEventArgs e)
        {
          if(something)
                e.Cancel = true;   //<- thats the magic part you want
}
m0s
A: 

I would suggest, check on the lines of handling MDI Child window events!!

The editor tab you are referring is basically an instance of MDI Child Window.

Hope this helps!

System.ArgumentException