Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Over ride closing event

Over ride closing event

Scheduled Pinned Locked Moved C#
help
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daniel Negron
    wrote on last edited by
    #1

    **NOOB** I am over riding the closing event for the main form, Windows Shutdown process halts until the application is manually closed. Then I have to initiate the shutdown sequence again. Below I have the OnClosing event. I am looking to combine the two below so that they close out the application if Shutdown, Restart or Logoff are initiated. protected override void OnClosing(CancelEventArgs e) { e.Cancel = true; this.WindowState = FormWindowState.Minimized; Hide(); } protected override void WndProc(ref Message m) { base.WndProc (ref m); if (m.Msg == 0x0011) { Application.Exit(); //this.Close(); } } If I have these 2 methods in place, the application WILL shutoff, BUT it will also halt the shutdown process, and once again I have to start the shutdown process all over again. Thank you in advance for your help. **DAN**

    H 1 Reply Last reply
    0
    • D Daniel Negron

      **NOOB** I am over riding the closing event for the main form, Windows Shutdown process halts until the application is manually closed. Then I have to initiate the shutdown sequence again. Below I have the OnClosing event. I am looking to combine the two below so that they close out the application if Shutdown, Restart or Logoff are initiated. protected override void OnClosing(CancelEventArgs e) { e.Cancel = true; this.WindowState = FormWindowState.Minimized; Hide(); } protected override void WndProc(ref Message m) { base.WndProc (ref m); if (m.Msg == 0x0011) { Application.Exit(); //this.Close(); } } If I have these 2 methods in place, the application WILL shutoff, BUT it will also halt the shutdown process, and once again I have to start the shutdown process all over again. Thank you in advance for your help. **DAN**

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Calling Application.Exit sends the WM_QUIT message to the application, this the pump catches and the WM_CLOSE event is not (typically) called, so OnClosing is not executed. That much you've discovered. When handling the WM_QUERYENDSESSION notification message, though, you should set Message.Result = new IntPtr(1); in order to essentially return TRUE as the return value so that the shutdown process isn't canceled. By not setting this value, FALSE is essentially returned and the shutdown process is cancelled as you have noticed. For more information, see the documentation for the WM_QUERYENDSESSION notification message at http://msdn.microsoft.com/library/en-us/sysinfo/base/wm_queryendsession.asp[^] and pay close attention the return value documentation and the remarks section. Hopefully this will help, but it won't combine those two handlers. Honestly though, it really doesn't matter - it solves the problem and that's what counts. Besides, the Closing event is triggered by the WM_CLOSE message which isn't sent to Windows unless the application pump handles an appropriate message and sends or posts the message itself (at least, from what I remember).

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups