• win32


    EnumDisplayDevices枚举适配器

    EnumDisplayMonitors枚举监视器

    #pragma comment(lib, "dxva2.lib")
    #include <windows.h>
    #include <lowlevelmonitorconfigurationapi.h>
    #include <physicalmonitorenumerationapi.h>
    #include <iostream>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string>
    #include <highlevelmonitorconfigurationapi.h>
    #include <vector>
    
    using namespace std;
    
    void D(HANDLE hPhysicalMonitor)
    {
        DWORD cchStringLength = 0;
        BOOL bSuccess = 0;
        LPSTR szCapabilitiesString = NULL;
    
        // Get the length of the string.
        bSuccess = GetCapabilitiesStringLength(
            hPhysicalMonitor, // Handle to the monitor.
            &cchStringLength
        );
        int err = GetLastError();
    
        if (bSuccess)
        {
            // Allocate the string buffer.
            LPSTR szCapabilitiesString = (LPSTR)malloc(cchStringLength);
            if (szCapabilitiesString != NULL)
            {
                // Get the capabilities string.
                bSuccess = CapabilitiesRequestAndCapabilitiesReply(
                    hPhysicalMonitor,
                    szCapabilitiesString,
                    cchStringLength
                );
                cout << szCapabilitiesString << endl;
                // Free the string buffer.
                free(szCapabilitiesString);
            }
        }
    }
    
    static BOOL CALLBACK MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData)
    {
        cout << "hmonitor:" << hMon << endl;
    
        DWORD cPhysicalMonitors;
        BOOL bSuccess = GetNumberOfPhysicalMonitorsFromHMONITOR(hMon, &cPhysicalMonitors);
        cout << "GetNumber: " << bSuccess << ", number of physical monitors: " << cPhysicalMonitors << endl;
    
        LPPHYSICAL_MONITOR pPhysicalMonitors = (LPPHYSICAL_MONITOR)malloc(cPhysicalMonitors * sizeof(PHYSICAL_MONITOR));
        bSuccess = GetPhysicalMonitorsFromHMONITOR(hMon, cPhysicalMonitors, pPhysicalMonitors);
        cout << "GetPhysicalMonitor: " << bSuccess << endl
            << "Handle: " << pPhysicalMonitors->hPhysicalMonitor << endl
            << "Description: ";
        wcout << (WCHAR*)(pPhysicalMonitors->szPhysicalMonitorDescription) << endl;;
    
        D(pPhysicalMonitors->hPhysicalMonitor);
    
        DestroyPhysicalMonitors(cPhysicalMonitors, pPhysicalMonitors);
        free(pPhysicalMonitors);
    
        cout << "---------------------------------------" << endl;
    
        return TRUE;
    }
    
    void A()
    {
        HWND hWnd = GetDesktopWindow();
        EnumDisplayMonitors(0, 0, MonitorEnum, NULL);
        HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY);
        cout << "---------------------------------------" << endl;
        cout << "Monitor: " << hMonitor << endl;  
    
    }
    
    void B()
    {
        DWORD DispNum = 0;
        DISPLAY_DEVICE DisplayDevice;
        // Initialize DisplayDevice.
        ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));
        DisplayDevice.cb = sizeof(DisplayDevice);
    
        while ((EnumDisplayDevices(NULL, DispNum, &DisplayDevice, 0)))
        {
            std::wstring deviceName = DisplayDevice.DeviceName;
            DISPLAY_DEVICE DisplayDeviceM;
            ZeroMemory(&DisplayDeviceM, sizeof(DisplayDeviceM));
            DisplayDeviceM.cb = sizeof(DisplayDeviceM);
            int monitorIndex = 0;
            while (EnumDisplayDevices(deviceName.c_str(), monitorIndex, &DisplayDeviceM, EDD_GET_DEVICE_INTERFACE_NAME))
            {
                std::wstring monitorID = DisplayDeviceM.DeviceID;
                wcout <<"monitorID :"<< monitorID<< endl;
                ++monitorIndex;            
            }
            DispNum++;
        }
        cout << "---------------------------------------" << endl;
    }
    
    int main()
    {
        B();
    
        A();
    
    
    
    
        getchar();
    
        return 0;
    }
  • 相关阅读:
    《自动化测试工程师进阶之路》系列课程
    开发测试工程师系列课程
    AQA新加入手机自动化测试版块
    持续集成体系搭建服务
    开源自动化测试White与UIA
    TIB自动化测试快讯 自动化测试空间一周精选(201119)
    周六广州软件测试俱乐部圆桌会议3期
    Java白盒测试训练
    TIB自动化测试快讯 自动化测试空间一周精选(2012220)
    TIB自动化测试快讯 自动化测试空间一周精选(201226)
  • 原文地址:https://www.cnblogs.com/strive-sun/p/13403996.html
Copyright © 2020-2023  润新知