[Ttssh2-commit] [8564] ttlib.c から一部関数を ttlib_static.c に移動

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2020年 2月 25日 (火) 23:11:18 JST


Revision: 8564
          https://osdn.net/projects/ttssh2/scm/svn/commits/8564
Author:   zmatsuo
Date:     2020-02-25 23:11:17 +0900 (Tue, 25 Feb 2020)
Log Message:
-----------
ttlib.c から一部関数を ttlib_static.c に移動

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

Added Paths:
-----------
    trunk/teraterm/common/ttlib_static.c

-------------- next part --------------
Modified: trunk/teraterm/common/ttlib.c
===================================================================
--- trunk/teraterm/common/ttlib.c	2020-02-24 16:39:14 UTC (rev 8563)
+++ trunk/teraterm/common/ttlib.c	2020-02-25 14:11:17 UTC (rev 8564)
@@ -1804,85 +1804,10 @@
 }
 
 /**
- *	\x83E\x83B\x83\x93\x83h\x83E\x8F\xE3\x82̈ʒu\x82\xF0\x8E擾\x82\xB7\x82\xE9
- *	@Param[in]		hWnd
- *	@Param[in]		point		\x88ʒu(x,y)
- *	@Param[in,out]	InWindow	\x83E\x83B\x83\x93\x83h\x83E\x8F\xE3
- *	@Param[in,out]	InClient	\x83N\x83\x89\x83C\x83A\x83\x93\x83g\x97̈\xE6\x8F\xE3
- *	@Param[in,out]	InTitleBar	\x83^\x83C\x83g\x83\x8B\x83o\x81[\x8F\xE3
- *	@retval			FALSE		\x96\xB3\x8C\xF8\x82\xC8hWnd
- */
-BOOL GetPositionOnWindow(
-	HWND hWnd, const POINT *point,
-	BOOL *InWindow, BOOL *InClient, BOOL *InTitleBar)
-{
-	const int x = point->x;
-	const int y = point->y;
-	RECT winRect;
-	RECT clientRect;
-
-	if (InWindow != NULL) *InWindow = FALSE;
-	if (InClient != NULL) *InClient = FALSE;
-	if (InTitleBar != NULL) *InTitleBar = FALSE;
-
-	if (!GetWindowRect(hWnd, &winRect)) {
-		return FALSE;
-	}
-
-	if ((x < winRect.left) || (winRect.right < x) ||
-		(y < winRect.top) || (winRect.bottom < y))
-	{
-		return TRUE;
-	}
-	if (InWindow != NULL) *InWindow = TRUE;
-
-	{
-		POINT pos;
-		GetClientRect(hWnd, &clientRect);
-		pos.x = clientRect.left;
-		pos.y = clientRect.top;
-		ClientToScreen(hWnd, &pos);
-		clientRect.left = pos.x;
-		clientRect.top = pos.y;
-
-		pos.x = clientRect.right;
-		pos.y = clientRect.bottom;
-		ClientToScreen(hWnd, &pos);
-		clientRect.right = pos.x;
-		clientRect.bottom = pos.y;
-	}
-
-	if ((clientRect.left <= x) && (x < clientRect.right) &&
-		(clientRect.top <= y) && (y < clientRect.bottom))
-	{
-		if (InClient != NULL) *InClient = TRUE;
-		if (InTitleBar != NULL) *InTitleBar = FALSE;
-		return TRUE;
-	}
-	if (InClient != NULL) *InClient = FALSE;
-
-	if (InTitleBar != NULL) {
-		*InTitleBar = (y < clientRect.top) ? TRUE : FALSE;
-	}
-
-	return TRUE;
-}
-
-int SetDlgTexts(HWND hDlgWnd, const DlgTextInfo *infos, int infoCount, const char *UILanguageFile)
-{
-	return SetI18nDlgStrs("Tera Term", hDlgWnd, infos, infoCount, UILanguageFile);
-}
-
-void SetDlgMenuTexts(HMENU hMenu, const DlgTextInfo *infos, int infoCount, const char *UILanguageFile)
-{
-	SetI18nMenuStrs("Tera Term", hMenu, infos, infoCount, UILanguageFile);
-}
-
-/**
  *	\x83_\x83C\x83A\x83\x8D\x83O\x83t\x83H\x83\x93\x83g\x82\xF0\x8E擾\x82\xB7\x82\xE9
  *	\x83G\x83\x89\x81[\x82͔\xAD\x90\xB6\x82\xB5\x82Ȃ\xA2
  */
