[ttssh2-commit] [9905] ttermpro.exe のアイコンをDPIに合わせて調整するようにした

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2022年 5月 3日 (火) 22:14:50 JST


Revision: 9905
          https://osdn.net/projects/ttssh2/scm/svn/commits/9905
Author:   zmatsuo
Date:     2022-05-03 22:14:49 +0900 (Tue, 03 May 2022)
Log Message:
-----------
ttermpro.exe のアイコンをDPIに合わせて調整するようにした

Modified Paths:
--------------
    branches/adjust_icon/teraterm/common/dlglib.h
    branches/adjust_icon/teraterm/common/dlglib_cpp.cpp
    branches/adjust_icon/teraterm/common/teraterm.ico
    branches/adjust_icon/teraterm/teraterm/vtwin.cpp

-------------- next part --------------
Modified: branches/adjust_icon/teraterm/common/dlglib.h
===================================================================
--- branches/adjust_icon/teraterm/common/dlglib.h	2022-05-03 13:03:50 UTC (rev 9904)
+++ branches/adjust_icon/teraterm/common/dlglib.h	2022-05-03 13:14:49 UTC (rev 9905)
@@ -96,6 +96,7 @@
 wchar_t *GetCommonDialogFilterW(const char *user_filter_mask, const char *UILanguageFile);
 void SetDlgItemIcon(HWND dlg, int nID, const wchar_t *name, int cx, int cy);
 void SetComboBoxHostHistory(HWND dlg, int dlg_item, int maxhostlist, const wchar_t *SetupFNW);
+HICON TTLoadIcon(HINSTANCE hinst, const wchar_t *name, int cx, int cy, UINT dpi);
 
 #ifdef __cplusplus
 }

Modified: branches/adjust_icon/teraterm/common/dlglib_cpp.cpp
===================================================================
--- branches/adjust_icon/teraterm/common/dlglib_cpp.cpp	2022-05-03 13:03:50 UTC (rev 9904)
+++ branches/adjust_icon/teraterm/common/dlglib_cpp.cpp	2022-05-03 13:14:49 UTC (rev 9905)
@@ -342,7 +342,7 @@
  *		cx == 0 && cy == 0 \x82̂Ƃ\xAB\x83f\x83t\x83H\x83\x8B\x83g\x82̃A\x83C\x83R\x83\x93\x83T\x83C\x83Y\x82œǂݍ\x9E\x82\xDE
  *		DestroyIcon()\x82\xB7\x82邱\x82\xC6
  */
-static HICON TTLoadIcon(HINSTANCE hinst, const wchar_t *name, int cx, int cy, UINT dpi)
+HICON TTLoadIcon(HINSTANCE hinst, const wchar_t *name, int cx, int cy, UINT dpi)
 {
 	if (cx == 0 && cy == 0) {
 		// 100%(96dpi?)\x82̂Ƃ\xAB\x81AGetSystemMetrics(SM_CXICON)=32

Modified: branches/adjust_icon/teraterm/common/teraterm.ico
===================================================================
(Binary files differ)

Modified: branches/adjust_icon/teraterm/teraterm/vtwin.cpp
===================================================================
--- branches/adjust_icon/teraterm/teraterm/vtwin.cpp	2022-05-03 13:03:50 UTC (rev 9904)
+++ branches/adjust_icon/teraterm/teraterm/vtwin.cpp	2022-05-03 13:14:49 UTC (rev 9905)
@@ -241,6 +241,23 @@
 	AutoDisconnectedPort = port;
 }
 
+static void SetIcon(HINSTANCE hInst_, HWND hWnd, const wchar_t *icon_name, int dpi)
+{
+	// \x91傫\x82\xA2\x83A\x83C\x83R\x83\x93(32x32,\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82̊g\x91嗦\x82\xAA100%(dpi=76)\x82̂Ƃ\xAB)
+	HICON icon = TTLoadIcon(hInst_, icon_name, 0, 0, dpi);
+	icon = (HICON)::SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)icon);
+	if (icon != NULL) {
+		DestroyIcon(icon);
+	}
+
+	// \x91傫\x82\xA2\x83A\x83C\x83R\x83\x93(16x16,\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82̊g\x91嗦\x82\xAA100%(dpi=76)\x82̂Ƃ\xAB)
+	icon = TTLoadIcon(hInst_, icon_name, 16, 16, dpi);
+	icon = (HICON)::SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)icon);
+	if (icon != NULL) {
+		DestroyIcon(icon);
+	}
+}
+
 /////////////////////////////////////////////////////////////////////////////
 // CVTWindow constructor
 
@@ -250,7 +267,6 @@
 	RECT rect;
 	DWORD Style;
 	int CmdShow;
-	int fuLoad = LR_DEFAULTCOLOR;
 	BOOL isFirstInstance;
 	m_hInst = hInstance;
 
@@ -418,21 +434,12 @@
 	// USB\x83f\x83o\x83C\x83X\x95ω\xBB\x92ʒm\x93o\x98^
 	RegDeviceNotify(HVTWin);
 
-	if (IsWindowsNT4()) {
-		fuLoad = LR_VGACOLOR;
+	{
+		const int dpi = GetMonitorDpiFromWindow(m_hWnd);
+		const int icon_id = (ts.VTIcon != IdIconDefault) ? ts.VTIcon : IDI_VT;
+		const wchar_t *icon_name = MAKEINTRESOURCEW(icon_id);
+		SetIcon(m_hInst, m_hWnd, icon_name, dpi);
 	}
-	::PostMessage(HVTWin,WM_SETICON,ICON_SMALL,
-	              (LPARAM)LoadImage(hInstance,
-	                                MAKEINTRESOURCE((ts.VTIcon!=IdIconDefault)?ts.VTIcon:IDI_VT),
-	                                IMAGE_ICON,16,16,fuLoad));
-	// Vista \x82\xCC Aero \x82ɂ\xA8\x82\xA2\x82\xC4 Alt+Tab \x90؂\xE8\x91ւ\xA6\x82ŕ\\x8E\xA6\x82\xB3\x82\xEA\x82\xE9\x83A\x83C\x83R\x83\x93\x82\xAA
-	// 16x16 \x83A\x83C\x83R\x83\x93\x82̊g\x91\xE5\x82ɂȂ\xC1\x82Ă\xB5\x82܂\xA4\x82̂ŁA\x91傫\x82\xA2\x83A\x83C\x83R\x83\x93\x82\xE0
-	// \x83Z\x83b\x83g\x82\xB7\x82\xE9 (2008.9.3 maya)
-	::PostMessage(HVTWin,WM_SETICON,ICON_BIG,
-	              (LPARAM)LoadImage(hInstance,
-	                                MAKEINTRESOURCE((ts.VTIcon!=IdIconDefault)?ts.VTIcon:IDI_VT),
-	                                IMAGE_ICON, 0, 0, fuLoad));
-
 	SetCustomNotifyIcon(
 		(HICON)LoadImage(
 			hInstance,
@@ -5041,6 +5048,12 @@
 
 	ChangeCaret();
 
+	{
+		const int icon_id = (ts.VTIcon != IdIconDefault) ? ts.VTIcon : IDI_VT;
+		const wchar_t *icon_name = MAKEINTRESOURCEW(icon_id);
+		SetIcon(m_hInst, m_hWnd, icon_name, NewDPI);
+	}
+
 	return TRUE;
 }
 


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