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).*/
| 14 | of the space left between the bottom of the |
| 15 | child window and the bottom of the parent window).*/ |
| 16 | BOOL 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 | |
| 52 | void GetWindowString(HWND hwnd, std::wstring &str) |
| 53 | { |
no test coverage detected