简体   繁体   English

捕获窗口关闭事件

[英]Capture window close event

I want to capture events that close editor window (tab) in Visual Studio 2008 IDE. 我想捕获在Visual Studio 2008 IDE中关闭编辑器窗口(选项卡)的事件。 When I use dte2.Application.Events.get_CommandEvents(null, 0).BeforeExecute I successfully captured such events: 当我使用dte2.Application.Events.get_CommandEvents(null,0).BeforeExecute我成功捕获了这样的事件:

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

If code in window is not acceptable, I stop the event (CancelDefault = true). 如果窗口中的代码不可接受,我会停止该事件(CancelDefault = true)。

But if I click "X" button on the right hand side, "Save Changes"; 但如果我点击右侧的“X”按钮,“保存更改”; 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. 在这种情况下,我可以捕获WindowClosing事件,但无法取消该事件。

Is it poosible to handle "x" button click and stop event? 处理“x”按钮点击和停止事件是否合理?

In C# it would be something like this: you add Closing event handler and then 在C#中它将是这样的:你添加Closing事件处理程序然后

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

如果您愿意使用某些Windows API代码,则可以使用SetWindowsHookEx函数设置一个钩子来拦截WM_CLOSEWM_QUITWM_DESTROY

I would suggest, check on the lines of handling MDI Child window events!! 我建议,检查处理MDI Child窗口事件的行!

The editor tab you are referring is basically an instance of MDI Child Window. 您引用的编辑器选项卡基本上是MDI子窗口的实例。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM