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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Detect closing of application from windows

Detect closing of application from windows

Scheduled Pinned Locked Moved C / C++ / MFC
windows-adminquestion
4 Posts 3 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.
  • M Offline
    M Offline
    Manfred Staiger
    wrote on last edited by
    #1

    I need to save some settings to the registry when the user closes my application. For this purpose i use the WM_DESTROY message and it works fine. Now i noticed that the application doesn't receive this message when a user terminates Windows without closing my application before. How can I detect that the application closes in such a case. MS

    B D 2 Replies Last reply
    0
    • M Manfred Staiger

      I need to save some settings to the registry when the user closes my application. For this purpose i use the WM_DESTROY message and it works fine. Now i noticed that the application doesn't receive this message when a user terminates Windows without closing my application before. How can I detect that the application closes in such a case. MS

      B Offline
      B Offline
      bnn3nasdfasdfa
      wrote on last edited by
      #2

      There are several other ways that Windows destroys it windows. The alternate shutdown is in the WM_COMMAND message when the user clicks on the small *X* or closes from the toolbar. The paramater sent to WM_COMMAND is the IDCANCEL and IDOK default macros. Simply intercept these messages in addition to WM_DESTROY and call the same exit procedures that you have setup for WM_DESTROY. Both IDOK and IDCANCEL are always Windows specific so if you do not program these in then they will call for the Window to destroy without saving any work including freeing memory. IDCANCEL and IDOK, though, is pretty generic so you might want to consider calling the DestroyWindow( HWND ) yourself in addition.

      1 Reply Last reply
      0
      • M Manfred Staiger

        I need to save some settings to the registry when the user closes my application. For this purpose i use the WM_DESTROY message and it works fine. Now i noticed that the application doesn't receive this message when a user terminates Windows without closing my application before. How can I detect that the application closes in such a case. MS

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Check out the WM_QUERYENDSESSION and WM_ENDSESSION messages.


        Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

        M 1 Reply Last reply
        0
        • D David Crow

          Check out the WM_QUERYENDSESSION and WM_ENDSESSION messages.


          Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

          M Offline
          M Offline
          Manfred Staiger
          wrote on last edited by
          #4

          Thank you David, WM_ENDSESSION did the trick. MS

          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