Re: How do I intercept a close event?

From: Tinius (Tinius_at_discussions.microsoft.com)
Date: 01/13/05


Date: Thu, 13 Jan 2005 08:11:05 -0800

Hi Branimir and thanks for the suggestion

I tried what you suggested and its works fine for detecting when the User
closes the app. The WM_CLOSE is received directly after MainForm_Closing gets
executed.
I still am in the situation where I cannot find a way of determining when
the App is closed via Shutdown.

Tinius

"Branimir Giurov [C# MVP]" wrote:

> Hi Tinius,
>
> I think that the easiest way of capturing the close event of the form, is
> in fact to capture the WM_CLOSE message that's being send to the form through
> the message loop of the OS. Here's an easy way for doing that
>
> //insert the following code inside your main form class:
>
> const int WM_CLOSE = 16;
>
> protected override void WndProc(ref Message m)
> {
> base.WndProc (ref m);
>
> if ( WM_CLOSE == m.Msg )
> {
> //closing
> Trace.WriteLine(Application.ExecutablePath + " is exiting !!!");
> }
> }
>
> Cheers,
> Branimir
>
> Branimir Giurov
> C# MVP, MCSD, MCDBA, MCT
> CTO, BSH Ltd.
> www.sofiadev.org
>



Relevant Pages

  • Re: How do I intercept a close event?
    ... I think that the easiest way of capturing the close event of the form, ... > I'm at a loss with how to differentiate between the User closing the ... > app down and Windows closing the app down ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Determining error context
    ... add in the error context identification, ... Capturing the context did not seem particularly important until I started ... developing a non-interactive app. ... hard-code that into the call to your error logger. ...
    (microsoft.public.access.modulesdaovba)
  • Re: preventing crash of cd based program when cd-rom ejected
    ... "Ken Halter" wrote: ... what you're trying to do is shut down the app if the CD's ejected? ... > detecting an already running copy to detecting and sending command lines ... of the drive every 3 seconds and if the drive reports anything other than ...
    (microsoft.public.vb.general.discussion)
  • Re: Detecting application launch
    ... I don't know of a direct method of detecting a new app start. ... 2- Using EnumWindows() Win32 function ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: preventing crash of cd based program when cd-rom ejected
    ... Matthew Nuzum wrote: ... what you're trying to do is shut down the app if the CD's ejected? ... detecting an already running copy to detecting and sending command lines ... Communicate with another instance of your app. ...
    (microsoft.public.vb.general.discussion)