tags:

views:

63

answers:

2

I'm looking for something similar with 'Form.Deactivate' event but per application. If I use Form.Deactivate event on my MainForm this event is fired even when I open a modal dialog that has as parent my MainForm.

In conclusion I nedd an event that is fired when my application was deactivated.

A: 

This similar post should provide a good starting point.

Eric J.
Is something else in that post. There is a windows message related to what I need?
Cornel
Yes, it's listed in the post: WM_QUERYENDSESSION. Here's a blog that shows how to receive that message: http://weblogs.asp.net/eporter/archive/2004/11/11/256115.aspx
Eric J.
+1  A: 

It is an odd omission but easily fixed. Paste this in your startup form:

protected void OnActivateApp(bool activate) {
  Console.WriteLine("Activate {0}", activate);
}
protected override void WndProc(ref Message m) {
  // Trap WM_ACTIVATEAPP
  if (m.Msg == 0x1c) OnActivateApp(m.WParam != IntPtr.Zero);
  base.WndProc(ref m);
}
Hans Passant
I think that there is win32 bug in this case. If I minimize my application by clicking on the taskbar (my application) the app seems to still be activated. Can this be fixed somehow?
Cornel
That works fine when I try it. Make sure there is actually another app that can get the focus. Use the Resize event to inspect WindowState to detect the user minimizing the window.
Hans Passant
Thanks a lot nobugz
Cornel