On 11/11/2010 15:06, Jay Tennant wrote:
From: Ralph Versteegen<[email protected]>
I'd like the hotswapping-of-displays crashes to be
resolved.

This seems to be impossible to detect. I've searched all over
the docs and the internet, but I only found that Windows
does not send notifications about monitor connection state. It
seems to "know" about it, but will not raise an event for the
rest of the system.

http://social.msdn.microsoft.com/Forums/en/etw/thread/01373322-30ea-4abc-b7ca-0e698febe39d

Maybe by checking for connected monitors once every 3 seconds?

I've done a bit of playing around, and discovered that it is possible to get monitor notifications.

WARNING: WIN32 CODE AHEAD, LINUX USERS AVERT YOUR EYES

#include <windows.h>
#include <dbt.h>

//this is normally defined in the Driver Development Kit, which I don't have
const GUID GUID_MONITORS = { 0xe6f07b5f, 0xee97, 0x4a90, {0xb0, 0x76, 0x33, 0xF5, 0x7B, 0xF4, 0xEA, 0xA7} };

void RegisterNotification(HWND hWnd) {
    DEV_BROADCAST_DEVICEINTERFACE flt;
    ZeroMemory(&flt, sizeof(flt));

    flt.dbcc_size = sizeof(flt);
    flt.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
    flt.dbcc_classguid = GUID_MONITORS;

    RegisterDeviceNotification(hWnd, &flt, DEVICE_NOTIFY_WINDOW_HANDLE);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

    switch (message) {
        //other messages, etc
    case WM_CREATE:
        RegisterNotification(hWnd);

    case WM_DEVICECHANGE:
        {
PDEV_BROADCAST_DEVICEINTERFACE b = (PDEV_BROADCAST_DEVICEINTERFACE) lParam;

            switch(wParam) {
                case DBT_DEVICEARRIVAL:
                    LogMsg("Device arrival: %S", b->dbcc_name);
                    break;
                case DBT_DEVICEREMOVECOMPLETE:
                    LogMsg("Device removal: %S", b->dbcc_name);
                    break;
            }

            return DefWindowProc(hWnd, message, wParam, lParam);
        }
    }
}

END OF WIN32 CODE

With this code (and, obviously, the glue I omitted), I get this when unplugging and replugging my monitor:

Device removal: \\?\DISPLAY#HSD0019#5&b07f988&0&UID1048833#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7} Device arrival: \\?\DISPLAY#HSD0019#5&b07f988&0&UID1048833#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}

Obviously, the name is irrelevant, but this is a good place to enumerate displays, etc.
_______________________________________________
Ohrrpgce mailing list
[email protected]
http://lists.motherhamster.org/listinfo.cgi/ohrrpgce-motherhamster.org

Reply via email to