[Ttssh2-commit] [8504] マルチモニタ関連のAPIを直接呼ばないようにした

scmno****@osdn***** scmno****@osdn*****
2020年 1月 27日 (月) 00:13:39 JST


Revision: 8504
          https://osdn.net/projects/ttssh2/scm/svn/commits/8504
Author:   zmatsuo
Date:     2020-01-27 00:13:39 +0900 (Mon, 27 Jan 2020)
Log Message:
-----------
マルチモニタ関連のAPIを直接呼ばないようにした

- MonitorFromWindow(), MonitorFromPoint(), GetMonitorInfo()
- pMonitorFromWindow(), pMonitorFromPoint(), pGetMonitorInfoA() を追加
- 使用しなくなった GetMonitorLeftmost() を削除

Modified Paths:
--------------
    trunk/teraterm/common/compat_win.cpp
    trunk/teraterm/common/compat_win.h
    trunk/teraterm/common/ttlib.c
    trunk/teraterm/teraterm/clipboarddlg.cpp
    trunk/teraterm/teraterm/sizetip.c
    trunk/teraterm/ttpmacro/macrodlgbase.h
    trunk/teraterm/ttpmacro/ttmlib.c
    trunk/teraterm/ttpmacro/ttmlib.h

-------------- next part --------------
Modified: trunk/teraterm/common/compat_win.cpp
===================================================================
--- trunk/teraterm/common/compat_win.cpp	2020-01-26 15:13:29 UTC (rev 8503)
+++ trunk/teraterm/common/compat_win.cpp	2020-01-26 15:13:39 UTC (rev 8504)
@@ -74,6 +74,10 @@
 BOOL (WINAPI *pInsertMenuW)(HMENU hMenu, UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem, LPCWSTR lpNewItem);
 BOOL (WINAPI *pAppendMenuW)(HMENU hMenu, UINT uFlags, UINT_PTR uIDNewItem, LPCWSTR lpNewItem);
 
