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. Catching WM_POWERBROADCAST message

Catching WM_POWERBROADCAST message

Scheduled Pinned Locked Moved C / C++ / MFC
6 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.
  • S Offline
    S Offline
    Still learning how to code
    wrote on last edited by
    #1

    Hello, In my App I need to do some processing prior to the system going into a sleep mode, and once again when waking up.   I have tried a number of different ways of implementing this, but haven't succeeded in sucessfully intercepting the message. The code for the current implementation is included below. My app is SDI, OS is Win2000. LRESULT CADSL_LoggerView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {      // TODO: Add your specialized code here and/or call the base class      if(message == WM_POWERBROADCAST)          {           CString szMsg;           BOOL bRC;            switch (wParam)         {                case PBT_APMSUSPEND:                     szMsg.Format("Received PBT_APMSUSPEND");                     g_pLogFile->Add(szMsg);                     bRC = KillTimer(ID_TIMER);                     szMsg.Format("KillTimer() returned %i",bRC);                     g_pLogFile->Add(szMsg);                     break;                case PBT_APMRESUMESUSPEND:                     szMsg.Format("Received PBT_APMRESUMESUSPEND");                     g_pLogFile->Add(szMsg);                     bRC = SetTimer(ID_TIMER,300000,TimerProcs);     // 5 mins (300 secs)                     szMsg.Format("SetTimer(300000) returned %i",bRC);              &n

    K S 2 Replies Last reply
    0
    • S Still learning how to code

      Hello, In my App I need to do some processing prior to the system going into a sleep mode, and once again when waking up.   I have tried a number of different ways of implementing this, but haven't succeeded in sucessfully intercepting the message. The code for the current implementation is included below. My app is SDI, OS is Win2000. LRESULT CADSL_LoggerView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {      // TODO: Add your specialized code here and/or call the base class      if(message == WM_POWERBROADCAST)          {           CString szMsg;           BOOL bRC;            switch (wParam)         {                case PBT_APMSUSPEND:                     szMsg.Format("Received PBT_APMSUSPEND");                     g_pLogFile->Add(szMsg);                     bRC = KillTimer(ID_TIMER);                     szMsg.Format("KillTimer() returned %i",bRC);                     g_pLogFile->Add(szMsg);                     break;                case PBT_APMRESUMESUSPEND:                     szMsg.Format("Received PBT_APMRESUMESUSPEND");                     g_pLogFile->Add(szMsg);                     bRC = SetTimer(ID_TIMER,300000,TimerProcs);     // 5 mins (300 secs)                     szMsg.Format("SetTimer(300000) returned %i",bRC);              &n

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      check the power configuration settings of the operating system:~ If it doesnt work check it on another PC, maybe on your old PC isnt all modern enough X|

      Press F1 for help or google it. Greetings from Germany

      S 1 Reply Last reply
      0
      • K KarstenK

        check the power configuration settings of the operating system:~ If it doesnt work check it on another PC, maybe on your old PC isnt all modern enough X|

        Press F1 for help or google it. Greetings from Germany

        S Offline
        S Offline
        Still learning how to code
        wrote on last edited by
        #3

        It is definitely not an OS problem - the system does hibernate.   Also, I know the WM_POWERBROADCAST message does get issued, as I can see it being "caught" by another project ("PowerLog" downloaded from website).   So, it's definitely something to do with my implementation.   For instance, does my code snippet have to be included in any particular class of the project ?

        Doug

        K 1 Reply Last reply
        0
        • S Still learning how to code

          It is definitely not an OS problem - the system does hibernate.   Also, I know the WM_POWERBROADCAST message does get issued, as I can see it being "caught" by another project ("PowerLog" downloaded from website).   So, it's definitely something to do with my implementation.   For instance, does my code snippet have to be included in any particular class of the project ?

          Doug

          K Offline
          K Offline
          KarstenK
          wrote on last edited by
          #4

          are you shure that your winproc is the active one of the main window?

          Press F1 for help or google it. Greetings from Germany

          S 1 Reply Last reply
          0
          • K KarstenK

            are you shure that your winproc is the active one of the main window?

            Press F1 for help or google it. Greetings from Germany

            S Offline
            S Offline
            Still learning how to code
            wrote on last edited by
            #5

            There is only one view - normally hidden, I admit. Surely such a messsage (WM_POWERBROADCAST) still gets to a window even if it is hidden ? (or is this my problem ?)

            Doug

            1 Reply Last reply
            0
            • S Still learning how to code

              Hello, In my App I need to do some processing prior to the system going into a sleep mode, and once again when waking up.   I have tried a number of different ways of implementing this, but haven't succeeded in sucessfully intercepting the message. The code for the current implementation is included below. My app is SDI, OS is Win2000. LRESULT CADSL_LoggerView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {      // TODO: Add your specialized code here and/or call the base class      if(message == WM_POWERBROADCAST)          {           CString szMsg;           BOOL bRC;            switch (wParam)         {                case PBT_APMSUSPEND:                     szMsg.Format("Received PBT_APMSUSPEND");                     g_pLogFile->Add(szMsg);                     bRC = KillTimer(ID_TIMER);                     szMsg.Format("KillTimer() returned %i",bRC);                     g_pLogFile->Add(szMsg);                     break;                case PBT_APMRESUMESUSPEND:                     szMsg.Format("Received PBT_APMRESUMESUSPEND");                     g_pLogFile->Add(szMsg);                     bRC = SetTimer(ID_TIMER,300000,TimerProcs);     // 5 mins (300 secs)                     szMsg.Format("SetTimer(300000) returned %i",bRC);              &n

              S Offline
              S Offline
              Still learning how to code
              wrote on last edited by
              #6

              For anybody that hits this problem, I thought that I would update this thread.   By a process of trial and error, I found that the only class of my project that would recognise the WM_POWERBROADCAST message was CMainFrame (by overriding WindowProc()   )

              Doug

              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