8

When the user in Windows 10 (or even previous versions changes display settings), they are being offered a choice by the OS whether to keep or revert the changes. The user is also given a 15 second window. If they do nothing, then settings will be reverted. If they select "Keep Changes" or "Revert", the appropriate action will be taken. I want to get notified by the OS when this dialog box is being displayed.

I monitored all the processes in Task Manager and no new process is being spawned as a result. So, I cannot even track the process. What is a possible way of doing this? I know one way to implement, listen to WM_DISPLAYCHANGE event. But this is not a reliable method because of the 15 second window the user is given. Basically, I want to get notified when the dialog box appears and disappears. Any ideas how I can implement this?

I need this to be implemented for Windows 10 by the way. So Windows 10 information will be the most helpful. Thank you!

enter image description here

11
  • 1
    AFAIK, all things desktop-related are here: msdn.microsoft.com/en-us/library/windows/desktop/…
    – defube
    Jul 20, 2015 at 23:41
  • 2
    Why do you need to know when the dialog appears and disappears? Should you not just handle the case when the display has changed?
    – icabod
    Jul 21, 2015 at 11:31
  • 1
    So wait 16 seconds after you get a WM_DISPLAYCHANGE, and if you haven't gotten a second one in that time send the notification.
    – Ross Ridge
    Jul 25, 2015 at 21:54
  • 1
    I think @icabod is suggesting that you just notify your other application every time you get a WM_DISPLAYCHANGE (assuming of course that the other application doesn't get its own WM_DISPLAYMESSAGE notifications). Yes, you'll be doing a tiny bit of extra work when a user reverts the settings - but probably not frequently, people don't fiddle with display settings very much, they've got real work to do! :-) Jul 25, 2015 at 22:24
  • 2
    This seems like an XY problem to me. Jul 26, 2015 at 7:38

2 Answers 2

5
+300

WM_DISPLAYCHANGE is the correct way. It is sent when the resolution really changes. That is, right before the dialog appears, and when you hit revert. It is not sent if you keep the resolution.

The 15 second window, with keep and revert buttons, is a #32770 dialog. When you use the OS dialog, the launching process is explorer.exe. It does show on my spyxx - see below. Just hit the Windows button when the dialog is showing and look for it.

You can change resolution without the dialog. Graphics cards usually have their own software with or without some other dialog. Any software can change the resolution using ChangeDisplaySettings.

You probably can track down the OS dialog, but this would be very fragile, so I would not recommend it.
If you really need to see the system dialog, you can enum all top level windows when you get WM_DISPLAYCHANGE.
I guess you'd have to enum continuously for at least a second, and look for that pattern of child windows, captions, classes, window position (center of primary screen). You would have to do that per OS version and per language.
You can also enum windows periodically, before you receive WM_DISPLAYCHANGE, and then look for changes in top level windows after the resolution change.

enter image description here

EDIT:
As requested, here's some code to see the dialog:

std::map<std::string,int> windows;

BOOL CALLBACK onEnumWindow( HWND hwnd, LPARAM lParam )
{
    char buf[500];
    if( IsWindowVisible(hwnd) && GetWindowText(hwnd,buf,500) > 0 )
        windows[buf]++;
    return TRUE;
}

std::string getLayout()
{
    std::string layout;
    EnumWindows(onEnumWindow, 0);
    for( auto& w : windows ) {
        if( w.first == "Display Settings" ) layout += "**** ";
        layout += std::to_string(w.second) + "x " + w.first + "\n";
    }
    windows.clear();
    return layout;
}

int _tmain(int argc, _TCHAR* argv[])
{
    std::string layout0;
    for(;;) {
        std::string layout = getLayout();
        if( layout != layout0 ) { // <-- you should test that across res change
            printf("%s\n", layout.c_str());
            layout0 = layout;
        }
    }
    return 0;
}

And here's it's output:

1x C:\Users\yakov\Documents\Visual Studio 2013\Projects\desk\x64\Release\desk.exe
1x EnumWindows function (Windows) - Google Chrome
1x Program Manager
1x Screen Resolution
1x Start
1x desk (Running) - Microsoft Visual Studio

1x C:\Users\yakov\Documents\Visual Studio 2013\Projects\desk\x64\Release\desk.exe
**** 1x Display Settings
1x EnumWindows function (Windows) - Google Chrome
1x Program Manager
1x Screen Resolution
1x Start
1x desk (Running) - Microsoft Visual Studio

1x C:\Users\yakov\Documents\Visual Studio 2013\Projects\desk\x64\Release\desk.exe
1x EnumWindows function (Windows) - Google Chrome
1x Program Manager
1x Screen Resolution
1x Start
1x desk (Running) - Microsoft Visual Studio

Another thing to note - if screen resolution triggers UAC in win10, or future OSs, you can not detect the dialog. You're still notified of the resolution change.
The UAC dialog is not detectable as it runs in a desktop that is accessible only to the system account.

1
  • do you think you can add a code snippet of what you just commented? That will be really helpful. If you can't, it's still OK, but please do if you have it already.
    – santahopar
    Aug 1, 2015 at 18:02
-1

Try finding that window using FindWindowEx , with a child window or main window with that specific text...

5
  • I have tried finding that windows using Spy++ (both x86 and x64 versions of the program), but have not been able to. Could you be more specific on how I can do it?
    – santahopar
    Jul 29, 2015 at 14:37
  • It is probably displayed in a different session / desktop just as the UAC dialog. You won't be able to access it by any means. Jul 30, 2015 at 11:03
  • It seems working to find that message window if the aero theme is disabled, I have tried it in vmware I dont have a windows now to test it in aero enabled environment Jul 30, 2015 at 11:17
  • Probably an enumeration of child windows may pick this message window if its a child window of desktop window , use a window enumeration API.Spy++ , I think can list child windows as well Jul 30, 2015 at 11:25
  • @TonyThomas, I cannot see that window using Spi++
    – santahopar
    Jul 31, 2015 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.