[Ttssh2-commit] [7713] ウィンドウが表示されているモニタのDPIを返す関数追加

scmno****@osdn***** scmno****@osdn*****
2019年 5月 27日 (月) 22:23:08 JST


Revision: 7713
          https://osdn.net/projects/ttssh2/scm/svn/commits/7713
Author:   zmatsuo
Date:     2019-05-27 22:23:08 +0900 (Mon, 27 May 2019)
Log Message:
-----------
ウィンドウが表示されているモニタのDPIを返す関数追加

- GetMonitorDpiFromWindow(HWND hWnd);

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-05-25 14:54:04 UTC (rev 7712)
+++ trunk/teraterm/common/ttlib.c	2019-05-27 13:23:08 UTC (rev 7713)
@@ -1911,3 +1911,36 @@
 	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)
+{
+	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
+		int dpiY;
+		HDC hDC = GetDC(hWnd);
+		dpiY = GetDeviceCaps(hDC,LOGPIXELSY);
+		ReleaseDC(hWnd, hDC);
+		return dpiY;
+	} else {
+		UINT dpiX;
+		UINT dpiY;
+		HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
+		pGetDpiForMonitor(hMonitor, 0 /*0=MDT_EFFECTIVE_DPI*/, &dpiX, &dpiY);
+		return (int)dpiY;
+	}
+}

Modified: trunk/teraterm/common/ttlib.h
===================================================================
--- trunk/teraterm/common/ttlib.h	2019-05-25 14:54:04 UTC (rev 7712)
+++ trunk/teraterm/common/ttlib.h	2019-05-27 13:23:08 UTC (rev 7713)
@@ -124,6 +124,7 @@
 
 void SetDlgTexts(HWND hDlgWnd, const DlgTextInfo *infos, int infoCount, const char *UILanguageFile);
 void SetDlgMenuTexts(HMENU hMenu, const DlgTextInfo *infos, int infoCount, const char *UILanguageFile);
+int GetMonitorDpiFromWindow(HWND hWnd);
 
 #if defined(_UNICODE)
 #define	doSelectFolderT(p1, p2, p3, p4, p5) doSelectFolderW(p1, p2, p3, p4, p5)


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