mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 01:48:00 +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:
parent
69e8d471d1
commit
cccdab9ba6
@ -5,6 +5,7 @@ add_sources_from_current_dir(utils
|
|||||||
utils/agent_named_pipe_name.c
|
utils/agent_named_pipe_name.c
|
||||||
utils/arm_arch_queries.c
|
utils/arm_arch_queries.c
|
||||||
utils/aux_match_opt.c
|
utils/aux_match_opt.c
|
||||||
|
utils/centre_window.c
|
||||||
utils/cryptoapi.c
|
utils/cryptoapi.c
|
||||||
utils/defaults.c
|
utils/defaults.c
|
||||||
utils/dll_hijacking_protection.c
|
utils/dll_hijacking_protection.c
|
||||||
|
@ -348,7 +348,7 @@ static INT_PTR GenericMainDlgProc(HWND hwnd, UINT msg, WPARAM wParam,
|
|||||||
LPARAM lParam, void *ctx)
|
LPARAM lParam, void *ctx)
|
||||||
{
|
{
|
||||||
const int DEMO_SCREENSHOT_TIMER_ID = 1230;
|
const int DEMO_SCREENSHOT_TIMER_ID = 1230;
|
||||||
HWND hw, treeview;
|
HWND treeview;
|
||||||
struct treeview_faff tvfaff;
|
struct treeview_faff tvfaff;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -369,19 +369,8 @@ static INT_PTR GenericMainDlgProc(HWND hwnd, UINT msg, WPARAM wParam,
|
|||||||
}
|
}
|
||||||
SendMessage(hwnd, WM_SETICON, (WPARAM) ICON_BIG,
|
SendMessage(hwnd, WM_SETICON, (WPARAM) ICON_BIG,
|
||||||
(LPARAM) LoadIcon(hinst, MAKEINTRESOURCE(IDI_CFGICON)));
|
(LPARAM) LoadIcon(hinst, MAKEINTRESOURCE(IDI_CFGICON)));
|
||||||
/*
|
|
||||||
* Centre the window.
|
|
||||||
*/
|
|
||||||
{ /* centre the window */
|
|
||||||
RECT rs, rd;
|
|
||||||
|
|
||||||
hw = GetDesktopWindow();
|
centre_window(hwnd);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create the tree view.
|
* Create the tree view.
|
||||||
|
@ -115,6 +115,8 @@ int ShinyDialogBox(HINSTANCE hinst, LPCTSTR tmpl, const char *winclass,
|
|||||||
HWND hwndparent, ShinyDlgProc proc, void *ctx);
|
HWND hwndparent, ShinyDlgProc proc, void *ctx);
|
||||||
void ShinyEndDialog(HWND hwnd, int ret);
|
void ShinyEndDialog(HWND hwnd, int ret);
|
||||||
|
|
||||||
|
void centre_window(HWND hwnd);
|
||||||
|
|
||||||
#ifndef __WINE__
|
#ifndef __WINE__
|
||||||
/* Up-to-date Windows headers warn that the unprefixed versions of
|
/* Up-to-date Windows headers warn that the unprefixed versions of
|
||||||
* these names are deprecated. */
|
* these names are deprecated. */
|
||||||
|
20
windows/utils/centre_window.c
Normal file
20
windows/utils/centre_window.c
Normal 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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user