Skip to main content

 none
Notification of display on/off RRS feed

  • Question

  • Hello,

    I have a mysterious apparent failure to redraw my full-screen app when the screen turns back on having turned off due to the "On battery power, turn off after" setting.  Still trying to work out what's going on, but I'd like to try an explicit re-paint.

    So my question is, can I trap notification of the screen going off/on, something along the lines of WM_POWERBROADCAST?

    Note this is not a sleep, just the screen going off.

    thanks,

    Mark

    Friday, February 9, 2018 12:35 AM

Answers

  • This is not a power management issue because the details of the answer depend on what you are using for the UI.

    Is your program painting the window in a paint event handler? And of course you might not know what that is but I don't know what you are using for a UI. If you application were to paint the window in a recommended manner then the problem you are asking about would not be a problem.



    Sam Hobbs
    SimpleSamples.Info

    • Marked as answer by kiwimew Tuesday, February 20, 2018 12:40 AM
    Friday, February 9, 2018 3:50 AM
  • Getting the message for the purposes of debugging sounds worthwhile.

    So first, note that there are NuGet packages called "WindowsAPICodePack" that supposedly can help. There are multiple packages and I don't know which one you need but supposedly they can help.

    You can get WM_POWERBROADCAST Messages but you must register for them. Supposedly you will need a GUID and it is not clear which one will help. See Power Setting GUIDs.

    If you study Power Management then you should be able to figure it out. I know nothing except what I learned by searching.



    Sam Hobbs
    SimpleSamples.Info

    • Marked as answer by kiwimew Tuesday, February 20, 2018 12:40 AM
    Monday, February 12, 2018 11:10 PM

All replies

  • Hi Mark,

    I would like to confirm:
    What do you mean by "the screen going off"?  Does it mean "monitor is turned off, i.e. monitor is power off" or "screen is black, i.e. nothing seen on the screen, no signal from graphic board"?

    Regards,

    Ashidacchi



    • Edited by Ashidacchi Friday, February 9, 2018 2:35 AM
    Friday, February 9, 2018 2:28 AM
  • This is not a power management issue because the details of the answer depend on what you are using for the UI.

    Is your program painting the window in a paint event handler? And of course you might not know what that is but I don't know what you are using for a UI. If you application were to paint the window in a recommended manner then the problem you are asking about would not be a problem.



    Sam Hobbs
    SimpleSamples.Info

    • Marked as answer by kiwimew Tuesday, February 20, 2018 12:40 AM
    Friday, February 9, 2018 3:50 AM
  • Why is that necessary if the window is painted properly from Windows paint messages? Does the documentation say it is necessary to do a redraw when the display is powered back on? Does Windows not send a paint message for that (or save the screen somewhere)? I assume the screen is still in the video adapter's memory so the screen could be gotten from there.


    Sam Hobbs
    SimpleSamples.Info

    Friday, February 9, 2018 10:37 PM
  • I mean the screen has been turned off, by Windows, after the configured period of no user activity, to save battery life. I'd like to know if my app is informed of this action, or more particularly, when the screen is turned back on again, in response to subsequent user activity.  Some kind of broadcast message.
    Monday, February 12, 2018 8:12 PM
  • I mean the screen has been turned off, by Windows, after the configured period of no user activity, to save battery life. I'd like to know if my app is informed of this action, or more particularly, when the screen is turned back on again, in response to subsequent user activity.  Some kind of broadcast message.

    Did you refer to the link I previously posted?
    Monday, February 12, 2018 8:31 PM
  • I mean you don't have to do anything if the program is written properly. Do you understand what I am saying? Do you understand about Windows sending paint messages?


    Sam Hobbs
    SimpleSamples.Info

    Monday, February 12, 2018 9:50 PM
  • Yes, I understand about WM_PAINT and I think our program is probably written properly.  But it's complicated; Qt is involved. And it's a very strange failure-to-render situation.  I'd like to gain some kind of data-point by hacking in a

    if the display was turned back on by the OS then
       explicitly repaint the app

    So I'm asking if I can tell that the display has been turned back on by the OS.

    Monday, February 12, 2018 10:04 PM
  • Getting the message for the purposes of debugging sounds worthwhile.

    So first, note that there are NuGet packages called "WindowsAPICodePack" that supposedly can help. There are multiple packages and I don't know which one you need but supposedly they can help.

    You can get WM_POWERBROADCAST Messages but you must register for them. Supposedly you will need a GUID and it is not clear which one will help. See Power Setting GUIDs.

    If you study Power Management then you should be able to figure it out. I know nothing except what I learned by searching.



    Sam Hobbs
    SimpleSamples.Info

    • Marked as answer by kiwimew Tuesday, February 20, 2018 12:40 AM
    Monday, February 12, 2018 11:10 PM
  • You can get WM_POWERBROADCAST Messages but you must register for them. Supposedly you will need a GUID and it is not clear which one will help. See Power Setting GUIDs.

    If you study Power Management then you should be able to figure it out. I know nothing except what I learned by searchin


    All available from the link that  I previously posted.
    Monday, February 12, 2018 11:40 PM
  • Calling

    RegisterPowerSettingNotification(hWnd, &GUID_CONSOLE_DISPLAY_STATE, DEVICE_NOTIFY_WINDOW_HANDLE);

    and looking for

    uMsg==WM_POWERBROADCAST, wParam==PBT_POWERSETTINGCHANGE

    provides a POWERBROADCAST_SETTING* in lParam with PowerSetting == GUID_CONSOLE_DISPLAY_STATE

    Interpret Data as a DWORD* and 0=-display off, 1==display on.

    This worked for me.  I could detect the display being turned back on and explicitly repaint the app.  So that's something!  A workaround, with the root cause still TBD.  But it's a data point....

    Thanks for your help,

    Mark

    Tuesday, February 20, 2018 12:47 AM