MCPcopy Create free account
hub / github.com/derceg/explorerplusplus / CenterWindow

Function CenterWindow

Explorer++/Helper/WindowHelper.cpp:16–50  ·  view source on GitHub ↗

Centers one window (hChild) with respect to another (hParent), as per the Windows UX Guidelines (2009). This means placing the child window 45% of the way from the top of the parent window (with 55% of the space left between the bottom of the child window and the bottom of the parent window).*/

Source from the content-addressed store, hash-verified

14of the space left between the bottom of the
15child window and the bottom of the parent window).*/
16BOOL CenterWindow(HWND hParent, HWND hChild)
17{
18 RECT rcParent;
19 BOOL bRet = GetClientRect(hParent, &rcParent);
20
21 if(!bRet)
22 {
23 return FALSE;
24 }
25
26 RECT rcChild;
27 bRet = GetClientRect(hChild, &rcChild);
28
29 if(!bRet)
30 {
31 return FALSE;
32 }
33
34 /* Take the offset between the two windows,
35 and map it back to the desktop. */
36 POINT ptOrigin;
37 ptOrigin.x = (GetRectWidth(&rcParent) - GetRectWidth(&rcChild)) / 2;
38 ptOrigin.y = static_cast<LONG>((GetRectHeight(&rcParent) - GetRectHeight(&rcChild)) * 0.45);
39
40 SetLastError(0);
41 int iRet = MapWindowPoints(hParent, HWND_DESKTOP, &ptOrigin, 1);
42
43 if(iRet == 0 && GetLastError() != 0)
44 {
45 return FALSE;
46 }
47
48 return SetWindowPos(hChild, NULL, ptOrigin.x, ptOrigin.y,
49 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOZORDER);
50}
51
52void GetWindowString(HWND hwnd, std::wstring &str)
53{

Callers 5

OnInitDialogMethod · 0.85
OnInitDialogMethod · 0.85
ShowMethod · 0.85
OnInitDialogMethod · 0.85
RestoreDialogPositionMethod · 0.85

Calls 2

GetRectWidthFunction · 0.85
GetRectHeightFunction · 0.85

Tested by

no test coverage detected