Announcement

Collapse
No announcement yet.

WM_QUERYENDSESSION

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • WM_QUERYENDSESSION

    I know we've covered this for evasive action before but lets say I have an option in my app to save settings prior to closing.
    If someone closes the app via the X on the top right, or Windodws is shutting down, do I use WM_QUERYENDSESSION or WM_CLOSE to detect this and save my settings first?

    I'm getting weird results...

    Thanks,


    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    I,m using %WM_SYSCOMMAND, work fine for me on close or ALT-F4....
    Code:
    Case %WM_SYSCOMMAND
      If CbWparam = %SC_CLOSE Then                                                              'Alt-F4 not allowed!
        ' Do whatever you want to do........
      End If                                                                                    'dialog.
    ------------------
    Peter.
    mailto[email protected][email protected]</A>
    Regards,
    Peter

    Comment


    • #3
      Scott,

      When the X is clicked, or the program icon is clicked and you
      select close or just alt+F4, windows sends the WM_SYSCOMMAND to
      to the top level window. Just let the default procedure handle
      this and a WM_CLOSE is issued back to the window.

      When Windows is shutting down, the WM_QUERYENDSESSION is sent
      to all top level windows that are running. Just make a procedure
      that you call from the window procedure at these two messages
      to do your program saves.

      Cheers,
      Cecil

      ------------------

      Comment


      • #4
        It's a very good idea to "respond" to a WM_QUERYENDSESSION as quickly as possible, and then begin your shutdown process. By returning 1 your application is telling Windows "I promise to shut down". If you don't return 1 within the Windows timeout, Windows will terminate your application "without mercy".

        In other words, you should do something like this:

        Code:
        ELSEIF wMsg = %WM_QUERYENDSESSION THEN
         
            PostQuitMessage 0
            FUNCTION = 1
        Then when your app processes the WM_QUIT that is posted by PostQuitMessage, it should shut down as quickly as possible.

        (You don't have to use WM_QUIT... You could use SendMessage %WM_USER, for example.)

        -- Eric

        ------------------
        Perfect Sync: Perfect Sync Development Tools
        Email: mailto:[email protected][email protected]</A>

        [This message has been edited by Eric Pearson (edited February 15, 2001).]
        "Not my circus, not my monkeys."

        Comment


        • #5
          I See two issues here.
          I don't want to repeat my %IDM_EXIT menu function in the event of SC_CLOSE Or WM_CLOSE (Whats' the difference?)..

          So if I send a Control send cbhndl,%IDM_EXIT,%BM_CLICK,0,0 it occurs twice upon a N ORMAL ueage of %IDM_EXIT.


          How do I avoid that now?


          [This message has been edited by Scott Turchin (edited February 15, 2001).]
          Scott Turchin
          MCSE, MCP+I
          http://www.tngbbs.com
          ----------------------
          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

          Comment


          • #6
            Think I got it, thank god for the Win32api bible

            WM_CLOSE is alt-f4, SC_CLOSE is the SYSTEM COMMAND Of CLOSE, and QUERYENDSESSION is ONLY when a user is logging off the machine.

            Scott

            [This message has been edited by Scott Turchin (edited February 15, 2001).]
            Scott Turchin
            MCSE, MCP+I
            http://www.tngbbs.com
            ----------------------
            True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

            Comment


            • #7
              Yup got it! This works flawlessly and I just did a reboot to test it!
              %IDM_EXIT does the file saving, user will get prompted (UNless he turned that option of hehe)

              Code:
              Select case CbMsg
                  Case %WM_QUERYENDSESSION',%WM_CLOSE
                       Control Send CbHndl, %IDM_EXIT,%BM_CLICK,0,0
                       PostQuitMessage 0
                       Function = %TRUE
              
                  Case %WM_SYSCOMMAND
                       Select Case CbWparam
                              Case %SC_CLOSE 'SYSTSEM CLOSE
                                  Control Send CbHndl, %IDM_EXIT,%BM_CLICK,0,0
              
                       End Select
              ------------------
              Scott
              mailto:[email protected][email protected]</A>
              Scott Turchin
              MCSE, MCP+I
              http://www.tngbbs.com
              ----------------------
              True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

              Comment

              Working...
              X