MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Blast / MoveWindowOntoAdapter

Function MoveWindowOntoAdapter

samples/SampleBase/core/DeviceManager.cpp:100–136  ·  view source on GitHub ↗

Adjust window rect so that it is centred on the given adapter. Clamps to fit if it's too big.

Source from the content-addressed store, hash-verified

98
99 // Adjust window rect so that it is centred on the given adapter. Clamps to fit if it's too big.
100 RECT MoveWindowOntoAdapter(IDXGIAdapter* targetAdapter, const RECT& rect)
101 {
102 assert(targetAdapter != NULL);
103
104 RECT result = rect;
105 HRESULT hres = S_OK;
106 unsigned int outputNo = 0;
107 while (SUCCEEDED(hres))
108 {
109 IDXGIOutput* pOutput = NULL;
110 hres = targetAdapter->EnumOutputs(outputNo++, &pOutput);
111
112 if (SUCCEEDED(hres) && pOutput)
113 {
114 DXGI_OUTPUT_DESC OutputDesc;
115 pOutput->GetDesc( &OutputDesc );
116 const RECT desktop = OutputDesc.DesktopCoordinates;
117 const int centreX = (int) desktop.left + (int)(desktop.right - desktop.left) / 2;
118 const int centreY = (int) desktop.top + (int)(desktop.bottom - desktop.top) / 2;
119 const int winW = rect.right - rect.left;
120 const int winH = rect.bottom - rect.top;
121 int left = centreX - winW/2;
122 int right = left + winW;
123 int top = centreY - winH/2;
124 int bottom = top + winH;
125 result.left = std::max(left, (int) desktop.left);
126 result.right = std::min(right, (int) desktop.right);
127 result.bottom = std::min(bottom, (int) desktop.bottom);
128 result.top = std::max(top, (int) desktop.top);
129 pOutput->Release();
130
131 // If there is more than one output, go with the first found. Multi-monitor support could go here.
132 break;
133 }
134 }
135 return result;
136 }
137}
138
139HRESULT

Callers 1

Calls 1

ReleaseMethod · 0.45

Tested by

no test coverage detected