MCPcopy Create free account
hub / github.com/TASEmulators/fceux / CenterWindow

Function CenterWindow

src/drivers/win/gui.cpp:13–40  ·  view source on GitHub ↗

* Centers a window relative to its parent window. * * @param hwndDlg Handle of the window to center. **/

Source from the content-addressed store, hash-verified

11* @param hwndDlg Handle of the window to center.
12**/
13void CenterWindow(HWND hwndDlg)
14{
15 //TODO: This function should probably moved into the generic Win32 window file
16 //move the window relative to its parent
17 HWND hwndParent = GetParent(hwndDlg);
18 RECT rect;
19 RECT rectP;
20
21 GetWindowRect(hwndDlg, &rect);
22 GetWindowRect(hwndParent, &rectP);
23
24 int width = rect.right - rect.left;
25 int height = rect.bottom - rect.top;
26
27 int x = ((rectP.right-rectP.left) - width) / 2 + rectP.left;
28 int y = ((rectP.bottom-rectP.top) - height) / 2 + rectP.top;
29
30 int screenwidth = GetSystemMetrics(SM_CXSCREEN);
31 int screenheight = GetSystemMetrics(SM_CYSCREEN);
32
33 //make sure that the dialog box never moves outside of the screen
34 if(x < 0) x = 0;
35 if(y < 0) y = 0;
36 if(x + width > screenwidth) x = screenwidth - width;
37 if(y + height > screenheight) y = screenheight - height;
38
39 MoveWindow(hwndDlg, x, y, width, height, FALSE);
40}
41
42/**
43* Centers a window on the screen.

Callers 5

ImportBookmarkCallBFunction · 0.85
AddbpCallBFunction · 0.85
AssemblerCallBFunction · 0.85
PatcherCallBFunction · 0.85
SymbolicNamingCallBFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected