zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    mobx的一个记录
    前端模块规范AMD/UMD/CommonJs
    CSS3字体大小单位的认识px/em/rem
    各浏览器之间的字号检测
    react整理一二(初入React世界)
    Node.js中实现套接字服务
    闲来无事,把node又拾起来看看
    判断类型
    html5 搜索框
    CSS 设置placeholder属性
  • 原文地址:https://www.cnblogs.com/strive-sun/p/13403996.html
Copyright © 2011-2022 走看看