[Ttssh2-commit] [7681] GetDesktopRect()#ttlib.cで、マルチモニタ系APIを直接使用しないようにした

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2019年 5月 15日 (水) 23:28:20 JST


Revision: 7681
          https://osdn.net/projects/ttssh2/scm/svn/commits/7681
Author:   zmatsuo
Date:     2019-05-15 23:28:19 +0900 (Wed, 15 May 2019)
Log Message:
-----------
GetDesktopRect()#ttlib.cで、マルチモニタ系APIを直接使用しないようにした

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

-------------- next part --------------
Modified: trunk/teraterm/common/ttlib.c
===================================================================
--- trunk/teraterm/common/ttlib.c	2019-05-14 13:54:39 UTC (rev 7680)
+++ trunk/teraterm/common/ttlib.c	2019-05-15 14:28:19 UTC (rev 7681)
@@ -104,6 +104,11 @@
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
 };
 
+static HMODULE hModuleUser32;
+static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR hMonitor, LPMONITORINFO lpmi);
+static HMONITOR (WINAPI *pMonitorFromWindow)(HWND hwnd, DWORD dwFlags);
+static HMONITOR (WINAPI *pMonitorFromPoint)(POINT pt, DWORD dwFlags);
+
 void b64encode(PCHAR d, int dsize, PCHAR s, int len)
 {
 	unsigned int b = 0;
@@ -1421,13 +1426,19 @@
 //   98 \x88ȍ~/2000 \x88ȍ~\x82\xCD TRUE \x82\xF0\x95Ԃ\xB7
 BOOL HasMultiMonitorSupport()
 {
-	HMODULE mod;
-
-	if (((mod = GetModuleHandle("user32.dll")) != NULL) &&
-	    (GetProcAddress(mod, "MonitorFromPoint") != NULL)) {
-		return TRUE;
+	if (hModuleUser32 == NULL) {
+		hModuleUser32 = GetModuleHandle("user32.dll");
+		if (hModuleUser32 == NULL) {
+			return FALSE;	// \x82\xBD\x82Ԃ񂠂蓾\x82Ȃ\xA2
+		}
 	}
-	return FALSE;
+	if (pMonitorFromPoint == NULL) {
+		pMonitorFromPoint = (void *)GetProcAddress(hModuleUser32, "MonitorFromPoint");
+	}
+	if (pMonitorFromPoint == NULL) {
+		return FALSE;
+	}
+	return TRUE;
 }
 
 // OS \x82\xAA GetAdaptersAddresses \x82\xF0\x83T\x83|\x81[\x83g\x82\xB5\x82Ă\xA2\x82邩\x82ǂ\xA4\x82\xA9\x82𔻕ʂ\xB7\x82\xE9\x81B
@@ -1855,12 +1866,29 @@
  */
 void GetDesktopRect(HWND hWnd, RECT *rect)
 {
-	if (HasMultiMonitorSupport()) {
+	BOOL Supported = TRUE;
+	if (!HasMultiMonitorSupport()) {
+		Supported = FALSE;
+	}
+	if (Supported) {
+		if (pGetMonitorInfoA == NULL) {
+			// hModuleUser32\x82̓Z\x83b\x83g\x82\xB3\x82\xEA\x82Ă\xA2\x82\xE9
+			pGetMonitorInfoA = (void *)GetProcAddress(hModuleUser32, "GetMonitorInfoA");
+		}
+		if (pMonitorFromWindow == NULL) {
+			pMonitorFromWindow = (void *)GetProcAddress(hModuleUser32, "MonitorFromWindow");
+		}
+		if (pGetMonitorInfoA == NULL || pMonitorFromWindow == NULL) {
+			Supported = FALSE;
+		}
+	}
+
+	if (Supported) {
 		// \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ꍇ


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