[Ttssh2-commit] [8374] DPIが変化したとき強制終了しないよう修正

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2019年 11月 16日 (土) 02:02:32 JST


Revision: 8374
          https://osdn.net/projects/ttssh2/scm/svn/commits/8374
Author:   zmatsuo
Date:     2019-11-16 02:02:31 +0900 (Sat, 16 Nov 2019)
Log Message:
-----------
DPIが変化したとき強制終了しないよう修正

- Windows 8.1のとき
- DPIの異なるディスプレイ間を移動したときなど
- Windows 10 1607 以降でしか使えない AdjustWindowRectExForDpi() を使用していた
- AdjustWindowRectExForDpi() が使えない場合は AdjustWindowRectEx() を使用するようにした
- Ticket: #39746
- Ticket: #39764

Ticket Links:
------------
    https://osdn.net/projects/ttssh2/tracker/detail/39746
    https://osdn.net/projects/ttssh2/tracker/detail/39764

Modified Paths:
--------------
    trunk/doc/en/html/about/history.html
    trunk/doc/ja/html/about/history.html
    trunk/teraterm/common/compat_win.cpp
    trunk/teraterm/common/compat_win.h
    trunk/teraterm/teraterm/vtwin.cpp

-------------- next part --------------
Modified: trunk/doc/en/html/about/history.html
===================================================================
--- trunk/doc/en/html/about/history.html	2019-11-15 17:02:20 UTC (rev 8373)
+++ trunk/doc/en/html/about/history.html	2019-11-15 17:02:31 UTC (rev 8374)
@@ -74,6 +74,7 @@
       <li>Don't close MACRO window when ESC key is pressed. This bug was introduced in 4.103.</li>
       <li>Tera Term is not terminate when TEK window is closed. This bug was introduced in 4.103.</li>
       <!--li>\x83\x81\x83j\x83\x85\x81[\x83o\x81[\x94\xF1\x95\\x8E\xA6\x8E\x9E\x81ADPI\x82\xAA\x95ω\xBB\x82\xB5\x82\xBD\x82Ƃ\xAB\x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82𐳂\xB5\x82\xAD\x92\xB2\x90\xAE\x82\xB7\x82\xE9\x82悤\x8FC\x90\xB3</li-->
+      <!--li>Windows 8.1\x82ŁADPI\x82\xAA\x95ω\xBB\x82\xB5\x82\xBD\x82Ƃ\xAB Tera Term \x82\xAA\x8B\xAD\x90\xA7\x8FI\x97\xB9\x82\xB5\x82Ȃ\xA2\x82悤\x82ɂ\xB5\x82\xBD\x81B</li-->
     </ul>
   </li>
 

Modified: trunk/doc/ja/html/about/history.html
===================================================================
--- trunk/doc/ja/html/about/history.html	2019-11-15 17:02:20 UTC (rev 8373)
+++ trunk/doc/ja/html/about/history.html	2019-11-15 17:02:31 UTC (rev 8374)
@@ -73,7 +73,8 @@
       <li>Windows2000\x81`10\x82ŁA\x88\xF3\x8D\xFC\x83_\x83C\x83A\x83\x8D\x83O\x82Ƀw\x83\x8B\x83v\x83{\x83^\x83\x93\x82\xAA\x95\\x8E\xA6\x82\xB3\x82\xEA\x82Ȃ\xA2\x96\xE2\x91\xE8\x82\xF0\x8FC\x90\xB3\x82\xB5\x82\xBD(Windows95\x82͏\x9C\x82\xAD)\x81B</li>
       <li>MACRO \x83E\x83B\x83\x93\x83h\x83E\x82ŁAESC\x83L\x81[\x82\xF0\x89\x9F\x89\xBA\x8E\x9E\x8FI\x97\xB9\x82\xB5\x82Ȃ\xA2\x82悤\x82ɂ\xB5\x82\xBD\x81B4.103\x82ł̃G\x83\x93\x83o\x83O\x81B</li>
       <li>TEK\x83E\x83B\x83\x93\x83h\x83E\x82\xF0\x95‚\xB6\x82\xBD\x82Ƃ\xAB Tera Term \x8E\xA9\x90g\x82͏I\x97\xB9\x82\xB5\x82Ȃ\xA2\x82悤\x82ɂ\xB5\x82\xBD\x81B4.103\x82ł̃G\x83\x93\x83o\x83O\x81B</li>
-      <li>\x83\x81\x83j\x83\x85\x81[\x83o\x81[\x94\xF1\x95\\x8E\xA6\x8E\x9E\x81A\x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82𐳂\xB5\x82\xAD\x92\xB2\x90\xAE\x82\xB7\x82\xE9\x82悤\x8FC\x90\xB3</li>
+      <li>\x83\x81\x83j\x83\x85\x81[\x83o\x81[\x94\xF1\x95\\x8E\xA6\x8E\x9E\x81ADPI\x82\xAA\x95ω\xBB\x82\xB5\x82\xBD\x82Ƃ\xAB\x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82𐳂\xB5\x82\xAD\x92\xB2\x90\xAE\x82\xB7\x82\xE9\x82悤\x8FC\x90\xB3</li>
+      <li>Windows 8.1\x82ŁADPI\x82\xAA\x95ω\xBB\x82\xB5\x82\xBD\x82Ƃ\xAB Tera Term \x82\xAA\x8B\xAD\x90\xA7\x8FI\x97\xB9\x82\xB5\x82Ȃ\xA2\x82悤\x82ɂ\xB5\x82\xBD\x81B</li>
     </ul>
   </li>
 

Modified: trunk/teraterm/common/compat_win.cpp
===================================================================
--- trunk/teraterm/common/compat_win.cpp	2019-11-15 17:02:20 UTC (rev 8373)
+++ trunk/teraterm/common/compat_win.cpp	2019-11-15 17:02:31 UTC (rev 8374)
@@ -46,6 +46,7 @@
 BOOL (WINAPI *pRemoveFontResourceExW)(LPCWSTR name, DWORD fl, PVOID pdv);
 HRESULT (WINAPI *pGetDpiForMonitor)(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT *dpiX, UINT *dpiY);
 HMONITOR (WINAPI *pMonitorFromRect)(LPCRECT lprc, DWORD dwFlags);
+BOOL (WINAPI *pAdjustWindowRectEx)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle);
 BOOL (WINAPI *pAdjustWindowRectExForDpi)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi);
 
 static const APIInfo Lists_user32[] = {
@@ -54,6 +55,7 @@
 	{ "IsValidDpiAwarenessContext", (void **)&pIsValidDpiAwarenessContext },
 	{ "GetDpiForWindow", (void **)&pGetDpiForWindow },
 	{ "MonitorFromRect", (void **)&pMonitorFromRect },
+	{ "AdjustWindowRectEx", (void **)&pAdjustWindowRectEx },
 	{ "AdjustWindowRectExForDpi", (void **)&pAdjustWindowRectExForDpi },
 	{},
 };

Modified: trunk/teraterm/common/compat_win.h
===================================================================
--- trunk/teraterm/common/compat_win.h	2019-11-15 17:02:20 UTC (rev 8373)
+++ trunk/teraterm/common/compat_win.h	2019-11-15 17:02:31 UTC (rev 8374)
@@ -74,6 +74,7 @@
 extern BOOL (WINAPI *pIsValidDpiAwarenessContext)(DPI_AWARENESS_CONTEXT dpiContext);
 extern UINT (WINAPI *pGetDpiForWindow)(HWND hwnd);
 extern HRESULT (WINAPI *pGetDpiForMonitor)(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT *dpiX, UINT *dpiY);
+extern BOOL (WINAPI *pAdjustWindowRectEx)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle);
 extern BOOL (WINAPI *pAdjustWindowRectExForDpi)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi);
 extern BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
 extern int (WINAPI *pAddFontResourceExA)(LPCSTR name, DWORD fl, PVOID res);

Modified: trunk/teraterm/teraterm/vtwin.cpp
===================================================================
--- trunk/teraterm/teraterm/vtwin.cpp	2019-11-15 17:02:20 UTC (rev 8373)
+++ trunk/teraterm/teraterm/vtwin.cpp	2019-11-15 17:02:31 UTC (rev 8374)
@@ -6228,13 +6228,37 @@
 	//AdjustScrollBar();
 
 	// \x83X\x83N\x83\x8A\x81[\x83\x93\x83T\x83C\x83Y(=Client Area\x82̃T\x83C\x83Y)\x82\xA9\x82\xE7\x83E\x83B\x83\x93\x83h\x83E\x83T\x83C\x83Y\x82\xF0\x8EZ\x8Fo
-	const LONG_PTR Style = ::GetWindowLongPtr(m_hWnd, GWL_STYLE);
-	const LONG_PTR ExStyle = ::GetWindowLongPtr(m_hWnd, GWL_EXSTYLE);
-	const BOOL bMenu = (ts.PopupMenu != 0) ? FALSE : TRUE;
-	RECT Rect = {0, 0, ScreenWidth, ScreenHeight};
-	pAdjustWindowRectExForDpi(&Rect, Style, bMenu, ExStyle, NewDPI);
-	const int NewWindowWidth = Rect.right - Rect.left;
-	const int NewWindowHeight = Rect.bottom - Rect.top;
+	int NewWindowWidth;
+	int NewWindowHeight;
+	if (pAdjustWindowRectExForDpi != NULL || pAdjustWindowRectEx != NULL) {
+		const LONG_PTR Style = ::GetWindowLongPtr(m_hWnd, GWL_STYLE);
+		const LONG_PTR ExStyle = ::GetWindowLongPtr(m_hWnd, GWL_EXSTYLE);
+		const BOOL bMenu = (ts.PopupMenu != 0) ? FALSE : TRUE;
+		RECT Rect = {0, 0, ScreenWidth, ScreenHeight};
+		if (pAdjustWindowRectExForDpi != NULL) {
+			// Windows 10, version 1607+
+			pAdjustWindowRectExForDpi(&Rect, Style, bMenu, ExStyle, NewDPI);
+		}
+		else {
+			// Windows 2000+
+			pAdjustWindowRectEx(&Rect, Style, bMenu, ExStyle);
+		}
+		NewWindowWidth = Rect.right - Rect.left;
+		NewWindowHeight = Rect.bottom - Rect.top;
+	}
+	else {
+		// WM_DPICHANGED\x82\xAA\x94\xAD\x90\xB6\x82\xB5\x82Ȃ\xA2\x8A‹\xAB\x82̂͂\xB8\x81A\x94O\x82̈׎\xC0\x91\x95
+		RECT WindowRect;
+		GetWindowRect(&WindowRect);
+		const int WindowWidth = WindowRect.right - WindowRect.left;
+		const int WindowHeight = WindowRect.bottom - WindowRect.top;
+		RECT ClientRect;
+		GetClientRect(&ClientRect);
+		const int ClientWidth =  ClientRect.right - ClientRect.left;
+		const int ClientHeight = ClientRect.bottom - ClientRect.top;
+		NewWindowWidth = WindowWidth - ClientWidth + ScreenWidth;
+		NewWindowHeight = WindowHeight - ClientHeight + ScreenHeight;
+	}
 
 	// \x90V\x82\xB5\x82\xA2\x83E\x83B\x83\x93\x83h\x83E\x97̈\xE6\x8C\xF3\x95\xE2
 	RECT NewWindowRect[5];


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