-void GetMessageboxFont(LOGFONT *logfont)
+DllExport void GetMessageboxFont(LOGFONT *logfont)
 {
 	NONCLIENTMETRICS nci;
 	const int st_size = CCSIZEOF_STRUCT(NONCLIENTMETRICS, lfMessageFont);
@@ -1894,162 +1819,3 @@
 	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 (pMonitorFromWindow != NULL) {
-		// \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 = pMonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
-		monitorInfo.cbSize = sizeof(MONITORINFO);
-		pGetMonitorInfoA(hMonitor, &monitorInfo);
-		*rect = monitorInfo.rcWork;
-	} else {
-		// \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);
-	}
-}
-
-/**
- *	\x83E\x83B\x83\x93\x83h\x83E\x82\xF0\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82\xA9\x82\xE7\x82͂ݏo\x82\xB3\x82Ȃ\xA2\x82悤\x82Ɉړ\xAE\x82\xB7\x82\xE9
- *	\x82͂ݏo\x82Ă\xA2\x82Ȃ\xA2\x8Fꍇ\x82͈ړ\xAE\x82\xB5\x82Ȃ\xA2
- *
- *	@param[in]	hWnd		\x88ʒu\x82𒲐\xAE\x82\xB7\x82\xE9\x83E\x83B\x83\x93\x83h\x83E
- */
-void MoveWindowToDisplay(HWND hWnd)
-{
-	RECT desktop;
-	RECT win_rect;
-	int win_width;
-	int win_height;
-	int win_x;
-	int win_y;
-	BOOL modify = FALSE;
-
-	GetDesktopRect(hWnd, &desktop);
-
-	GetWindowRect(hWnd, &win_rect);
-	win_x = win_rect.left;
-	win_y = win_rect.top;
-	win_height = win_rect.bottom - win_rect.top;
-	win_width = win_rect.right - win_rect.left;
-	if (win_y < desktop.top) {
-		win_y = desktop.top;
-		modify = TRUE;
-	}
-	else if (win_y + win_height > desktop.bottom) {
-		win_y = desktop.bottom - win_height;
-		modify = TRUE;
-	}
-	if (win_x < desktop.left) {
-		win_x = desktop.left;
-		modify = TRUE;
-	}
-	else if (win_x + win_width > desktop.right) {
-		win_x = desktop.right - win_width;
-		modify = TRUE;
-	}
-
-	if (modify) {
-		SetWindowPos(hWnd, NULL, win_x, win_y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
-	}
-}
-
-/**
- *	\x83E\x83B\x83\x93\x83h\x83E\x82\xF0\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82̒\x86\x89\x9B\x82ɔz\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
- *							(NULL\x82̏ꍇ\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82̒\x86\x89\x9B)
- *
- *	hWndParent\x82̎w\x92肪\x82\xA0\x82\xE9\x8Fꍇ
- *		hWndParent\x82\xAA\x95\\x8E\xA6\x8F\xF3\x91Ԃ̏ꍇ
- *			- hWndParent\x82̒\x86\x89\x9B\x82ɔz\x92u
- *			- \x82\xBD\x82\xBE\x82\xB5\x95\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82\xA9\x82\xE7\x82͂ݏo\x82\xB7\x8Fꍇ\x82͒\xB2\x90\xAE\x82\xB3\x82\xEA\x82\xE9
- *		hWndParent\x82\xAA\x94\xF1\x95\\x8E\xA6\x8F\xF3\x91Ԃ̏ꍇ
- *			- hWnd\x82\xAA\x95\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82̒\x86\x89\x9B\x82ɔz\x92u\x82\xB3\x82\xEA\x82\xE9
- *	hWndParent\x82\xAANULL\x82̏ꍇ
- *		- hWnd\x82\xAA\x95\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82̒\x86\x89\x9B\x82ɔz\x92u\x82\xB3\x82\xEA\x82\xE9
- */
-void CenterWindow(HWND hWnd, HWND hWndParent)
-{
-	RECT rcWnd;
-	LONG WndWidth;
-	LONG WndHeight;
-	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;
-
-	if (hWndParent == NULL || !IsWindowVisible(hWndParent) || IsIconic(hWndParent)) {
-		// \x90e\x82\xAA\x90ݒ肳\x82\xEA\x82Ă\xA2\x82Ȃ\xA2 or \x95\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82Ȃ\xA2 or icon\x89\xBB\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9 \x8Fꍇ
-		// \x83E\x83B\x83\x93\x83h\x83E\x82̕\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82̒\x86\x89\x9B\x82ɕ\\x8E\xA6\x82\xB7\x82\xE9
-		GetDesktopRect(hWnd, &rcDesktop);
-
-		// \x83f\x83X\x83N\x83g\x83b\x83v(\x95\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x83f\x83B\x83X\x83v\x83\x8C\x83C)\x82̒\x86\x89\x9B
-		NewX = (rcDesktop.left + rcDesktop.right) / 2 - WndWidth / 2;
-		NewY = (rcDesktop.top + rcDesktop.bottom) / 2 - WndHeight / 2;
-	} else {
-		RECT rcParent;
-		r = GetWindowRect(hWndParent, &rcParent);
-		assert(r != FALSE); (void)r;
-
-		// hWndParent\x82̒\x86\x89\x9B
-		NewX = (rcParent.left + rcParent.right) / 2 - WndWidth / 2;
-		NewY = (rcParent.top + rcParent.bottom) / 2 - WndHeight / 2;
-
-		GetDesktopRect(hWndParent, &rcDesktop);
-	}
-
-	// \x83f\x83X\x83N\x83g\x83b\x83v\x82\xA9\x82\xE7\x82͂ݏo\x82\xB7\x8Fꍇ\x81A\x92\xB2\x90\xAE\x82\xB7\x82\xE9
-	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);
-}
-
-/**
- *	hWnd\x82̕\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82郂\x83j\x83^\x82\xCCDPI\x82\xF0\x8E擾\x82\xB7\x82\xE9
- *	Per-monitor DPI awareness\x91Ή\x9E
- *
- *	@retval	DPI\x92l(\x92ʏ\xED\x82\xCCDPI\x82\xCD96)
- */
-int GetMonitorDpiFromWindow(HWND hWnd)
-{
-	if (pGetDpiForMonitor == NULL) {
-		// \x83_\x83C\x83A\x83\x8D\x83O\x93\xE0\x82ł͎\xA9\x93\xAE\x83X\x83P\x81[\x83\x8A\x83\x93\x83O\x82\xAA\x8C\xF8\x82\xA2\x82Ă\xA2\x82\xE9\x82̂\xC5
-		// \x8F\xED\x82\xC996\x82\xF0\x95Ԃ\xB7\x82悤\x82\xBE
-		int dpiY;
-		HDC hDC = GetDC(hWnd);
-		dpiY = GetDeviceCaps(hDC,LOGPIXELSY);
-		ReleaseDC(hWnd, hDC);
-		return dpiY;
-	} else {
-		UINT dpiX;
-		UINT dpiY;
-		HMONITOR hMonitor = pMonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
-		pGetDpiForMonitor(hMonitor, 0 /*0=MDT_EFFECTIVE_DPI*/, &dpiX, &dpiY);
-		return (int)dpiY;
-	}
-}
-
-/* vim: set ts=4 sw=4 ff=dos : */

