Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Notified about Windows is Going to Sleep/Waking up in C++

Tags:

People also ask

How come when I put my computer to sleep it wakes up?

This is a Power & Sleep issue. You may disable this ability by locating your PC's Network Adapter in Device Manager and opening the Properties window. Then, click the Power Management tab and uncheck the box for "Allow this device to wake the computer".

How do I change the Wake Up settings in Windows 10?

To adjust power and sleep settings in Windows 10, go to Start , and select Settings > System > Power & sleep.

How do I stop Windows 10 from waking up?

Open the Start menu, search for "Edit Power Plan," and click Change Advanced Settings in the Edit Plan Settings window. Head to Sleep > Allow Wake Timers and change both Battery and Plugged In to Disabled.

How do you see what is waking up my computer?

To check to see if that's what's waking your computer, go to the Control Panel and launch the Power Options utility. Next click on “Change Plan Settings,” and then on “Change Advanced Power Settings.” If you don't see wake alerts in the windows that opens, that's not your problem.


I am working on an App which has Multiple Threads waiting for different inputs from DLLs and Serial Ports.

I want to add a functionality that before machine going to Sleep, I have to unload certain DLL and On waking up have to Re-load the DLL. For this, I need to get notified on Sleep and Wake up.

I found many files about doing in C# but I want to do this in C++.

I tried using this code Project but could not capture any event. I removed everything related to Window Paint and All that as I do not need it's GUI and kept only main message loop (The While loop in the main)

EDIT:-

I am using this as my main loop:-

 // Start the message loop. 

while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{ 
    if (bRet == -1)
    {
        // handle the error and possibly exit
    }
    else
    {
        TranslateMessage(&msg); 
        DispatchMessage(&msg); 
    }
} 

To be frank I have copied this from CodeProject, and Made only one Modification i.e. Checked GetMessage(..) != 0 from a MSDN Article.

Am I missing something?

Or anyother Solution??

I am using VS2010 and programming in C++

Thanks in Advance!