MCPcopy Create free account
hub / github.com/lxn/walk / fitRectToScreen

Function fitRectToScreen

dialog.go:197–231  ·  view source on GitHub ↗

fitRectToScreen fits rectangle to screen. Input and output rectangles are in native pixels.

(hWnd win.HWND, r Rectangle)

Source from the content-addressed store, hash-verified

195
196// fitRectToScreen fits rectangle to screen. Input and output rectangles are in native pixels.
197func fitRectToScreen(hWnd win.HWND, r Rectangle) Rectangle {
198 var mi win.MONITORINFO
199 mi.CbSize = uint32(unsafe.Sizeof(mi))
200
201 if !win.GetMonitorInfo(win.MonitorFromWindow(
202 hWnd, win.MONITOR_DEFAULTTOPRIMARY), &mi) {
203
204 return r
205 }
206
207 mon := rectangleFromRECT(mi.RcWork)
208
209 dpi := win.GetDpiForWindow(hWnd)
210 mon.Height -= int(win.GetSystemMetricsForDpi(win.SM_CYCAPTION, dpi))
211
212 if r.Width <= mon.Width {
213 switch {
214 case r.X < mon.X:
215 r.X = mon.X
216 case r.X+r.Width > mon.X+mon.Width:
217 r.X = mon.X + mon.Width - r.Width
218 }
219 }
220
221 if r.Height <= mon.Height {
222 switch {
223 case r.Y < mon.Y:
224 r.Y = mon.Y
225 case r.Y+r.Height > mon.Y+mon.Height:
226 r.Y = mon.Y + mon.Height - r.Height
227 }
228 }
229
230 return r
231}
232
233func (dlg *Dialog) Run() int {
234 dlg.Show()

Callers 1

ShowMethod · 0.85

Calls 1

rectangleFromRECTFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…