MCPcopy Create free account
hub / github.com/chcg/NPP_HexEditor / getViewablePositionRect

Method getViewablePositionRect

Common/Ccpp/StaticDialog.cpp:159–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157}
158
159RECT StaticDialog::getViewablePositionRect(RECT testPositionRc) const
160{
161 HMONITOR hMon = ::MonitorFromRect(&testPositionRc, MONITOR_DEFAULTTONULL);
162
163 MONITORINFO mi{};
164 mi.cbSize = sizeof(MONITORINFO);
165
166 bool rectPosViewableWithoutChange = false;
167
168 if (hMon != NULL)
169 {
170 // rect would be at least partially visible on a monitor
171
172 ::GetMonitorInfo(hMon, &mi);
173
174 int margin = ::GetSystemMetrics(SM_CYBORDER) + ::GetSystemMetrics(SM_CYSIZEFRAME) + ::GetSystemMetrics(SM_CYCAPTION);
175
176 // require that the title bar of the window be in a viewable place so the user can see it to grab it with the mouse
177 if ((testPositionRc.top >= mi.rcWork.top) && (testPositionRc.top + margin <= mi.rcWork.bottom) &&
178 // require that some reasonable amount of width of the title bar be in the viewable area:
179 (testPositionRc.right - (margin * 2) > mi.rcWork.left) && (testPositionRc.left + (margin * 2) < mi.rcWork.right))
180 {
181 rectPosViewableWithoutChange = true;
182 }
183 }
184 else
185 {
186 // rect would not have been visible on a monitor; get info about the nearest monitor to it
187
188 hMon = ::MonitorFromRect(&testPositionRc, MONITOR_DEFAULTTONEAREST);
189
190 ::GetMonitorInfo(hMon, &mi);
191 }
192
193 RECT returnRc = testPositionRc;
194
195 if (!rectPosViewableWithoutChange)
196 {
197 // reposition rect so that it would be viewable on current/nearest monitor, centering if reasonable
198
199 LONG testRectWidth = testPositionRc.right - testPositionRc.left;
200 LONG testRectHeight = testPositionRc.bottom - testPositionRc.top;
201 LONG monWidth = mi.rcWork.right - mi.rcWork.left;
202 LONG monHeight = mi.rcWork.bottom - mi.rcWork.top;
203
204 returnRc.left = mi.rcWork.left;
205 if (testRectWidth < monWidth) returnRc.left += (monWidth - testRectWidth) / 2;
206 returnRc.right = returnRc.left + testRectWidth;
207
208 returnRc.top = mi.rcWork.top;
209 if (testRectHeight < monHeight) returnRc.top += (monHeight - testRectHeight) / 2;
210 returnRc.bottom = returnRc.top + testRectHeight;
211 }
212
213 return returnRc;
214}
215
216HGLOBAL StaticDialog::makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected