• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision7681 (tree)
Time2019-05-15 23:28:19
Authorzmatsuo

Log Message

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

Change Summary

Incremental Difference

--- trunk/teraterm/common/ttlib.c (revision 7680)
+++ trunk/teraterm/common/ttlib.c (revision 7681)
@@ -104,6 +104,11 @@
104104 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
105105 };
106106
107+static HMODULE hModuleUser32;
108+static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR hMonitor, LPMONITORINFO lpmi);
109+static HMONITOR (WINAPI *pMonitorFromWindow)(HWND hwnd, DWORD dwFlags);
110+static HMONITOR (WINAPI *pMonitorFromPoint)(POINT pt, DWORD dwFlags);
111+
107112 void b64encode(PCHAR d, int dsize, PCHAR s, int len)
108113 {
109114 unsigned int b = 0;
@@ -1421,13 +1426,19 @@
14211426 // 98 以降/2000 以降は TRUE を返す
14221427 BOOL HasMultiMonitorSupport()
14231428 {
1424- HMODULE mod;
1425-
1426- if (((mod = GetModuleHandle("user32.dll")) != NULL) &&
1427- (GetProcAddress(mod, "MonitorFromPoint") != NULL)) {
1428- return TRUE;
1429+ if (hModuleUser32 == NULL) {
1430+ hModuleUser32 = GetModuleHandle("user32.dll");
1431+ if (hModuleUser32 == NULL) {
1432+ return FALSE; // たぶんあり得ない
1433+ }
14291434 }
1430- return FALSE;
1435+ if (pMonitorFromPoint == NULL) {
1436+ pMonitorFromPoint = (void *)GetProcAddress(hModuleUser32, "MonitorFromPoint");
1437+ }
1438+ if (pMonitorFromPoint == NULL) {
1439+ return FALSE;
1440+ }
1441+ return TRUE;
14311442 }
14321443
14331444 // OS が GetAdaptersAddresses をサポートしているかどうかを判別する。
@@ -1855,12 +1866,29 @@
18551866 */
18561867 void GetDesktopRect(HWND hWnd, RECT *rect)
18571868 {
1858- if (HasMultiMonitorSupport()) {
1869+ BOOL Supported = TRUE;
1870+ if (!HasMultiMonitorSupport()) {
1871+ Supported = FALSE;
1872+ }
1873+ if (Supported) {
1874+ if (pGetMonitorInfoA == NULL) {
1875+ // hModuleUser32はセットされている
1876+ pGetMonitorInfoA = (void *)GetProcAddress(hModuleUser32, "GetMonitorInfoA");
1877+ }
1878+ if (pMonitorFromWindow == NULL) {
1879+ pMonitorFromWindow = (void *)GetProcAddress(hModuleUser32, "MonitorFromWindow");
1880+ }
1881+ if (pGetMonitorInfoA == NULL || pMonitorFromWindow == NULL) {
1882+ Supported = FALSE;
1883+ }
1884+ }
1885+
1886+ if (Supported) {
18591887 // マルチモニタがサポートされている場合
18601888 MONITORINFO monitorInfo;
1861- HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
1889+ HMONITOR hMonitor = pMonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
18621890 monitorInfo.cbSize = sizeof(MONITORINFO);
1863- GetMonitorInfo(hMonitor, &monitorInfo);
1891+ pGetMonitorInfoA(hMonitor, &monitorInfo);
18641892 *rect = monitorInfo.rcWork;
18651893 } else {
18661894 // マルチモニタがサポートされていない場合
Show on old repository browser