首页 > 代码库 > 获取显示器连接方式

获取显示器连接方式

typedef enum _D3DKMDT_VIDEO_OUTPUT_TECHNOLOGY { 
  D3DKMDT_VOT_UNINITIALIZED         = -2,
  D3DKMDT_VOT_OTHER                 = -1,
  D3DKMDT_VOT_HD15                  = 0,
  D3DKMDT_VOT_SVIDEO                = 1,
  D3DKMDT_VOT_COMPOSITE_VIDEO       = 2,
  D3DKMDT_VOT_COMPONENT_VIDEO       = 3,
  D3DKMDT_VOT_DVI                   = 4,
  D3DKMDT_VOT_HDMI                  = 5,
  D3DKMDT_VOT_LVDS                  = 6,
  D3DKMDT_VOT_D_JPN                 = 8,
  D3DKMDT_VOT_SDI                   = 9,
  D3DKMDT_VOT_DISPLAYPORT_EXTERNAL  = 10,
  D3DKMDT_VOT_DISPLAYPORT_EMBEDDED  = 11,
  D3DKMDT_VOT_UDI_EXTERNAL          = 12,
  D3DKMDT_VOT_UDI_EMBEDDED          = 13,
  D3DKMDT_VOT_SDTVDONGLE            = 14,
#if (DXGKDDI_INTERFACE_VERSION >= DXGKDDI_INTERFACE_VERSION_WDDM1_3_M1)
  D3DKMDT_VOT_MIRACAST              = 15,
#endif 
  D3DKMDT_VOT_INTERNAL              = 0x80000000,
  D3DKMDT_VOT_SVIDEO_4PIN           = D3DKMDT_VOT_SVIDEO,
  D3DKMDT_VOT_SVIDEO_7PIN           = D3DKMDT_VOT_SVIDEO,
  D3DKMDT_VOT_RF                    = D3DKMDT_VOT_COMPOSITE_VIDEO,
  D3DKMDT_VOT_RCA_3COMPONENT        = D3DKMDT_VOT_COMPONENT_VIDEO,
  D3DKMDT_VOT_BNC                   = D3DKMDT_VOT_COMPONENT_VIDEO
} D3DKMDT_VIDEO_OUTPUT_TECHNOLOGY;


D3DKMDT_VOT_UNINITIALIZED

Indicates that a variable of type D3DKMDT_VIDEO_OUTPUT_TECHNOLOGY has not yet been assigned a meaningful value.

D3DKMDT_VOT_OTHER

Indicates that the video output device connects to an external display device through a connector that is not one of the types that is indicated by the following values in this enumeration.

D3DKMDT_VOT_HD15

Indicates that the video output device connects to an external display device through an HD15 (VGA) connector.

D3DKMDT_VOT_SVIDEO

Indicates that the video output device connects to an external display device through an S-video connector.

D3DKMDT_VOT_COMPOSITE_VIDEO

Indicates that the video output device connects to an external display device through composite video connectors.

D3DKMDT_VOT_COMPONENT_VIDEO

Indicates that the video output device connects to an external display device through component video connectors.

D3DKMDT_VOT_DVI

Indicates that the video output device connects to an external display device through a Digital Video Interface (DVI) connector.

D3DKMDT_VOT_HDMI

Indicates that the video output device connects to an external display device through an High-Definition Multimedia Interface (HDMI) connector.

D3DKMDT_VOT_LVDS

Indicates that the video output device connects to an external display device through an Low Voltage Differential Swing (LVDS) or Mobile Industry Processor Interface (MIPI) Digital Serial Interface (DSI) connector.

D3DKMDT_VOT_D_JPN

Indicates that the video output device connects to an external display device through a D-Jpn connector.

D3DKMDT_VOT_SDI

Indicates that the video output device connects to an external display device through an SDI connector.

D3DKMDT_VOT_DISPLAYPORT_EXTERNAL

Indicates that the connector type is an external display port.

D3DKMDT_VOT_DISPLAYPORT_EMBEDDED

Indicates that the connector type is an embedded display port.

D3DKMDT_VOT_UDI_EXTERNAL

Indicates that the connector type is an external Unified Display Interface (UDI).

D3DKMDT_VOT_UDI_EMBEDDED

Indicates that the connector type is an embedded UDI.

D3DKMDT_VOT_SDTVDONGLE

