Revision: 9927 https://osdn.net/projects/ttssh2/scm/svn/commits/9927 Author: nmaya Date: 2022-05-17 19:18:28 +0900 (Tue, 17 May 2022) Log Message: ----------- いちど作成されたカスタム通知アイコンがずっと使われる問題に対応した カスタム通知アイコンの ID をセットする関数 SetCustomNotifyIconID() を追加した カスタム通知アイコンが拡大率にあわせて読み直せるようになった ticket #44517, #43907 Ticket Links: ------------ https://osdn.net/projects/ttssh2/tracker/detail/44517 https://osdn.net/projects/ttssh2/tracker/detail/43907 Modified Paths: -------------- branches/adjust_icon/teraterm/common/compat_win.cpp branches/adjust_icon/teraterm/common/compat_win.h branches/adjust_icon/teraterm/common/dlglib.h branches/adjust_icon/teraterm/common/dlglib_cpp.cpp branches/adjust_icon/teraterm/common/ttcommon.h branches/adjust_icon/teraterm/teraterm/vtwin.cpp branches/adjust_icon/teraterm/ttpcmn/ttcmn_notify.cpp branches/adjust_icon/teraterm/ttpcmn/ttpcmn.def branches/adjust_icon/ttssh2/ttxssh/ttxssh.c -------------- next part -------------- Modified: branches/adjust_icon/teraterm/common/compat_win.cpp =================================================================== --- branches/adjust_icon/teraterm/common/compat_win.cpp 2022-05-16 23:53:19 UTC (rev 9926) +++ branches/adjust_icon/teraterm/common/compat_win.cpp 2022-05-17 10:18:28 UTC (rev 9927) @@ -283,6 +283,20 @@ return false; } +static bool IsWindows2000() +{ + OSVERSIONINFOA osvi; + osvi.dwOSVersionInfoSize = sizeof(osvi); + GetVersionExA(&osvi); + if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && + osvi.dwMajorVersion == 5 && + osvi.dwMinorVersion == 0) { + // 2000 + return true; + } + return false; +} + void WinCompatInit() { static BOOL done = FALSE; @@ -621,7 +635,7 @@ return S_OK; } -HRESULT _LoadIconWithScaleDown(HINSTANCE hinst, PCWSTR pszName, int cx, int cy, HICON *phico) +HRESULT _LoadIconWithScaleDown(HINSTANCE hinst, PCWSTR pszName, int cx, int cy, HICON *phico, BOOL notify) { if (pLoadIconWithScaleDown != NULL) { HRESULT hr = pLoadIconWithScaleDown(hinst, pszName, cx, cy, phico); @@ -632,10 +646,18 @@ HICON hIcon; int fuLoad = LR_DEFAULTCOLOR; - if (IsWindowsNT4()) { + if (notify) { + // Windows 2000 \x82̃^\x83X\x83N\x83g\x83\x8C\x83C\x83A\x83C\x83R\x83\x93\x82\xCD 4bit \x83A\x83C\x83R\x83\x93\x82̂ݑΉ\x9E + if (IsWindows2000()) { + fuLoad = LR_VGACOLOR; + } + } + else { // Windows NT 4.0 \x82\xCD 4bit \x83A\x83C\x83R\x83\x93\x82\xB5\x82\xA9\x83T\x83|\x81[\x83g\x82\xB5\x82Ă\xA2\x82Ȃ\xA2 // 16(4bit) color = VGA color - fuLoad = LR_VGACOLOR; + if (IsWindowsNT4()) { + fuLoad = LR_VGACOLOR; + } } hIcon = (HICON)LoadImageW(hinst, pszName, IMAGE_ICON, cx, cy, fuLoad); if (hIcon == NULL) { Modified: branches/adjust_icon/teraterm/common/compat_win.h =================================================================== --- branches/adjust_icon/teraterm/common/compat_win.h 2022-05-16 23:53:19 UTC (rev 9926) +++ branches/adjust_icon/teraterm/common/compat_win.h 2022-05-17 10:18:28 UTC (rev 9927) @@ -195,7 +195,7 @@ HRESULT _SHGetKnownFolderPath(REFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken, PWSTR* ppszPath); // comctl32.dll -HRESULT _LoadIconWithScaleDown(HINSTANCE hinst, PCWSTR pszName, int cx, int cy, HICON *phico); +HRESULT _LoadIconWithScaleDown(HINSTANCE hinst, PCWSTR pszName, int cx, int cy, HICON *phico, BOOL notify); void WinCompatInit(); Modified: branches/adjust_icon/teraterm/common/dlglib.h =================================================================== --- branches/adjust_icon/teraterm/common/dlglib.h 2022-05-16 23:53:19 UTC (rev 9926) +++ branches/adjust_icon/teraterm/common/dlglib.h 2022-05-17 10:18:28 UTC (rev 9927) @@ -96,7 +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); +HICON TTLoadIcon(HINSTANCE hinst, const wchar_t *name, int cx, int cy, UINT dpi, BOOL notify); #ifdef __cplusplus } Modified: branches/adjust_icon/teraterm/common/dlglib_cpp.cpp =================================================================== --- branches/adjust_icon/teraterm/common/dlglib_cpp.cpp 2022-05-16 23:53:19 UTC (rev 9926) +++ branches/adjust_icon/teraterm/common/dlglib_cpp.cpp 2022-05-17 10:18:28 UTC (rev 9927) @@ -337,12 +337,13 @@ * @param[in] cx \x83A\x83C\x83R\x83\x93\x83T\x83C\x83Y(96dpi\x8E\x9E) * @param[in] cy \x83A\x83C\x83R\x83\x93\x83T\x83C\x83Y * @param[in] dpi \x83A\x83C\x83R\x83\x93\x83T\x83C\x83Y(cx,cy)\x82\xCDdpi/96\x94{\x82̃T\x83C\x83Y\x82œǂݍ\x9E\x82܂\xEA\x82\xE9 + * @param[in] notify \x83J\x83X\x83^\x83\x80\x92ʒm\x83A\x83C\x83R\x83\x93\x82̏ꍇ\x82\xCD TRUE, \x83E\x83B\x83\x93\x83h\x83E\x83A\x83C\x83R\x83\x93\x82̏ꍇ\x82\xCD FALSE * @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 */ -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, BOOL notify) { if (cx == 0 && cy == 0) { // 100%(96dpi?)\x82̂Ƃ\xAB\x81AGetSystemMetrics(SM_CXICON)=32 @@ -360,7 +361,7 @@ cy = cy * dpi / 96; } HICON hIcon; - HRESULT hr = _LoadIconWithScaleDown(hinst, name, cx, cy, &hIcon); + HRESULT hr = _LoadIconWithScaleDown(hinst, name, cx, cy, &hIcon, notify); if(FAILED(hr)) { hIcon = NULL; } @@ -401,7 +402,7 @@ case WM_DPICHANGED: { const HINSTANCE hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE); const UINT new_dpi = LOWORD(wp); - HICON icon = TTLoadIcon(hinst, data->icon_name, data->cx, data->cy, new_dpi); + HICON icon = TTLoadIcon(hinst, data->icon_name, data->cx, data->cy, new_dpi, FALSE); if (icon != NULL) { DestroyIcon(data->icon); data->icon = icon; @@ -450,7 +451,7 @@ const HINSTANCE hinst = (HINSTANCE)GetWindowLongPtr(dlg, GWLP_HINSTANCE); const UINT dpi = GetMonitorDpiFromWindow(dlg); - data->icon = TTLoadIcon(hinst, name, cx, cy, dpi); + data->icon = TTLoadIcon(hinst, name, cx, cy, dpi, FALSE); const HWND hwnd = GetDlgItem(dlg, nID); SetIcon(hwnd, data->icon); Modified: branches/adjust_icon/teraterm/common/ttcommon.h =================================================================== --- branches/adjust_icon/teraterm/common/ttcommon.h 2022-05-16 23:53:19 UTC (rev 9926) +++ branches/adjust_icon/teraterm/common/ttcommon.h 2022-05-17 10:18:28 UTC (rev 9927) @@ -82,6 +82,7 @@ DllExport void PASCAL SetVerNotifyIcon(PComVar cv, unsigned int ver); DllExport void PASCAL SetCustomNotifyIcon(HICON icon); DllExport HICON PASCAL GetCustomNotifyIcon(void); +DllExport void PASCAL SetCustomNotifyIconID(HINSTANCE hInstance, WORD IconID, BOOL plugin); #define NotifyInfoMessage(cv, msg, title) NotifyMessage(cv, msg, title, 1) #define NotifyWarnMessage(cv, msg, title) NotifyMessage(cv, msg, title, 2) Modified: branches/adjust_icon/teraterm/teraterm/vtwin.cpp =================================================================== --- branches/adjust_icon/teraterm/teraterm/vtwin.cpp 2022-05-16 23:53:19 UTC (rev 9926) +++ branches/adjust_icon/teraterm/teraterm/vtwin.cpp 2022-05-17 10:18:28 UTC (rev 9927) @@ -244,7 +244,7 @@ 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=96)\x82̂Ƃ\xAB) - HICON icon = TTLoadIcon(hInst_, icon_name, 0, 0, dpi); + HICON icon = TTLoadIcon(hInst_, icon_name, 0, 0, dpi, FALSE); icon = (HICON)::SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)icon); if (icon != NULL) { DestroyIcon(icon); @@ -251,23 +251,11 @@ } // \x8F\xAC\x82\xB3\x82\xA2\x83A\x83C\x83R\x83\x93(16x16,\x83f\x83B\x83X\x83v\x83\x8C\x83C\x82̊g\x91嗦\x82\xAA100%(dpi=96)\x82̂Ƃ\xAB) - icon = TTLoadIcon(hInst_, icon_name, 16, 16, dpi); + icon = TTLoadIcon(hInst_, icon_name, 16, 16, dpi, FALSE); icon = (HICON)::SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)icon); if (icon != NULL) { DestroyIcon(icon); } - - // \x92ʒm\x97̈\xE6\x82̃A\x83C\x83R\x83\x93 - // Windows 2000 \x82̃^\x83X\x83N\x83g\x83\x8C\x83C\x83A\x83C\x83R\x83\x93\x82\xCD 4bit \x82̂ݑΉ\x9E - // Windows 2000 \x88ȊO\x82\xCD VT \x83E\x83B\x83\x93\x83h\x83E\x82\xA9\x82\xE7\x8E擾\x82\xB3\x82\xEA\x82\xE9\x82̂łȂɂ\xE0\x82\xB5\x82Ȃ\xA2 - if (IsWindows2000()) { - icon = GetCustomNotifyIcon(); - if (icon != NULL) { - DestroyIcon(icon); - } - icon = TTLoadIcon(hInst_, icon_name, 16, 16, dpi); - SetCustomNotifyIcon(icon); - } } static void SetVTIcon(TTTSet *ts, HINSTANCE hInstance, WORD IconID) @@ -467,11 +455,22 @@ HINSTANCE inst; WORD icon_id; const int dpi = GetMonitorDpiFromWindow(m_hWnd); + + // VT \x83E\x83B\x83\x93\x83h\x83E\x82̃A\x83C\x83R\x83\x93 inst = (ts.PluginVTIconInstance != NULL) ? ts.PluginVTIconInstance : m_hInst; icon_id = (ts.PluginVTIconID != 0) ? ts.PluginVTIconID : (ts.VTIcon != IdIconDefault) ? ts.VTIcon : IDI_VT; SetIcon(inst, m_hWnd, MAKEINTRESOURCEW(icon_id), dpi); + + // \x92ʒm\x97̈\xE6\x82̃A\x83C\x83R\x83\x93 + // Windows 2000 \x82̃^\x83X\x83N\x83g\x83\x8C\x83C\x83A\x83C\x83R\x83\x93\x82\xCD 4bit \x82̂ݑΉ\x9E\x82Ȃ̂ŁAID \x82\xF0\x95ۑ\xB6\x82\xB5\x82Ă\xA8\x82\xA2\x82ĕ\\x8E\xA6\x82̂Ƃ\xAB\x82ɓǂݍ\x9E\x82\xF1\x82ł\xE0\x82炤 + // Windows 2000 \x88ȊO\x82\xCD VT \x83E\x83B\x83\x93\x83h\x83E\x82\xA9\x82\xE7\x8E擾\x82\xB3\x82\xEA\x82\xE9\x82̂łȂɂ\xE0\x82\xB5\x82Ȃ\xA2 + if (IsWindows2000()) { + icon_id = (ts.VTIcon != IdIconDefault) ? ts.VTIcon : IDI_VT; + icon_id = IDI_VT_CLASSIC; + SetCustomNotifyIconID(inst, icon_id, FALSE); + } } MainMenu = NULL; Modified: branches/adjust_icon/teraterm/ttpcmn/ttcmn_notify.cpp =================================================================== --- branches/adjust_icon/teraterm/ttpcmn/ttcmn_notify.cpp 2022-05-16 23:53:19 UTC (rev 9926) +++ branches/adjust_icon/teraterm/ttpcmn/ttcmn_notify.cpp 2022-05-17 10:18:28 UTC (rev 9927) @@ -48,11 +48,12 @@ #include "ttcommon.h" #include "codeconv.h" #include "compat_win.h" +#include "dlglib.h" typedef struct { TT_NOTIFYICONDATAW_V2 notify_icon; int NotifyIconShowCount; - HICON CustomIcon; + HICON CustomIcon; // \x96\xA2\x8Eg\x97p } NotifyIcon; /** @@ -90,6 +91,15 @@ return ni; } +static void NotifyUpdateIcon(NotifyIcon *ni, HICON icon) +{ + TT_NOTIFYICONDATAW_V2 *NotifyIcon = &ni->notify_icon; + NotifyIcon->uFlags = NIF_ICON; + NotifyIcon->uID = 1; + NotifyIcon->hIcon = icon; + Shell_NotifyIconW(NIM_MODIFY, NotifyIcon); +} + static void NotifyDelete(NotifyIcon *ni) { TT_NOTIFYICONDATAW_V2 *NotifyIcon = &ni->notify_icon; @@ -160,11 +170,6 @@ ni->NotifyIconShowCount += 1; } -/* - * EXPORT API - */ -static HICON CustomIcon = NULL; - static NotifyIcon *GetNotifyData(PComVar cv) { NotifyIcon *p = (NotifyIcon *)cv->NotifyIcon; @@ -171,29 +176,91 @@ return p; } +/* + * EXPORT API + */ + +// SetCustomNotifyIcon(), GetCustomNotifyIcon() \x82ő\x80\x8D\xEC\x82ł\xAB\x82邪\x81A\x93\xE0\x95\x94\x82\xA9\x82\xE7\x82͎g\x97p\x82\xB3\x82\xEA\x82Ȃ\xA2 +static HICON CustomIcon = NULL; + +// \x93\xAE\x8D삷\x82邪 CustomIcon \x82͎g\x97p\x82\xB3\x82\xEA\x82Ȃ\xA2 void WINAPI SetCustomNotifyIcon(HICON icon) { CustomIcon = icon; } +// \x93\xAE\x8D삷\x82邪 CustomIcon \x82͎g\x97p\x82\xB3\x82\xEA\x82Ȃ\xA2 HICON WINAPI GetCustomNotifyIcon() { return CustomIcon; } +static HINSTANCE TTCustomIconInstance = NULL; +static WORD TTCustomIconID = 0; +static HINSTANCE CustomIconInstance = NULL; +static WORD CustomIconID = 0; + +void WINAPI SetCustomNotifyIconID(HINSTANCE hInstance, WORD IconID, BOOL plugin) +{ + if (!plugin) { + CustomIconInstance = hInstance; + CustomIconID = IconID; + + // \x82\xA0\x82ƂŊO\x95\x94\x82\xA9\x82\xE7\x83J\x83X\x83^\x83\x80\x92ʒm\x83A\x83C\x83R\x83\x93\x82\xF0\x8F\xC1\x8B\x8E\x82\xB3\x82\xEA\x82\xE9\x82Ƃ\xAB\x82̂\xBD\x82߂\xC9 + // Tera Term \x96{\x91̂\xA9\x82\xE7\x90ݒ肳\x82ꂽ\x83J\x83X\x83^\x83\x80\x92ʒm\x83A\x83C\x83R\x83\x93\x82\xF0\x95ێ\x9D\x82\xB5\x82Ă\xA8\x82\xAD + TTCustomIconInstance = hInstance; + TTCustomIconID = IconID; + } + else { + if (hInstance == NULL) { + CustomIconInstance = TTCustomIconInstance; + } + else { + CustomIconInstance = hInstance; + } + if (IconID == 0) { + CustomIconID = TTCustomIconID; + } + else { + CustomIconID = IconID; + } + } +} + void WINAPI CreateNotifyIcon(PComVar cv) { NotifyIcon *ni = GetNotifyData(cv); - if (ni != NULL) { + HICON icon = NULL; + + // \x83E\x83B\x83\x93\x83h\x83E\x83n\x83\x93\x83h\x83\x8B\x82\xAA\x95K\x97v\x82ɂȂ\xE9\x82̂ŁA\x90ڑ\xB1\x92\x86\x82łȂ\xA2\x82ƃA\x83C\x83R\x83\x93\x82͍쐬\x82ł\xAB\x82Ȃ\xA2 + if (cv->HWin == NULL) { return; } - HICON icon = CustomIcon; - if (icon == NULL) { + + if (CustomIconInstance != NULL && CustomIconID != 0) { + const int dpi = GetMonitorDpiFromWindow(cv->HWin); + icon = TTLoadIcon(CustomIconInstance, MAKEINTRESOURCEW(CustomIconID), 16 ,16, dpi, TRUE); + } + else { icon = (HICON)SendMessage(cv->HWin, WM_GETICON, ICON_SMALL, 0); } - ni = NotifyCreate(cv->HWin, icon, WM_USER_NOTIFYICON); + if (ni == NULL) { + ni = NotifyCreate(cv->HWin, icon, WM_USER_NOTIFYICON); + } + else { + NotifyUpdateIcon(ni, icon); + } cv->NotifyIcon = ni; + + // \x92ʒm\x83A\x83C\x83R\x83\x93\x82͓n\x82\xB5\x82\xBD\x82\xE7\x83R\x83s\x81[\x82\xB3\x82\xEA\x82\xE9\x82̂ŕێ\x9D\x82\xB5\x82Ȃ\xAD\x82Ă悢 + // \x82\xB7\x82\xAE\x82ɔj\x8A\xFC\x82\xB7\x82\xE9 + // https://docs.microsoft.com/ja-jp/windows/win32/shell/taskbar + // https://stackoverflow.com/questions/23897103/how-to-properly-update-tray-notification-icon + if (CustomIconInstance != NULL && CustomIconID != 0 && + icon != NULL) { + DestroyIcon(icon); + } } void WINAPI DeleteNotifyIcon(PComVar cv) @@ -207,10 +274,12 @@ void WINAPI ShowNotifyIcon(PComVar cv) { - NotifyIcon* ni = GetNotifyData(cv); + NotifyIcon* ni; + + CreateNotifyIcon(cv); + ni = GetNotifyData(cv); if (ni == NULL) { - CreateNotifyIcon(cv); - ni = GetNotifyData(cv); + return; } NotifyShowIcon(ni); @@ -219,22 +288,29 @@ void WINAPI HideNotifyIcon(PComVar cv) { NotifyIcon *ni = GetNotifyData(cv); + if (ni == NULL) { + return; + } NotifyHide(ni); } -// \x8Eg\x82\xED\x82\xEA\x82Ă\xA2\x82Ȃ\xA2 void WINAPI SetVerNotifyIcon(PComVar cv, unsigned int ver) { NotifyIcon *ni = GetNotifyData(cv); + if (ni == NULL) { + return; + } NotifySetVersion(ni, ver); } void WINAPI NotifyMessageW(PComVar cv, const wchar_t *msg, const wchar_t *title, DWORD flag) { - NotifyIcon *ni = GetNotifyData(cv); + NotifyIcon *ni; + + CreateNotifyIcon(cv); + ni = GetNotifyData(cv); if (ni == NULL) { - CreateNotifyIcon(cv); - ni = GetNotifyData(cv); + return; } NotifySetMessageW(ni, msg, title, flag); Modified: branches/adjust_icon/teraterm/ttpcmn/ttpcmn.def =================================================================== --- branches/adjust_icon/teraterm/ttpcmn/ttpcmn.def 2022-05-16 23:53:19 UTC (rev 9926) +++ branches/adjust_icon/teraterm/ttpcmn/ttpcmn.def 2022-05-17 10:18:28 UTC (rev 9927) @@ -34,6 +34,7 @@ NotifyMessage @79 SetCustomNotifyIcon @85 GetCustomNotifyIcon @86 + SetCustomNotifyIconID @94 SJIS2JIS @30 SJIS2EUC @31 Modified: branches/adjust_icon/ttssh2/ttxssh/ttxssh.c =================================================================== --- branches/adjust_icon/ttssh2/ttxssh/ttxssh.c 2022-05-16 23:53:19 UTC (rev 9926) +++ branches/adjust_icon/ttssh2/ttxssh/ttxssh.c 2022-05-17 10:18:28 UTC (rev 9927) @@ -183,6 +183,9 @@ FWDUI_end(pvar); pvar->ts->SetVTIcon(pvar->ts, NULL, 0); + if (IsWindows2000()) { + SetCustomNotifyIconID(NULL, 0, TRUE); + } ssh_heartbeat_lock_finalize(); @@ -661,6 +664,13 @@ { pvar->ts->SetVTIcon(pvar->ts, hInst, pvar->settings.IconID); + // \x92ʒm\x97̈\xE6\x82̃A\x83C\x83R\x83\x93 + // Windows 2000 \x82̃^\x83X\x83N\x83g\x83\x8C\x83C\x83A\x83C\x83R\x83\x93\x82\xCD 4bit \x82̂ݑΉ\x9E\x82Ȃ̂ŁAID \x82\xF0\x95ۑ\xB6\x82\xB5\x82Ă\xA8\x82\xA2\x82ĕ\\x8E\xA6\x82̂Ƃ\xAB\x82ɓǂݍ\x9E\x82\xF1\x82ł\xE0\x82炤 + // Windows 2000 \x88ȊO\x82\xCD VT \x83E\x83B\x83\x93\x83h\x83E\x82\xA9\x82\xE7\x8E擾\x82\xB3\x82\xEA\x82\xE9\x82̂łȂɂ\xE0\x82\xB5\x82Ȃ\xA2 + if (IsWindows2000()) { + SetCustomNotifyIconID(hInst, pvar->settings.IconID, TRUE); + } + logputs(LOG_LEVEL_VERBOSE, "Entering secure mode"); }