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. How to get notificaion when laptop switches from power to battery?

How to get notificaion when laptop switches from power to battery?

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
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.
  • A Offline
    A Offline
    Amarelia
    wrote on last edited by
    #1

    Hi I have wrote one dialog based MFC application which i run on Windows 2000 Professional. In this application i capture different windows messges. I want to do certaing things when the power cable is removed from laptop and it automatically switches to battery status. And again I want to get notification when power becomes available. For this I use WM_POWERBROADCAST message. I have written one function as LRESULT OnMessagePowerBroadcast(WPARAM wParam, LPARAM lParam); Declared in my header file. And applied as LRESULT MyClass::OnMessagePowerBroadcast(WPARAM wParam, LPARAM lParam) { MessageBox("WM_POWERBROADCAST"); return 0; } BEGIN_MESSAGE_MAP(MyClass, CDialog) ON_MESSAGE(WM_POWERBROADCAST, OnMessagePowerBroadcast) END_MESSAGE_MAP() Here I get notification whenever my laptop switches from power to battery. But the problem is : It shows me message box even when power get in. for this I use wParam and compare it with the given values, and I get PBT_APMPOWERSTATUSCHANGE all the time. How to distinguish that Power is in or power is out? Right now it gives me same message as ( "WM_POWERBROADCAST")even when power is in and when it's out. Any idea how to distinguish it? Regards, Mahesh

    N D 2 Replies Last reply
    0
    • A Amarelia

      Hi I have wrote one dialog based MFC application which i run on Windows 2000 Professional. In this application i capture different windows messges. I want to do certaing things when the power cable is removed from laptop and it automatically switches to battery status. And again I want to get notification when power becomes available. For this I use WM_POWERBROADCAST message. I have written one function as LRESULT OnMessagePowerBroadcast(WPARAM wParam, LPARAM lParam); Declared in my header file. And applied as LRESULT MyClass::OnMessagePowerBroadcast(WPARAM wParam, LPARAM lParam) { MessageBox("WM_POWERBROADCAST"); return 0; } BEGIN_MESSAGE_MAP(MyClass, CDialog) ON_MESSAGE(WM_POWERBROADCAST, OnMessagePowerBroadcast) END_MESSAGE_MAP() Here I get notification whenever my laptop switches from power to battery. But the problem is : It shows me message box even when power get in. for this I use wParam and compare it with the given values, and I get PBT_APMPOWERSTATUSCHANGE all the time. How to distinguish that Power is in or power is out? Right now it gives me same message as ( "WM_POWERBROADCAST")even when power is in and when it's out. Any idea how to distinguish it? Regards, Mahesh

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

      Well I haven't gone through this[^]. Hope it helps.


      Nibu thomas Software Developer

      A 1 Reply Last reply
      0
      • N Nibu babu thomas

        Well I haven't gone through this[^]. Hope it helps.


        Nibu thomas Software Developer

        A Offline
        A Offline
        Amarelia
        wrote on last edited by
        #3

        Thank you very much for taking time read my question. Regards, Mahesh Mahesh

        1 Reply Last reply
        0
        • A Amarelia

          Hi I have wrote one dialog based MFC application which i run on Windows 2000 Professional. In this application i capture different windows messges. I want to do certaing things when the power cable is removed from laptop and it automatically switches to battery status. And again I want to get notification when power becomes available. For this I use WM_POWERBROADCAST message. I have written one function as LRESULT OnMessagePowerBroadcast(WPARAM wParam, LPARAM lParam); Declared in my header file. And applied as LRESULT MyClass::OnMessagePowerBroadcast(WPARAM wParam, LPARAM lParam) { MessageBox("WM_POWERBROADCAST"); return 0; } BEGIN_MESSAGE_MAP(MyClass, CDialog) ON_MESSAGE(WM_POWERBROADCAST, OnMessagePowerBroadcast) END_MESSAGE_MAP() Here I get notification whenever my laptop switches from power to battery. But the problem is : It shows me message box even when power get in. for this I use wParam and compare it with the given values, and I get PBT_APMPOWERSTATUSCHANGE all the time. How to distinguish that Power is in or power is out? Right now it gives me same message as ( "WM_POWERBROADCAST")even when power is in and when it's out. Any idea how to distinguish it? Regards, Mahesh

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

          Amarelia wrote:

          I want to do certaing things when the power cable is removed from laptop and it automatically switches to battery status. And again I want to get notification when power becomes available.

          Check out the ISensOnNow interface.


          "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

          "There is no death, only a change of worlds." - Native American Proverb

          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