Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7503281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:10:08+00:00 2026-05-29T21:10:08+00:00

I have a Visual Studio 2008 C++ project for Windows 7 where I would

  • 0

I have a Visual Studio 2008 C++ project for Windows 7 where I would like to be notified of power state transitions (e.g. suspend, hibernate, resume, etc…). I have created a message-only window that watches for WM_POWERBROADCAST messages. Once the window is created, I suspend the PC.

For example (error checking omitted for brevity):

const TCHAR class_name[] = _T( "Power State Monitor" );
WNDCLASSEX wc = { 0 };
wc.cbSize = sizeof( WNDCLASSEX );
wc.lpfnWndProc = PowerStateMonitor;
wc.lpszClassName = class_name;
::RegisterClassEx( &wc );
::CreateWindowEx( 0, class_name, class_name, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, wc.hInstance, NULL );

::SetSuspendState( FALSE, FALSE, FALSE );

The WindowProc looks like this:

LRESULT CALLBACK PowerStateMonitor( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
    if( uMsg == WM_POWERBROADCAST )
    {
        ATLTRACE( L"WM_POWERBROADCAST:\r\n");
        return TRUE;
    }
    ATLTRACE( L"Default Handler: %#08x\r\n", uMsg );
    return ::DefWindowProc( hwnd, uMsg, wParam, lParam );
}

I would expect to see WM_POWERBROADCAST: logged, but instead all I see are the typical window creation messages:

Default Handler: WM_GETMINMAXINFO
Default Handler: WM_NCCREATE
Default Handler: WM_NCCALCSIZE
Default Handler: WM_CREATE

Can anybody suggest what I can change to have my window correctly receive power change notifications?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:10:09+00:00Added an answer on May 29, 2026 at 9:10 pm

    Message only windows do not receive broadcast messages. You will have to use a hidden, normal window instead. From MSDN, emphasis mine:

    Message-Only Windows

    A message-only window enables you to send and receive messages. It is not visible, has no z-order, cannot be enumerated, and does not receive broadcast messages. The window simply dispatches messages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Visual Studio 2008 C++ Windows Mobile 6.5 project where I would
I have a Windows Forms project in Visual Studio 2008, which references a library
I have a basic ASP.Net project created in Visual Studio 2008 on Windows Server
I have a Visual Studio 2008 Windows Mobile 6.5.3 ARMV4I project. I check for
I am working in Visual Studio 2008 and have a Windows Forms project +
I have created a Windows Forms Application project by Visual Studio.Net 2008. In order
I have a Visual Studio 2008 C++ project for Windows Mobile 6 with two
I have a Visual Studio 2008 C++ project that has support for using multiple
I have a Visual Studio 2008 C++ project that outputs a static library and
I have a bunch of Velocity template files in a Visual Studio 2008 project,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.