[Ttssh2-commit] [7591] ウィンドウを親ウィンドウの中央に移動するための関数追加

scmno****@osdn***** scmno****@osdn*****
2019年 4月 18日 (木) 00:08:27 JST


Revision: 7591
          https://osdn.net/projects/ttssh2/scm/svn/commits/7591
Author:   zmatsuo
Date:     2019-04-18 00:08:26 +0900 (Thu, 18 Apr 2019)
Log Message:
-----------
ウィンドウを親ウィンドウの中央に移動するための関数追加
CenterWindow(),GetDesktopRect()追加

Modified Paths:
--------------
    trunk/teraterm/common/ttlib.c
    trunk/teraterm/common/ttlib.h

-------------- next part --------------
Modified: trunk/teraterm/common/ttlib.c
===================================================================
--- trunk/teraterm/common/ttlib.c	2019-04-14 03:50:19 UTC (rev 7590)
+++ trunk/teraterm/common/ttlib.c	2019-04-17 15:08:26 UTC (rev 7591)
@@ -39,6 +39,7 @@
 #include <mbctype.h>	// for _ismbblead
 #include <assert.h>
 
+#include "teraterm_conf.h"
 #include "teraterm.h"
 #include "tttypes.h"
 #include "compat_win.h"
@@ -1817,3 +1818,71 @@
 	assert(r == TRUE);
 	*logfont = nci.lfStatusFont;
 }
+
+/**
+ *	\x83E\x83B\x83\x93\x83h\x83E\x95\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82̃f\x83X\x83N\x83g\x83b\x83v\x82͈̔͂\xF0\x8E擾\x82\xB7\x82\xE9
+ *	@param[in]		hWnd	\x83E\x83B\x83\x93\x83h\x83E\x82̃n\x83\x93\x83h\x83\x8B
+ *	@param[out]		rect	\x83f\x83X\x83N\x83g\x83b\x83v
+ */
+void GetDesktopRect(HWND hWnd, RECT *rect)
+{
+#if _WIN32_WINNT >= 0x0500
+	// Windows 2000 \x88ȏ\xE3
+	if (HasMultiMonitorSupport()) {
+		// \x83}\x83\x8B\x83`\x83\x82\x83j\x83^\x82\xAA\x83T\x83|\x81[\x83g\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x8Fꍇ
+		MONITORINFO monitorInfo;
+		HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
+		monitorInfo.cbSize = sizeof(MONITORINFO);
+		GetMonitorInfo(hMonitor, &monitorInfo);
+		*rect = monitorInfo.rcWork;
+	} else
+#endif
+	{
+		// \x83}\x83\x8B\x83`\x83\x82\x83j\x83^\x82\xAA\x83T\x83|\x81[\x83g\x82\xB3\x82\xEA\x82Ă\xA2\x82Ȃ\xA2\x8Fꍇ
+		SystemParametersInfo(SPI_GETWORKAREA, 0, rect, 0);
+	}
+}
+
+/**
+ *	\x8Ew\x92\xE8\x83E\x83B\x83\x93\x83h\x83E\x82̒\x86\x89\x9B\x82ɃE\x83B\x83\x93\x83h\x83E\x82\xF0\x94z\x92u\x82\xB7\x82\xE9
+ *	@param[in]	hWnd		\x88ʒu\x82𒲐\xAE\x82\xB7\x82\xE9\x83E\x83B\x83\x93\x83h\x83E
+ *	@param[in]	hWndParent	\x82\xB1\x82̃E\x83B\x83\x93\x83h\x83E\x82̒\x86\x89\x9B\x82Ɉړ\xAE\x82\xB7\x82\xE9
+ */
+void CenterWindow(HWND hWnd, HWND hWndParent)
+{
+	RECT rcWnd;
+	LONG WndWidth;
+	LONG WndHeight;
+	RECT rcParent;
+	int NewX;
+	int NewY;
+	RECT rcDesktop;
+	BOOL r;
+
+	r = GetWindowRect(hWnd, &rcWnd);
+	assert(r != FALSE); (void)r;
+	WndWidth = rcWnd.right - rcWnd.left;
+	WndHeight = rcWnd.bottom - rcWnd.top;
+	r = GetWindowRect(hWndParent, &rcParent);
+	assert(r != FALSE); (void)r;
+
+	// \x90V\x82\xB5\x82\xA2\x88ʒu
+	NewX = (rcParent.left + rcParent.right) / 2 - WndWidth / 2;
+	NewY = (rcParent.top + rcParent.bottom) / 2 - WndHeight / 2;
+
+	// \x83f\x83X\x83N\x83g\x83b\x83v\x82\xA9\x82\xE7\x82͂ݏo\x82\xB7\x8Fꍇ\x81A\x92\xB2\x90\xAE\x82\xB7\x82\xE9
+	GetDesktopRect(hWndParent, &rcDesktop);
+	if (NewX + WndWidth > rcDesktop.right)
+		NewX = rcDesktop.right - WndWidth;
+	if (NewX < rcDesktop.left)
+		NewX = rcDesktop.left;
+
+	if (NewY + WndHeight > rcDesktop.bottom)
+		NewY = rcDesktop.bottom - WndHeight;
+	if (NewY < rcDesktop.top)
+		NewY = rcDesktop.top;
+
+	// \x88ړ\xAE\x82\xB7\x82\xE9
+	SetWindowPos(hWnd, NULL, NewX, NewY, 0, 0,
+				 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
+}

Modified: trunk/teraterm/common/ttlib.h
===================================================================
--- trunk/teraterm/common/ttlib.h	2019-04-14 03:50:19 UTC (rev 7590)
+++ trunk/teraterm/common/ttlib.h	2019-04-17 15:08:26 UTC (rev 7591)
@@ -114,6 +114,8 @@
 	HWND hWnd, const POINT *point,
 	BOOL *InWindow, BOOL *InClient, BOOL *InTitleBar);
 DllExport void GetMessageboxFont(LOGFONTA *logfont);
+void GetDesktopRect(HWND hWnd, RECT *rect);
+void CenterWindow(HWND hWnd, HWND hWndParent);
 
 #define CheckFlag(var, flag)	(((var) & (flag)) != 0)
 


Ttssh2-commit メーリングリストの案内