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