Get notified that Windows goes into sleep / wake mode in C ++

I am working on an application in which there are several threads waiting for different entries from a DLL and serial ports.

I want to add functionality that, before the machine goes to sleep, I have to unload a specific DLL and have to reload the DLL to wake up. To do this, I need to receive a notification about Sleep and Wake Up.

I found a lot of files about working in C #, but I want to do it in C ++.

I tried to use this project code , but could not capture any event. I deleted everything related to Window Paint and everything, since I do not need its GUI and it only storesmain message loop (The While loop in the main)

EDIT: -

I use 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); 
    }
} 

, CodeProject . i.e GetMessage (..)!= 0 MSDN.

- ?

?

VS2010 ++

, Advance!

+5
1

WM_POWERBROADCAST

, . , , . .

static long FAR PASCAL WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    if(message == WM_POWERBROADCAST)
    {
        //Do something
        return TRUE;
    }
    else
        return DefWindowProc(hWnd, message, wParam, lParam);
}

int _tmain(int argc, _TCHAR* argv[])
{
    WNDCLASS wc = {0};


    // Set up and register window class
    wc.lpfnWndProc = WindowProc;
    wc.lpszClassName = _T("SomeNameYouInvented");
    RegisterClass(&wc);
    HWND hWin = CreateWindow(_T("SomeNameYouInvented"), _T(""), 0, 0, 0, 0, 0, NULL, NULL, NULL, 0);

    BOOL bRet;
    MSG msg;
    while( (bRet = GetMessage( &msg, hWin, 0, 0 )) != 0)
    { 
        if (bRet == -1)
        {
            // handle the error and possibly exit
        }
        else
        {
            TranslateMessage(&msg); 
            DispatchMessage(&msg); 
        }
    }
    return 0;
}
+5

All Articles