Added: trunk/teraterm/common/ttlib_static.c
===================================================================
--- trunk/teraterm/common/ttlib_static.c	                        (rev 0)
+++ trunk/teraterm/common/ttlib_static.c	2020-02-25 14:11:17 UTC (rev 8564)
@@ -0,0 +1,282 @@
+/*
+ * Copyright (C) 1994-1998 T. Teranishi
+ * (C) 2006-2020 TeraTerm Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* misc. routines  */
+
+#include <sys/stat.h>
+#include <sys/utime.h>
+#include <string.h>
+#include <time.h>
+#include <stdio.h>
+#include <shlobj.h>
+#include <ctype.h>
+#include <mbctype.h>	// for _ismbblead
+#include <assert.h>
+
+#include "teraterm_conf.h"
+#include "teraterm.h"
+#include "tttypes.h"
+#include "compat_win.h"
+
+#include "../teraterm/unicode_test.h"
+
+
+/**
+ *	\x83E\x83B\x83\x93\x83h\x83E\x8F\xE3\x82̈ʒu\x82\xF0\x8E擾\x82\xB7\x82\xE9
+ *	@Param[in]		hWnd
+ *	@Param[in]		point		\x88ʒu(x,y)
+ *	@Param[in,out]	InWindow	\x83E\x83B\x83\x93\x83h\x83E\x8F\xE3
+ *	@Param[in,out]	InClient	\x83N\x83\x89\x83C\x83A\x83\x93\x83g\x97̈\xE6\x8F\xE3
+ *	@Param[in,out]	InTitleBar	\x83^\x83C\x83g\x83\x8B\x83o\x81[\x8F\xE3
+ *	@retval			FALSE		\x96\xB3\x8C\xF8\x82\xC8hWnd
+ */
+BOOL GetPositionOnWindow(
+	HWND hWnd, const POINT *point,
+	BOOL *InWindow, BOOL *InClient, BOOL *InTitleBar)
+{
+	const int x = point->x;
+	const int y = point->y;
+	RECT winRect;
+	RECT clientRect;
+
+	if (InWindow != NULL) *InWindow = FALSE;
+	if (InClient != NULL) *InClient = FALSE;
+	if (InTitleBar != NULL) *InTitleBar = FALSE;
+
+	if (!GetWindowRect(hWnd, &winRect)) {
+		return FALSE;
+	}
+
+	if ((x < winRect.left) || (winRect.right < x) ||
+		(y < winRect.top) || (winRect.bottom < y))
+	{
+		return TRUE;
+	}
+	if (InWindow != NULL) *InWindow = TRUE;
+
+	{
+		POINT pos;
+		GetClientRect(hWnd, &clientRect);
+		pos.x = clientRect.left;
+		pos.y = clientRect.top;
+		ClientToScreen(hWnd, &pos);
+		clientRect.left = pos.x;
+		clientRect.top = pos.y;
+
+		pos.x = clientRect.right;
+		pos.y = clientRect.bottom;
+		ClientToScreen(hWnd, &pos);
+		clientRect.right = pos.x;
+		clientRect.bottom = pos.y;
+	}
+
+	if ((clientRect.left <= x) && (x < clientRect.right) &&
+		(clientRect.top <= y) && (y < clientRect.bottom))
+	{
+		if (InClient != NULL) *InClient = TRUE;
+		if (InTitleBar != NULL) *InTitleBar = FALSE;
+		return TRUE;
+	}
+	if (InClient != NULL) *InClient = FALSE;
+
+	if (InTitleBar != NULL) {
+		*InTitleBar = (y < clientRect.top) ? TRUE : FALSE;
+	}
+
+	return TRUE;
+}
+
+int SetDlgTexts(HWND hDlgWnd, const DlgTextInfo *infos, int infoCount, const char *UILanguageFile)
+{
+	return SetI18nDlgStrs("Tera Term", hDlgWnd, infos, infoCount, UILanguageFile);
+}
+
+void SetDlgMenuTexts(HMENU hMenu, const DlgTextInfo *infos, int infoCount, const char *UILanguageFile)
+{
+	SetI18nMenuStrs("Tera Term", hMenu, infos, infoCount, UILanguageFile);
+}
+
+/**
+ *	\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 (pMonitorFromWindow != NULL) {
+		// \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 = pMonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
+		monitorInfo.cbSize = sizeof(MONITORINFO);
+		pGetMonitorInfoA(hMonitor, &monitorInfo);
+		*rect = monitorInfo.rcWork;
+	} else {
+		// \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);
+	}
+}
+
+/**
+ *	\x83E\x83B\x83\x93\x83h\x83E\x82\xF0\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82\xA9\x82\xE7\x82͂ݏo\x82\xB3\x82Ȃ\xA2\x82悤\x82Ɉړ\xAE\x82\xB7\x82\xE9
+ *	\x82͂ݏo\x82Ă\xA2\x82Ȃ\xA2\x8Fꍇ\x82͈ړ\xAE\x82\xB5\x82Ȃ\xA2
+ *
+ *	@param[in]	hWnd		\x88ʒu\x82𒲐\xAE\x82\xB7\x82\xE9\x83E\x83B\x83\x93\x83h\x83E
+ */
+void MoveWindowToDisplay(HWND hWnd)
+{
+	RECT desktop;
+	RECT win_rect;
+	int win_width;
+	int win_height;
+	int win_x;
+	int win_y;
+	BOOL modify = FALSE;
+
+	GetDesktopRect(hWnd, &desktop);
+
+	GetWindowRect(hWnd, &win_rect);
+	win_x = win_rect.left;
+	win_y = win_rect.top;
+	win_height = win_rect.bottom - win_rect.top;
+	win_width = win_rect.right - win_rect.left;
+	if (win_y < desktop.top) {
+		win_y = desktop.top;
+		modify = TRUE;
+	}
+	else if (win_y + win_height > desktop.bottom) {
+		win_y = desktop.bottom - win_height;
+		modify = TRUE;
+	}
+	if (win_x < desktop.left) {
+		win_x = desktop.left;
+		modify = TRUE;
+	}
+	else if (win_x + win_width > desktop.right) {
+		win_x = desktop.right - win_width;
+		modify = TRUE;
+	}
+
+	if (modify) {
+		SetWindowPos(hWnd, NULL, win_x, win_y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
+	}
+}
+
+/**
+ *	\x83E\x83B\x83\x93\x83h\x83E\x82\xF0\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82̒\x86\x89\x9B\x82ɔz\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
+ *							(NULL\x82̏ꍇ\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82̒\x86\x89\x9B)
+ *
+ *	hWndParent\x82̎w\x92肪\x82\xA0\x82\xE9\x8Fꍇ
+ *		hWndParent\x82\xAA\x95\\x8E\xA6\x8F\xF3\x91Ԃ̏ꍇ
+ *			- hWndParent\x82̒\x86\x89\x9B\x82ɔz\x92u
+ *			- \x82\xBD\x82\xBE\x82\xB5\x95\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82\xA9\x82\xE7\x82͂ݏo\x82\xB7\x8Fꍇ\x82͒\xB2\x90\xAE\x82\xB3\x82\xEA\x82\xE9
+ *		hWndParent\x82\xAA\x94\xF1\x95\\x8E\xA6\x8F\xF3\x91Ԃ̏ꍇ
+ *			- hWnd\x82\xAA\x95\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82̒\x86\x89\x9B\x82ɔz\x92u\x82\xB3\x82\xEA\x82\xE9
+ *	hWndParent\x82\xAANULL\x82̏ꍇ
+ *		- hWnd\x82\xAA\x95\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82̒\x86\x89\x9B\x82ɔz\x92u\x82\xB3\x82\xEA\x82\xE9
+ */
+void CenterWindow(HWND hWnd, HWND hWndParent)
+{
+	RECT rcWnd;
+	LONG WndWidth;
+	LONG WndHeight;
+	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;
+
+	if (hWndParent == NULL || !IsWindowVisible(hWndParent) || IsIconic(hWndParent)) {
+		// \x90e\x82\xAA\x90ݒ肳\x82\xEA\x82Ă\xA2\x82Ȃ\xA2 or \x95\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82Ȃ\xA2 or icon\x89\xBB\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9 \x8Fꍇ
+		// \x83E\x83B\x83\x93\x83h\x83E\x82̕\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82̒\x86\x89\x9B\x82ɕ\\x8E\xA6\x82\xB7\x82\xE9
+		GetDesktopRect(hWnd, &rcDesktop);
+
+		// \x83f\x83X\x83N\x83g\x83b\x83v(\x95\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9\x83f\x83B\x83X\x83v\x83\x8C\x83C)\x82̒\x86\x89\x9B
+		NewX = (rcDesktop.left + rcDesktop.right) / 2 - WndWidth / 2;
+		NewY = (rcDesktop.top + rcDesktop.bottom) / 2 - WndHeight / 2;
+	} else {
+		RECT rcParent;
+		r = GetWindowRect(hWndParent, &rcParent);
+		assert(r != FALSE); (void)r;
+
+		// hWndParent\x82̒\x86\x89\x9B
+		NewX = (rcParent.left + rcParent.right) / 2 - WndWidth / 2;
+		NewY = (rcParent.top + rcParent.bottom) / 2 - WndHeight / 2;
+
+		GetDesktopRect(hWndParent, &rcDesktop);
+	}
+
+	// \x83f\x83X\x83N\x83g\x83b\x83v\x82\xA9\x82\xE7\x82͂ݏo\x82\xB7\x8Fꍇ\x81A\x92\xB2\x90\xAE\x82\xB7\x82\xE9
+	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);
+}
+
+/**
+ *	hWnd\x82̕\\x8E\xA6\x82\xB3\x82\xEA\x82Ă\xA2\x82郂\x83j\x83^\x82\xCCDPI\x82\xF0\x8E擾\x82\xB7\x82\xE9
+ *	Per-monitor DPI awareness\x91Ή\x9E
+ *
+ *	@retval	DPI\x92l(\x92ʏ\xED\x82\xCCDPI\x82\xCD96)
+ */
+int GetMonitorDpiFromWindow(HWND hWnd)
+{
+	if (pGetDpiForMonitor == NULL) {
+		// \x83_\x83C\x83A\x83\x8D\x83O\x93\xE0\x82ł͎\xA9\x93\xAE\x83X\x83P\x81[\x83\x8A\x83\x93\x83O\x82\xAA\x8C\xF8\x82\xA2\x82Ă\xA2\x82\xE9\x82̂\xC5
+		// \x8F\xED\x82\xC996\x82\xF0\x95Ԃ\xB7\x82悤\x82\xBE
+		int dpiY;
+		HDC hDC = GetDC(hWnd);
+		dpiY = GetDeviceCaps(hDC,LOGPIXELSY);
+		ReleaseDC(hWnd, hDC);
+		return dpiY;
+	} else {
+		UINT dpiX;
+		UINT dpiY;
+		HMONITOR hMonitor = pMonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
+		pGetDpiForMonitor(hMonitor, 0 /*0=MDT_EFFECTIVE_DPI*/, &dpiX, &dpiY);
+		return (int)dpiY;
+	}
+}
+
+/* vim: set ts=4 sw=4 ff=dos : */


Ttssh2-commit メーリングリストの案内
Back to archive index