Overriding the "X" control and using WndProc

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I have an application that should run in the system tray while open.
It is supposed to be open at all times and I need it to dissapear when
the "X" button is pushed on the form...but without closing the app.

I've tried overriding the closing event

> Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As
> System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
> 'Don't close this form
> e.Cancel = True
> Me.Hide()
>
>
> End Sub

but when you try to shutdown windows or reboot it will cancel the event
and windows can't shutdown without closing my app first.

So I tried to override the WndProc() method and catch the message for a
system shutdown.

<code>
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand,
Name:="FullTrust")> _
Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
' Listen for operating system messages
Select Case (m.Msg)
Case WM_QUERYENDSESSION
Application.Exit()
End Select


' Handle the message
MyBase.WndProc(m)
End Sub
</code>

This will close my app while windows is Shutting down/rebooting but it
will still cancel the shut down process. I've been looking everywhere
and can't seem to find how to do this. I tried using WndProc to catch
the message sent by the "X" button and did so successfully, but it
would still close the app.

Any help would be greatly appreciated!!

Paul Huff

.



Relevant Pages

  • Re: NotifyIcon and SetForegroundWindow
    ... Public Shared Function _ ... Public Shared Sub Main ... >> I use NotifyIcon to minimize my app to the system tray. ... >> The problem is it doesn't bring the app out of the system tray. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Overriding the "X" control and using WndProc
    ... >I have an application that should run in the system tray while open. ... > the "X" button is pushed on the form...but without closing the app. ... >> Private Sub frmMain_Closing(ByVal sender As Object, ... > This will close my app while windows is Shutting down/rebooting but it ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Overriding the "X" control and using WndProc
    ... the component itself is the startup item, so your app continues to run. ... Make the Component the startup object, adding a Shared Sub Main to the ... ' Component designer generated code omitted. ... The call to Me.Dispose enables the icon to be removed from the system tray ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Windows wont shut down
    ... Can you show me how to implement WndProc? ... When windows is shutting down, ... > app cancels the request to shut down, then it will halt the shutdown. ... >> system tray, windows doesn't close down and there's no error messages. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Win32 talking to *nix question
    ... If you can open a socket in delphi, you should be able to get this to work ... sub time_stamp { ... > I have a small Delphi app that runs under Windows. ...
    (borland.public.delphi.non-technical)