Indicates that the video output device connects to an external display device through a dongle cable that supports SDTV.

D3DKMDT_VOT_MIRACAST

Indicates that the video output device connects to an external display device wirelessly through a Miracast connected session. For more info, see Wireless displays (Miracast).

Supported starting with Windows 8.1.

D3DKMDT_VOT_INTERNAL

Indicates that the video output device connects internally to a display device (for example, the internal connection in a laptop computer).

This constant value is not a bit-field value. Instead, it‘s a standalone video output type.

D3DKMDT_VOT_SVIDEO_4PIN

Indicates that the video output device connects to an external display device through a 4-pin S-video connector.

D3DKMDT_VOT_SVIDEO_7PIN

Indicates that the video output device connects to an external display device through a 7-pin S-video connector.

D3DKMDT_VOT_RF

Indicates that the video output device connects to an external display device through an RF connector.

D3DKMDT_VOT_RCA_3COMPONENT

Indicates that the video output device connects to an external display device through a set of three RCA connectors.

D3DKMDT_VOT_BNC

Indicates that the video output device connects to an external display device through a BNC connector.

 

技术分享
  1 #include "stdafx.h"
  2 #define _WIN32_DCOM
  3 #include <iostream>
  4 using namespace std;
  5 #include <comdef.h>
  6 #include <Wbemidl.h>
  7 # pragma comment(lib, "wbemuuid.lib")
  8 
  9 
 10 // Monitor‘s basic connection parameters
 11 
 12 #pragma argsused
 13 int main(int argc, char* argv[])
 14 {
 15     BSTR strNetworkResource;
 16     //To use a WMI remote connection set localconn to false and configure the values of the pszName, pszPwd and the name of the remote machine in strNetworkResource
 17     strNetworkResource = L"\\\\.\\root\\WMI";
 18 
 19     COAUTHIDENTITY *userAcct =  NULL ;
 20     COAUTHIDENTITY authIdent;
 21 
 22     // Initialize COM. ------------------------------------------
 23 
 24     HRESULT hres;
 25     hres =  CoInitializeEx(0, COINIT_MULTITHREADED);
 26     if (FAILED(hres))
 27     {
 28         cout << "Failed to initialize COM library. Error code = 0x" << hex << hres << endl;
 29         cout << _com_error(hres).ErrorMessage() << endl;
 30         cout << "press enter to exit" << endl;
 31         cin.get();      
 32         return 1;                  // Program has failed.
 33     }
 34 
 35     // Set general COM security levels --------------------------
 36 
 37         hres =  CoInitializeSecurity(
 38             NULL,
 39             -1,                          // COM authentication
 40             NULL,                        // Authentication services
 41             NULL,                        // Reserved
 42             RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication
 43             RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
 44             NULL,                        // Authentication info
 45             EOAC_NONE,                   // Additional capabilities
 46             NULL                         // Reserved
 47             );
 48 
 49     if (FAILED(hres))
 50     {
 51         cout << "Failed to initialize security. Error code = 0x" << hex << hres << endl;
 52         cout << _com_error(hres).ErrorMessage() << endl;
 53         CoUninitialize();
 54         cout << "press enter to exit" << endl;
 55         cin.get();      
 56         return 1;                    // Program has failed.
 57     }
 58 
 59     // Obtain the initial locator to WMI -------------------------
 60 
 61     IWbemLocator *pLoc = NULL;
 62     hres = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
 63 
 64     if (FAILED(hres))
 65     {
 66         cout << "Failed to create IWbemLocator object." << " Err code = 0x" << hex << hres << endl;
 67         cout << _com_error(hres).ErrorMessage() << endl;
 68         CoUninitialize();       
 69         cout << "press enter to exit" << endl;
 70         cin.get();      
 71         return 1;                 // Program has failed.
 72     }
 73 
 74     // Connect to WMI through the IWbemLocator::ConnectServer method
 75 
 76     IWbemServices *pSvc = NULL;
 77 
 78         hres = pLoc->ConnectServer(
 79              _bstr_t(strNetworkResource),      // Object path of WMI namespace
 80              NULL,                    // User name. NULL = current user
 81              NULL,                    // User password. NULL = current
 82              0,                       // Locale. NULL indicates current
 83              NULL,                    // Security flags.
 84              0,                       // Authority (e.g. Kerberos)
 85              0,                       // Context object
 86              &pSvc                    // pointer to IWbemServices proxy
 87              );
 88 
 89     if (FAILED(hres))
 90     {
 91         cout << "Could not connect. Error code = 0x" << hex << hres << endl;    
 92         cout << _com_error(hres).ErrorMessage() << endl;
 93         pLoc->Release();
 94         CoUninitialize();
 95         cout << "press enter to exit" << endl;
 96         cin.get();          
 97         return 1;                // Program has failed.
 98     }
 99 
100     cout << "Connected to root\\WMI WMI namespace" << endl;
101 
102     // Set security levels on the proxy -------------------------
103         hres = CoSetProxyBlanket(
104            pSvc,                        // Indicates the proxy to set
105            RPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxx
106            RPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxx
107            NULL,                        // Server principal name
108            RPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxx
109            RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
110            NULL,                        // client identity
111            EOAC_NONE                    // proxy capabilities
112         );
113 
114     if (FAILED(hres))
115     {
116         cout << "Could not set proxy blanket. Error code = 0x" << hex << hres << endl;
117         cout << _com_error(hres).ErrorMessage() << endl;
118         pSvc->Release();
119         pLoc->Release();
120         CoUninitialize();
121         cout << "press enter to exit" << endl;
122         cin.get();      
123         return 1;               // Program has failed.
124     }
125 
126     // Use the IWbemServices pointer to make requests of WMI ----
127 
128     IEnumWbemClassObject* pEnumerator = NULL;
129     hres = pSvc->ExecQuery( L"WQL", L"SELECT * FROM WmiMonitorConnectionParams",
130     WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
131 
132     if (FAILED(hres))
133     {
134         cout << "ExecQuery failed" << " Error code = 0x"    << hex << hres << endl;
135         cout << _com_error(hres).ErrorMessage() << endl;
136         pSvc->Release();
137         pLoc->Release();
138         CoUninitialize();
139         cout << "press enter to exit" << endl;
140         cin.get();      
141         return 1;               // Program has failed.
142     }
143 
144 
145     // Get the data from the WQL sentence
146     IWbemClassObject *pclsObj = NULL;
147     ULONG uReturn = 0;
148 
149     while (pEnumerator)
150     {
151         HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
152 
153         if(0 == uReturn || FAILED(hr))
154           break;
155 
156         VARIANT vtProp;
157 
158                 hr = pclsObj->Get(L"Active", 0, &vtProp, 0, 0);// Boolean
159                 if (!FAILED(hr))
160                 {
161                   if ((vtProp.vt==VT_NULL) || (vtProp.vt==VT_EMPTY))
162                     wcout << "Active : " << ((vtProp.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
163                   else
164                     wcout << "Active : " << (vtProp.boolVal ? "True" : "False") << endl;
165                 }
166                 VariantClear(&vtProp);
167 
168                 hr = pclsObj->Get(L"InstanceName", 0, &vtProp, 0, 0);// String
169                 if (!FAILED(hr))
170                 {
171                   if ((vtProp.vt==VT_NULL) || (vtProp.vt==VT_EMPTY))
172                     wcout << "InstanceName : " << ((vtProp.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
173                   else
174                     wcout << "InstanceName : " << vtProp.bstrVal << endl;
175                 }
176                 VariantClear(&vtProp);
177 
178                 hr = pclsObj->Get(L"VideoOutputTechnology", 0, &vtProp, 0, 0);// Uint32
179                 if (!FAILED(hr))
180                 {
181                   if ((vtProp.vt==VT_NULL) || (vtProp.vt==VT_EMPTY))
182                     wcout << "VideoOutputTechnology : " << ((vtProp.vt==VT_NULL) ? "NULL" : "EMPTY") << endl;
183                   else
184                     wcout << "VideoOutputTechnology : " << vtProp.uintVal << endl;
185                 }
186                 VariantClear(&vtProp);
187 
188 
189         pclsObj->Release();
190         pclsObj=NULL;
191     }
192 
193     // Cleanup
194 
195     pSvc->Release();
196     pLoc->Release();
197     pEnumerator->Release();
198     if (pclsObj!=NULL)
199      pclsObj->Release();
200 
201     CoUninitialize();
202     cout << "press enter to exit" << endl;
203     cin.get();
204     return 0;   // Program successfully completed.
205 }
View Code

 

获取显示器连接方式