1 | // NOTE: https://stackoverflow.com/questions/48172751/dxgi-monitors-enumeration-does-not-give-full-size-for-dell-p2715q-monitor |
---|
2 | |
---|
3 | #include <winsdkver.h> |
---|
4 | #include <sdkddkver.h> |
---|
5 | #include <stdio.h> |
---|
6 | #include <tchar.h> |
---|
7 | #include <iostream> |
---|
8 | #include <ShellScalingAPI.h> |
---|
9 | #include <dxgi.h> |
---|
10 | |
---|
11 | #pragma comment(lib, "shcore.lib") |
---|
12 | #pragma comment(lib, "dxgi.lib") |
---|
13 | |
---|
14 | using namespace std; |
---|
15 | |
---|
16 | int main() |
---|
17 | { |
---|
18 | //SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE); |
---|
19 | |
---|
20 | IDXGIFactory1* pFactory1; |
---|
21 | |
---|
22 | HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)(&pFactory1)); |
---|
23 | |
---|
24 | if (FAILED(hr)) |
---|
25 | { |
---|
26 | wcout << L"CreateDXGIFactory1 failed. " << endl; |
---|
27 | return 0; |
---|
28 | } |
---|
29 | |
---|
30 | for (UINT i = 0;; i++) |
---|
31 | { |
---|
32 | IDXGIAdapter1* pAdapter1 = nullptr; |
---|
33 | |
---|
34 | hr = pFactory1->EnumAdapters1(i, &pAdapter1); |
---|
35 | |
---|
36 | if (hr == DXGI_ERROR_NOT_FOUND) |
---|
37 | { |
---|
38 | // no more adapters |
---|
39 | break; |
---|
40 | } |
---|
41 | |
---|
42 | if (FAILED(hr)) |
---|
43 | { |
---|
44 | wcout << L"EnumAdapters1 failed. " << endl; |
---|
45 | return 0; |
---|
46 | } |
---|
47 | |
---|
48 | DXGI_ADAPTER_DESC1 desc; |
---|
49 | |
---|
50 | hr = pAdapter1->GetDesc1(&desc); |
---|
51 | |
---|
52 | if (FAILED(hr)) |
---|
53 | { |
---|
54 | wcout << L"GetDesc1 failed. " << endl; |
---|
55 | return 0; |
---|
56 | } |
---|
57 | |
---|
58 | wcout << L"Adapter: " << desc.Description << endl; |
---|
59 | |
---|
60 | for (UINT j = 0;; j++) |
---|
61 | { |
---|
62 | IDXGIOutput *pOutput = nullptr; |
---|
63 | |
---|
64 | HRESULT hr = pAdapter1->EnumOutputs(j, &pOutput); |
---|
65 | |
---|
66 | if (hr == DXGI_ERROR_NOT_FOUND) |
---|
67 | { |
---|
68 | // no more outputs |
---|
69 | break; |
---|
70 | } |
---|
71 | |
---|
72 | if (FAILED(hr)) |
---|
73 | { |
---|
74 | wcout << L"EnumOutputs failed. " << endl; |
---|
75 | return 0; |
---|
76 | } |
---|
77 | |
---|
78 | DXGI_OUTPUT_DESC desc; |
---|
79 | |
---|
80 | hr = pOutput->GetDesc(&desc); |
---|
81 | |
---|
82 | if (FAILED(hr)) |
---|
83 | { |
---|
84 | wcout << L"GetDesc1 failed. " << endl; |
---|
85 | return 0; |
---|
86 | } |
---|
87 | |
---|
88 | wcout << L" Output: " << desc.DeviceName << |
---|
89 | L" (" << desc.DesktopCoordinates.left << L"," << desc.DesktopCoordinates.top << L")-(" << |
---|
90 | (desc.DesktopCoordinates.right - desc.DesktopCoordinates.left) << L"," << |
---|
91 | (desc.DesktopCoordinates.bottom - desc.DesktopCoordinates.top) << L")" << endl; |
---|
92 | |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | return 0; |
---|
97 | } |
---|