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 / C++ / MFC
  4. System Shutdown

System Shutdown

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorial
11 Posts 5 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.
  • K Offline
    K Offline
    kk tvm
    wrote on last edited by
    #1

    Hi How to capture System Shutdown/Restart/Stand By messeges from a Visual C/C++ Program thanx in advance by KK

    N C 2 Replies Last reply
    0
    • K kk tvm

      Hi How to capture System Shutdown/Restart/Stand By messeges from a Visual C/C++ Program thanx in advance by KK

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      Take a look at WM_QUERYENDSESSION and WM_ENDSESSION.


      Nibu thomas Software Developer

      E 1 Reply Last reply
      0
      • N Nibu babu thomas

        Take a look at WM_QUERYENDSESSION and WM_ENDSESSION.


        Nibu thomas Software Developer

        E Offline
        E Offline
        Eytukan
        wrote on last edited by
        #3

        Hold on!, i've been trying to capture these messages in the PreTranslateMessage, but i dont know what mistake i'm making. its not getting trapped. can you help me out?

        BOOL CTESTMFC2Dlg::PreTranslateMessage(MSG* pMsg) 
        {
           if(pMsg->message==WM_QUERYENDSESSION)
              {
                 if(pMsg->lParam==0x80000000)
                    {
                        /*code here*/
        
                    }
        
               }
        
           if(pMsg->message==WM_ENDSESSION)
             {
                   /*code here*/     
        
              }
        
          return CDialog::PreTranslateMessage(pMsg);
        }
        

        Actually the 0x80000000 is to check if its a LogOff. the owner of this thread may also like to see your reply. ;)


        VuNic

        1 Reply Last reply
        0
        • K kk tvm

          Hi How to capture System Shutdown/Restart/Stand By messeges from a Visual C/C++ Program thanx in advance by KK

          C Offline
          C Offline
          CodeVarma
          wrote on last edited by
          #4

          BOOL CMainFrame::OnQueryEndSession() { if (!CFrameWnd::OnQueryEndSession()) return FALSE; AfxMessageBox("I caught System ShutDown"); return TRUE; }:laugh: also c WM_ENDSESSION

          E 1 Reply Last reply
          0
          • C CodeVarma

            BOOL CMainFrame::OnQueryEndSession() { if (!CFrameWnd::OnQueryEndSession()) return FALSE; AfxMessageBox("I caught System ShutDown"); return TRUE; }:laugh: also c WM_ENDSESSION

            E Offline
            E Offline
            Eytukan
            wrote on last edited by
            #5

            If its a dialog based application?:confused:


            VuNic

            C 2 Replies Last reply
            0
            • E Eytukan

              If its a dialog based application?:confused:


              VuNic

              C Offline
              C Offline
              CodeVarma
              wrote on last edited by
              #6

              afx_msg void CShutWindowDlg::OnEndSession( BOOL bEnding ) { AfxMessageBox("Shut Down Message Caught"); } :laugh:

              E 1 Reply Last reply
              0
              • C CodeVarma

                afx_msg void CShutWindowDlg::OnEndSession( BOOL bEnding ) { AfxMessageBox("Shut Down Message Caught"); } :laugh:

                E Offline
                E Offline
                Eytukan
                wrote on last edited by
                #7

                Did you chage your post?? what's that afx_msg void?? it only returns a BOOL right? Btw, still its not working. I tried both ::OnEndSession(BOOL b) and ::OnQueryEndSession() BOOL CTESTMFC2Dlg::OnEndSession(BOOL bEnding) { //Not entering here :( } BOOL CTESTMFC2Dlg::OnQueryEndSession() { // Not entering here :( } What'd have gone wrong?:confused:


                VuNic

                1 Reply Last reply
                0
                • E Eytukan

                  If its a dialog based application?:confused:


                  VuNic

                  C Offline
                  C Offline
                  CodeVarma
                  wrote on last edited by
                  #8

                  afx_msg void CShutWindowDlg::OnEndSession( BOOL bEnding ) { AfxMessageBox("System ShutDown Message Caught"); } Handel WM_ENDSESSION Message :laugh:

                  E 1 Reply Last reply
                  0
                  • C CodeVarma

                    afx_msg void CShutWindowDlg::OnEndSession( BOOL bEnding ) { AfxMessageBox("System ShutDown Message Caught"); } Handel WM_ENDSESSION Message :laugh:

                    E Offline
                    E Offline
                    Eytukan
                    wrote on last edited by
                    #9

                    Handle it again??:confused: then what's the need for ::OnEndSession ??


                    VuNic

                    R 1 Reply Last reply
                    0
                    • E Eytukan

                      Handle it again??:confused: then what's the need for ::OnEndSession ??


                      VuNic

                      R Offline
                      R Offline
                      Rster021111
                      wrote on last edited by
                      #10

                      Don't try adding those functions. Instead, go to your dialog view (where you can manipulate the button/textbox fields) click on the dialog somewhere. From there, go to the Properties tab. This is the place where you would normally set the button/textbox name, readonly, etc. Instead, click on the button next to the little Lightning bolt that is labeled "Messages." From there, scroll down until you see "WM_QUERYENDSESSION", click on that, and add OnQueryEndSession. From there your function will be added and implimented, and you can change what you're testing for inside of that. da Big_R

                      E 1 Reply Last reply
                      0
                      • R Rster021111

                        Don't try adding those functions. Instead, go to your dialog view (where you can manipulate the button/textbox fields) click on the dialog somewhere. From there, go to the Properties tab. This is the place where you would normally set the button/textbox name, readonly, etc. Instead, click on the button next to the little Lightning bolt that is labeled "Messages." From there, scroll down until you see "WM_QUERYENDSESSION", click on that, and add OnQueryEndSession. From there your function will be added and implimented, and you can change what you're testing for inside of that. da Big_R

                        E Offline
                        E Offline
                        Eytukan
                        wrote on last edited by
                        #11

                        are you talking about the class wizard?


                        VuNic

                        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