+HMONITOR (WINAPI *pMonitorFromWindow)(HWND hwnd, DWORD dwFlags);
+HMONITOR (WINAPI *pMonitorFromPoint)(POINT pt, DWORD dwFlags);
+BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR hMonitor, LPMONITORINFO lpmi);
+
 /**
  *	GetConsoleWindow() \x82Ɠ\xAF\x82\xB6\x93\xAE\x8D\xEC\x82\xF0\x82\xB7\x82\xE9
  *	 https://support.microsoft.com/ja-jp/help/124103/how-to-obtain-a-console-window-handle-hwnd
@@ -131,6 +135,9 @@
 	{ "DialogBoxIndirectParamW", (void **)&pDialogBoxIndirectParamW },
 	{ "InsertMenuW", (void **)&pInsertMenuW },
 	{ "AppendMenuW", (void **)&pAppendMenuW },
+	{ "MonitorFromWindow", (void **)&pMonitorFromWindow },
+	{ "MonitorFromPoint", (void **)&pMonitorFromPoint },
+	{ "GetMonitorInfoA", (void **)&pGetMonitorInfoA },
 	{},
 };
 

Modified: trunk/teraterm/common/compat_win.h
===================================================================
--- trunk/teraterm/common/compat_win.h	2020-01-26 15:13:29 UTC (rev 8503)
+++ trunk/teraterm/common/compat_win.h	2020-01-26 15:13:39 UTC (rev 8504)
@@ -104,7 +104,11 @@
 extern HWND (WINAPI *pHtmlHelpA)(HWND hwndCaller, LPCSTR pszFile, UINT uCommand, DWORD_PTR dwData);
 extern BOOL (WINAPI *pInsertMenuW)(HMENU hMenu, UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem, LPCWSTR lpNewItem);
 extern BOOL (WINAPI *pAppendMenuW)(HMENU hMenu, UINT uFlags, UINT_PTR uIDNewItem, LPCWSTR lpNewItem);
+extern HMONITOR (WINAPI *pMonitorFromWindow)(HWND hwnd, DWORD dwFlags);
+extern HMONITOR (WINAPI *pMonitorFromPoint)(POINT pt, DWORD dwFlags);
+extern BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR hMonitor, LPMONITORINFO lpmi);
 
+
 #ifdef UNICODE
 #define pAddFontResourceEx		pAddFontResourceExW
 #define pRemoveFontResourceEx	pRemoveFontResourceExW

Modified: trunk/teraterm/common/ttlib.c
===================================================================
--- trunk/teraterm/common/ttlib.c	2020-01-26 15:13:29 UTC (rev 8503)
+++ trunk/teraterm/common/ttlib.c	2020-01-26 15:13:39 UTC (rev 8504)
@@ -1902,12 +1902,12 @@
  */
 void GetDesktopRect(HWND hWnd, RECT *rect)
 {
-	if (HasMultiMonitorSupport()) {
+	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 = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
+		HMONITOR hMonitor = pMonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
 		monitorInfo.cbSize = sizeof(MONITORINFO);
-		GetMonitorInfo(hMonitor, &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ꍇ
@@ -2035,14 +2035,6 @@
  */
 int GetMonitorDpiFromWindow(HWND hWnd)
 {
-	static HRESULT (__stdcall  *pGetDpiForMonitor)(HMONITOR hmonitor, int/*enum MONITOR_DPI_TYPE*/ dpiType, UINT *dpiX, UINT *dpiY);
-	static HMODULE hDll;
-	if (hDll == NULL) {
-		hDll = LoadLibraryA("Shcore.dll");
-		if (hDll != NULL) {
-			pGetDpiForMonitor = (void *)GetProcAddress(hDll, "GetDpiForMonitor");
-		}
-	}
 	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
@@ -2054,7 +2046,7 @@
 	} else {
 		UINT dpiX;
 		UINT dpiY;
-		HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
+		HMONITOR hMonitor = pMonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
 		pGetDpiForMonitor(hMonitor, 0 /*0=MDT_EFFECTIVE_DPI*/, &dpiX, &dpiY);
 		return (int)dpiY;
 	}

Modified: trunk/teraterm/teraterm/clipboarddlg.cpp
===================================================================
--- trunk/teraterm/teraterm/clipboarddlg.cpp	2020-01-26 15:13:29 UTC (rev 8503)
+++ trunk/teraterm/teraterm/clipboarddlg.cpp	2020-01-26 15:13:39 UTC (rev 8504)
@@ -1,5 +1,5 @@
 /*
- * (C) 2019 TeraTerm Project
+ * (C) 2019-2020 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -44,6 +44,7 @@
 #include "layer_for_unicode.h"
 #include "tt_res.h"
 #include "clipboarddlg.h"
+#include "compat_win.h"
 
 static INT_PTR CALLBACK OnClipboardDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
 {
@@ -104,7 +105,7 @@
 			// \x83L\x83\x83\x83\x8C\x83b\x83g\x82\xAA\x89\xE6\x96ʂ\xA9\x82\xE7\x82͂ݏo\x82\xB5\x82Ă\xA2\x82\xE9\x82Ƃ\xAB\x82ɓ\\x82\xE8\x95t\x82\xAF\x82\xF0\x82\xB7\x82\xE9\x82\xC6
 			// \x8Am\x94F\x83E\x83C\x83\x93\x83h\x83E\x82\xAA\x8C\xA9\x82\xA6\x82\xE9\x82Ƃ\xB1\x82\xEB\x82ɕ\\x8E\xA6\x82\xB3\x82\xEA\x82Ȃ\xA2\x82\xB1\x82Ƃ\xAA\x82\xA0\x82\xE9\x81B
 			// \x83E\x83C\x83\x93\x83h\x83E\x82\xA9\x82\xE7\x82͂ݏo\x82\xB5\x82\xBD\x8Fꍇ\x82ɒ\xB2\x90߂\xB7\x82\xE9 (2008.4.24 maya)
-			if (!HasMultiMonitorSupport()) {
+			if (pMonitorFromPoint == NULL) {
 				// NT4.0, 95 \x82̓}\x83\x8B\x83`\x83\x82\x83j\x83^API\x82ɔ\xF1\x91Ή\x9E
 				SystemParametersInfo(SPI_GETWORKAREA, 0, &rc_dsk, 0);
 			}
@@ -115,10 +116,10 @@
 
 				pt.x = p.x;
 				pt.y = p.y;
-				hm = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
+				hm = pMonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
 
 				mi.cbSize = sizeof(MONITORINFO);
-				GetMonitorInfo(hm, &mi);
+				pGetMonitorInfoA(hm, &mi);
 				rc_dsk = mi.rcWork;
 			}
 			GetWindowRect(hDlgWnd, &rc_dlg);

Modified: trunk/teraterm/teraterm/sizetip.c
===================================================================
--- trunk/teraterm/teraterm/sizetip.c	2020-01-26 15:13:29 UTC (rev 8503)
+++ trunk/teraterm/teraterm/sizetip.c	2020-01-26 15:13:39 UTC (rev 8504)
@@ -31,6 +31,7 @@
 #include "tttypes.h"
 #include "ttlib.h"
 #include "ttwinman.h"
+#include "compat_win.h"
 
 #include <windows.h>
 #include <stdio.h>
@@ -60,20 +61,20 @@
 		ix = point->x;
 		iy = point->y;
 
-		hm = MonitorFromPoint(*point, MONITOR_DEFAULTTONULL);
+		hm = pMonitorFromPoint(*point, MONITOR_DEFAULTTONULL);
 		if (hm == NULL) {
 			if (NearestMonitor) {
 				// \x8Dł\xE0\x8B߂\xA2\x83\x82\x83j\x83^\x82ɕ\\x8E\xA6\x82\xB7\x82\xE9
-				hm = MonitorFromPoint(*point, MONITOR_DEFAULTTONEAREST);
+				hm = pMonitorFromPoint(*point, MONITOR_DEFAULTTONEAREST);
 			} else {
 				// \x83X\x83N\x83\x8A\x81[\x83\x93\x82\xA9\x82\xE7\x82͂ݏo\x82\xB5\x82Ă\xA2\x82\xE9\x8Fꍇ\x82̓}\x83E\x83X\x82̂\xA0\x82郂\x83j\x83^\x82ɕ\\x8E\xA6\x82\xB7\x82\xE9
 				GetCursorPos(point);
-				hm = MonitorFromPoint(*point, MONITOR_DEFAULTTONEAREST);
+				hm = pMonitorFromPoint(*point, MONITOR_DEFAULTTONEAREST);
 			}
 		}
 
 		mi.cbSize = sizeof(MONITORINFO);
-		GetMonitorInfo(hm, &mi);
+		pGetMonitorInfoA(hm, &mi);
 		if (ix < mi.rcMonitor.left + FrameWidth) {
 			ix = mi.rcMonitor.left + FrameWidth;
 		}

Modified: trunk/teraterm/ttpmacro/macrodlgbase.h
===================================================================
--- trunk/teraterm/ttpmacro/macrodlgbase.h	2020-01-26 15:13:29 UTC (rev 8503)
+++ trunk/teraterm/ttpmacro/macrodlgbase.h	2020-01-26 15:13:39 UTC (rev 8504)
@@ -95,7 +95,6 @@
 	 */
 	BOOL IsValidPos()
 	{
-		// return !(PosX <= GetMonitorLeftmost(PosX, PosY) - 100);
 		return !((PosX == CW_USEDEFAULT) || (PosY == CW_USEDEFAULT));
 	}
 };

Modified: trunk/teraterm/ttpmacro/ttmlib.c
===================================================================
--- trunk/teraterm/ttpmacro/ttmlib.c	2020-01-26 15:13:29 UTC (rev 8503)
+++ trunk/teraterm/ttpmacro/ttmlib.c	2020-01-26 15:13:39 UTC (rev 8504)
@@ -198,27 +198,6 @@
 	return 0;
 }
 
-int GetMonitorLeftmost(int PosX, int PosY)
-{
-	if (!HasMultiMonitorSupport()) {
-		// // NT4.0, 95 \x82̓}\x83\x8B\x83`\x83\x82\x83j\x83^API\x82ɔ\xF1\x91Ή\x9E
-		return 0;
-	}
-	else {
-		HMONITOR hm;
-		POINT pt;
-		MONITORINFO mi;
-
-		pt.x = PosX;
-		pt.y = PosY;
-		hm = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
-
-		mi.cbSize = sizeof(MONITORINFO);
-		GetMonitorInfo(hm, &mi);
-		return mi.rcWork.left;
-	}
-}
-
 void BringupWindow(HWND hWnd)
 {
 	DWORD thisThreadId;

Modified: trunk/teraterm/ttpmacro/ttmlib.h
===================================================================
--- trunk/teraterm/ttpmacro/ttmlib.h	2020-01-26 15:13:29 UTC (rev 8503)
+++ trunk/teraterm/ttpmacro/ttmlib.h	2020-01-26 15:13:39 UTC (rev 8504)
@@ -44,7 +44,6 @@
 void TTMSetDir(PCHAR Dir);
 int GetAbsPath(PCHAR FName, int destlen);
 int GetSpecialFolder(PCHAR dest, int dest_len, PCHAR type);
-int GetMonitorLeftmost(int PosX, int PosY);
 void BringupWindow(HWND hWnd);
 int MessageBoxHaltScript(HWND hWnd);
 


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