MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / CenterWindow

Function CenterWindow

source/util.cpp:1742–1760  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1740
1741
1742POINT CenterWindow(int aWidth, int aHeight)
1743// Given a the window's width and height, calculates where to position its upper-left corner
1744// so that it is centered EVEN IF the task bar is on the left side or top side of the window.
1745// This does not currently handle multi-monitor systems explicitly, since those calculations
1746// require API functions that don't exist in Win95/NT (and thus would have to be loaded
1747// dynamically to allow the program to launch). Therefore, windows will likely wind up
1748// being centered across the total dimensions of all monitors, which usually results in
1749// half being on one monitor and half in the other. This doesn't seem too terrible and
1750// might even be what the user wants in some cases (i.e. for really big windows).
1751{
1752 RECT rect;
1753 SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0); // Get desktop rect excluding task bar.
1754 // Note that rect.left will NOT be zero if the taskbar is on docked on the left.
1755 // Similarly, rect.top will NOT be zero if the taskbar is on docked at the top of the screen.
1756 POINT pt;
1757 pt.x = rect.left + (((rect.right - rect.left) - aWidth) / 2);
1758 pt.y = rect.top + (((rect.bottom - rect.top) - aHeight) / 2);
1759 return pt;
1760}
1761
1762
1763

Callers 1

InputBoxProcFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected