diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index 6c802183..7bfa955c 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -5,6 +5,7 @@ add_sources_from_current_dir(utils utils/agent_named_pipe_name.c utils/arm_arch_queries.c utils/aux_match_opt.c + utils/centre_window.c utils/cryptoapi.c utils/defaults.c utils/dll_hijacking_protection.c diff --git a/windows/dialog.c b/windows/dialog.c index e68ef2af..65534815 100644 --- a/windows/dialog.c +++ b/windows/dialog.c @@ -348,7 +348,7 @@ static INT_PTR GenericMainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, void *ctx) { const int DEMO_SCREENSHOT_TIMER_ID = 1230; - HWND hw, treeview; + HWND treeview; struct treeview_faff tvfaff; int ret; @@ -369,19 +369,8 @@ static INT_PTR GenericMainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, } SendMessage(hwnd, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) LoadIcon(hinst, MAKEINTRESOURCE(IDI_CFGICON))); - /* - * Centre the window. - */ - { /* centre the window */ - RECT rs, rd; - hw = GetDesktopWindow(); - if (GetWindowRect(hw, &rs) && GetWindowRect(hwnd, &rd)) - MoveWindow(hwnd, - (rs.right + rs.left + rd.left - rd.right) / 2, - (rs.bottom + rs.top + rd.top - rd.bottom) / 2, - rd.right - rd.left, rd.bottom - rd.top, true); - } + centre_window(hwnd); /* * Create the tree view. diff --git a/windows/platform.h b/windows/platform.h index c6bf056a..25de278f 100644 --- a/windows/platform.h +++ b/windows/platform.h @@ -115,6 +115,8 @@ int ShinyDialogBox(HINSTANCE hinst, LPCTSTR tmpl, const char *winclass, HWND hwndparent, ShinyDlgProc proc, void *ctx); void ShinyEndDialog(HWND hwnd, int ret); +void centre_window(HWND hwnd); + #ifndef __WINE__ /* Up-to-date Windows headers warn that the unprefixed versions of * these names are deprecated. */ diff --git a/windows/utils/centre_window.c b/windows/utils/centre_window.c new file mode 100644 index 00000000..651fc279 --- /dev/null +++ b/windows/utils/centre_window.c @@ -0,0 +1,20 @@ +/* + * Centre a window on the screen. Used to position the main config box. + */ + +#include "putty.h" + +void centre_window(HWND win) +{ + RECT rd, rw; + + if (!GetWindowRect(GetDesktopWindow(), &rd)) + return; + if (!GetWindowRect(win, &rw)) + return; + + MoveWindow(win, + (rd.right + rd.left + rw.left - rw.right) / 2, + (rd.bottom + rd.top + rw.top - rw.bottom) / 2, + rw.right - rw.left, rw.bottom - rw.top, true); +}