Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get notification about Windows 10's Revert/Keep new display settings dialog

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

like image 788
aalimian Avatar asked Jul 20 '15 21:07

aalimian


People also ask

Why does Windows keep changing my display settings?

Reinstall Your Graphics Card Driver. Sometimes, the Windows 10 display resolution changes itself issue can be caused by a corrupted graphics card drive. For this, you need to reinstall the device driver.

How do I stop users from changing display settings?

Open group policy editor, go to User Configuration->Administrative Templates->Control Panel->Personalization, then enable required GPOs, such as Prevent changing desktop background, Prevent changing color and appearance etc..

How do I get notifications for Windows 10?

Go to Settings > System > Notifications & actions‌ , under Get notifications from these senders select the app, and then under Priority of notifications in action center select Top.


1 Answers

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.

like image 137
BitWhistler Avatar answered Sep 22 '22 00:09

BitWhistler