Revision: 9478 https://osdn.net/projects/ttssh2/scm/svn/commits/9478 Author: zmatsuo Date: 2021-10-17 23:42:27 +0900 (Sun, 17 Oct 2021) Log Message: ----------- 三角アイコンがDPI変更に追従していなかったので修正 - 初期化時のディスプレイのDPIに合わせたサイズで表示していた - ディスプレイのDPIが変化したとき追従してサイズを変更していなかった - DPIの異なるディスプレイへダイアログを移動、ディスプレイの設定の変更など Modified Paths: -------------- trunk/teraterm/common/dlglib.h trunk/teraterm/common/dlglib_cpp.cpp trunk/teraterm/ttpdlg/ttdlg.c trunk/ttssh2/ttxssh/auth.c trunk/ttssh2/ttxssh/ttxssh.c -------------- next part -------------- Modified: trunk/teraterm/common/dlglib.h =================================================================== --- trunk/teraterm/common/dlglib.h 2021-10-16 16:17:22 UTC (rev 9477) +++ trunk/teraterm/common/dlglib.h 2021-10-17 14:42:27 UTC (rev 9478) @@ -94,7 +94,7 @@ void ExpandCBWidth(HWND dlg, int ID); wchar_t *GetCommonDialogFilterWW(const char *user_filter_mask, const wchar_t *UILanguageFile); wchar_t *GetCommonDialogFilterW(const char *user_filter_mask, const char *UILanguageFile); -void SetDlgItemIcon(HWND dlg, int nID, const wchar_t *name); +void SetDlgItemIcon(HWND dlg, int nID, const wchar_t *name, int cx, int cy); #ifdef __cplusplus } Modified: trunk/teraterm/common/dlglib_cpp.cpp =================================================================== --- trunk/teraterm/common/dlglib_cpp.cpp 2021-10-16 16:17:22 UTC (rev 9477) +++ trunk/teraterm/common/dlglib_cpp.cpp 2021-10-17 14:42:27 UTC (rev 9478) @@ -35,6 +35,7 @@ #include <stdlib.h> #include <crtdbg.h> #include <wchar.h> +#include <assert.h> #include "dlglib.h" #include "ttlib.h" @@ -329,23 +330,35 @@ } /** - * \x83f\x83t\x83H\x83\x8B\x83g\x83T\x83C\x83Y\x82ŃA\x83C\x83R\x83\x93\x82\xF0\x83\x8D\x81[\x83h\x82\xB7\x82\xE9 + * \x83A\x83C\x83R\x83\x93\x82\xF0\x83\x8D\x81[\x83h\x82\xB7\x82\xE9 + * @param[in] hinst + * @param[in] name + * @param[in] cx \x83A\x83C\x83R\x83\x93\x83T\x83C\x83Y + * @param[in] cy \x83A\x83C\x83R\x83\x93\x83T\x83C\x83Y + * @param[in] dpi cx,cy \x82\xCD 96dpi\x82\xA9\x82\xE7\x82̔䗦 + * @return HICON + * + * 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, UINT dpi) +static HICON TTLoadIcon(HINSTANCE hinst, const wchar_t *name, int cx, int cy, UINT dpi) { HICON hIcon; HRESULT hr; - int cx; - int cy; - // - 100%(96dpi?)\x82̂Ƃ\xAB\x81AGetSystemMetrics(SM_CXICON)=32 - if (pGetSystemMetricsForDpi != NULL) { - cx = pGetSystemMetricsForDpi(SM_CXICON, dpi); - cy = pGetSystemMetricsForDpi(SM_CYICON, dpi); + if (cx == 0 && cy == 0) { + // 100%(96dpi?)\x82̂Ƃ\xAB\x81AGetSystemMetrics(SM_CXICON)=32 + if (pGetSystemMetricsForDpi != NULL) { + cx = pGetSystemMetricsForDpi(SM_CXICON, dpi); + cy = pGetSystemMetricsForDpi(SM_CYICON, dpi); + } + else { + cx = GetSystemMetrics(SM_CXICON); + cy = GetSystemMetrics(SM_CYICON); + } } else { - cx = GetSystemMetrics(SM_CXICON); - cy = GetSystemMetrics(SM_CYICON); + cx = cx * dpi / 96; + cy = cy * dpi / 96; } #if 0 // defined(NTDDI_VISTA) && (NTDDI_VERSION >= NTDDI_VISTA) // LoadIconWithScaleDown() \x82\xCD vista\x82\xA9\x82\xE7 @@ -368,8 +381,25 @@ wchar_t *icon_name; HICON icon; WNDPROC prev_proc; + int cx; + int cy; } IconSubclassData; +static void SetIcon(HWND hwnd, HICON icon) +{ + char class_name[32]; + int r = GetClassNameA(hwnd, class_name, _countof(class_name)); + if (strcmp(class_name, "Button") == 0) { + SendMessage(hwnd, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)icon); + } + else if (strcmp(class_name, "Static") == 0) { + SendMessage(hwnd, STM_SETICON, (WPARAM)icon, 0); + } + else { + assert(("not support", FALSE)); + } +} + static LRESULT IconProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { IconSubclassData *data = (IconSubclassData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); @@ -377,11 +407,11 @@ case WM_DPICHANGED: { const HINSTANCE hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE); const UINT new_dpi = LOWORD(wp); - HICON icon = TTLoadIcon(hinst, data->icon_name, new_dpi); + HICON icon = TTLoadIcon(hinst, data->icon_name, data->cx, data->cy, new_dpi); if (icon != NULL) { DestroyIcon(data->icon); data->icon = icon; - SendMessage(hwnd, STM_SETICON, (WPARAM)icon, 0); + SetIcon(hwnd, icon); } break; } @@ -403,24 +433,34 @@ /** * \x83_\x83C\x83A\x83\x8D\x83O\x82̃R\x83\x93\x83g\x83\x8D\x81[\x83\x8B\x82ɃA\x83C\x83R\x83\x93\x82\xF0\x83Z\x83b\x83g\x82\xB7\x82\xE9 * - * \x97\xE1 - * SetDlgItemIcon(Dialog, IDC_TT_ICON, MAKEINTRESOURCEW(IDI_TTERM)); - * DPI\x82\xAA\x95ω\xBB\x82\xB5\x82\xBD\x82Ƃ\xAB\x82ɃA\x83C\x83R\x83\x93\x82̃T\x83C\x83Y\x82\xF0\x95ύX\x82\xB7\x82\xE9 - * case WM_DPICHANGED: - * SendDlgItemMessage(Dialog, IDC_TT_ICON, Message, wParam, lParam); + * @param dlg \x83_\x83C\x83A\x83\x8D\x83O + * @param nID \x83R\x83\x93\x83g\x83\x8D\x81[\x83\x8BID + * @param name \x83A\x83C\x83R\x83\x93 + * @param cx \x83A\x83C\x83R\x83\x93\x83T\x83C\x83Y + * @param cy \x83A\x83C\x83R\x83\x93\x83T\x83C\x83Y + * + * 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 + * + * \x83Z\x83b\x83g\x82\xB7\x82\xE9\x97\xE1 + * SetDlgItemIcon(Dialog, IDC_TT_ICON, MAKEINTRESOURCEW(IDI_TTERM), 0, 0); + * DPI\x82\xAA\x95ω\xBB\x82\xB5\x82\xBD\x82Ƃ\xAB\x82ɃA\x83C\x83R\x83\x93\x82̃T\x83C\x83Y\x82\xF0\x95ύX\x82\xB7\x82\xE9\x97\xE1 + * case WM_DPICHANGED: + * SendDlgItemMessage(Dialog, IDC_TT_ICON, WM_DPICHANGED, wParam, lParam); */ -void SetDlgItemIcon(HWND dlg, int nID, const wchar_t *name) +void SetDlgItemIcon(HWND dlg, int nID, const wchar_t *name, int cx, int cy) { IconSubclassData *data = (IconSubclassData *)malloc(sizeof(IconSubclassData)); data->icon_name = (HIWORD(name) == 0) ? (wchar_t *)name : _wcsdup(name); + data->cx = cx; + data->cy = cy; const HINSTANCE hinst = (HINSTANCE)GetWindowLongPtr(dlg, GWLP_HINSTANCE); const UINT dpi = GetMonitorDpiFromWindow(dlg); - data->icon = TTLoadIcon(hinst, name, dpi); + data->icon = TTLoadIcon(hinst, name, cx, cy, dpi); - const HWND hWnd = GetDlgItem(dlg, nID); - SendMessage(hWnd, STM_SETICON, (WPARAM)data->icon, 0); + const HWND hwnd = GetDlgItem(dlg, nID); + SetIcon(hwnd, data->icon); - data->prev_proc = (WNDPROC)SetWindowLongPtrW(hWnd, GWLP_WNDPROC, (LONG_PTR)IconProc); - SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)data); + data->prev_proc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)IconProc); + SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR)data); } Modified: trunk/teraterm/ttpdlg/ttdlg.c =================================================================== --- trunk/teraterm/ttpdlg/ttdlg.c 2021-10-16 16:17:22 UTC (rev 9477) +++ trunk/teraterm/ttpdlg/ttdlg.c 2021-10-17 14:42:27 UTC (rev 9478) @@ -2558,7 +2558,7 @@ // WM_PAINT \x82ŕ`\x89悷\x82\xE9\x81B dlghicon = hicon; #else - SetDlgItemIcon(Dialog, IDC_TT_ICON, MAKEINTRESOURCEW(IDI_TTERM)); + SetDlgItemIcon(Dialog, IDC_TT_ICON, MAKEINTRESOURCEW(IDI_TTERM), 0, 0); #endif } Modified: trunk/ttssh2/ttxssh/auth.c =================================================================== --- trunk/ttssh2/ttxssh/auth.c 2021-10-16 16:17:22 UTC (rev 9477) +++ trunk/ttssh2/ttxssh/auth.c 2021-10-17 14:42:27 UTC (rev 9478) @@ -772,7 +772,6 @@ static BOOL autologin_sent_none; static BOOL UseControlChar; static BOOL ShowPassPhrase; - static HICON hIconDropdown; static size_t username_str_len; static wchar_t password_char; // \x95\x9A\x82\xB9\x8E\x9A\x83L\x83\x83\x83\x89\x83N\x83^ @@ -789,12 +788,8 @@ init_auth_dlg(pvar, dlg, &UseControlChar); // "\x81\xA5"\x89摜\x82\xF0\x83Z\x83b\x83g\x82\xB7\x82\xE9 - const UINT dpi = GetMonitorDpiFromWindow(dlg); - int size = 16 * dpi / 96; // 16 = original image size for 96dpi - hIconDropdown = LoadImageW(hInst, MAKEINTRESOURCEW(IDI_DROPDOWN), - IMAGE_ICON, size, size, LR_DEFAULTCOLOR); - SendDlgItemMessage(dlg, IDC_USERNAME_OPTION, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hIconDropdown); - SendDlgItemMessage(dlg, IDC_SSHPASSWORD_OPTION, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hIconDropdown); + SetDlgItemIcon(dlg, IDC_USERNAME_OPTION, MAKEINTRESOURCEW(IDI_DROPDOWN), 16, 16); + SetDlgItemIcon(dlg, IDC_SSHPASSWORD_OPTION, MAKEINTRESOURCEW(IDI_DROPDOWN), 16, 16); // SSH2 autologin\x82\xAA\x97L\x8C\xF8\x82̏ꍇ\x82́A\x83^\x83C\x83}\x82\xF0\x8Ed\x8A|\x82\xAF\x82\xE9\x81B (2004.12.1 yutaka) if (pvar->ssh2_autologin == 1) { @@ -1163,10 +1158,9 @@ } return FALSE; - case WM_DESTROY: - if (hIconDropdown != NULL) { - DeleteObject(hIconDropdown); - } + case WM_DPICHANGED: + SendDlgItemMessage(dlg, IDC_USERNAME_OPTION, WM_DPICHANGED, wParam, lParam); + SendDlgItemMessage(dlg, IDC_SSHPASSWORD_OPTION, WM_DPICHANGED, wParam, lParam); return FALSE; default: Modified: trunk/ttssh2/ttxssh/ttxssh.c =================================================================== --- trunk/ttssh2/ttxssh/ttxssh.c 2021-10-16 16:17:22 UTC (rev 9477) +++ trunk/ttssh2/ttxssh/ttxssh.c 2021-10-17 14:42:27 UTC (rev 9478) @@ -2156,7 +2156,7 @@ SendDlgItemMessage(dlg, IDC_ABOUTTEXT, WM_SETFONT, (WPARAM)DlgAboutTextFont, MAKELPARAM(TRUE,0)); } - SetDlgItemIcon(dlg, IDC_TTSSH_ICON, MAKEINTRESOURCEW(pvar->settings.IconID)); + SetDlgItemIcon(dlg, IDC_TTSSH_ICON, MAKEINTRESOURCEW(pvar->settings.IconID), 0, 0); init_about_dlg(pvar, dlg); CheckDlgButton(dlg, IDC_FP_HASH_ALG_SHA256, TRUE); @@ -2204,7 +2204,7 @@ if (DlgAboutTextFont != NULL) { SendDlgItemMessage(dlg, IDC_ABOUTTEXT, WM_SETFONT, (WPARAM)DlgAboutTextFont, MAKELPARAM(TRUE,0)); } - SendDlgItemMessage(dlg, IDC_TTSSH_ICON, msg, wParam, lParam); + SendDlgItemMessage(dlg, IDC_TTSSH_ICON, WM_DPICHANGED, wParam, lParam); return FALSE; }