1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 09:27:59 +00:00

Windows: utility function to centre a window.

This was called from config box setup, and is obviously the kind of
thing that ought to be a reusable utility function.
This commit is contained in:
Simon Tatham 2022-04-24 13:34:15 +01:00
parent 69e8d471d1
commit cccdab9ba6
4 changed files with 25 additions and 13 deletions

View File

@ -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

View File

@ -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.

View File

@ -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. */

View File

@ -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);
}