Revision: 9460 https://osdn.net/projects/ttssh2/scm/svn/commits/9460 Author: zmatsuo Date: 2021-10-08 00:12:10 +0900 (Fri, 08 Oct 2021) Log Message: ----------- Aboutbox の Tera Term アイコンを DPI 変更に追従するようにした - ハンドルリークを修正 Modified Paths: -------------- trunk/teraterm/ttpdlg/ttdlg.c -------------- next part -------------- Modified: trunk/teraterm/ttpdlg/ttdlg.c =================================================================== --- trunk/teraterm/ttpdlg/ttdlg.c 2021-09-26 13:55:03 UTC (rev 9459) +++ trunk/teraterm/ttpdlg/ttdlg.c 2021-10-07 15:12:10 UTC (rev 9460) @@ -36,10 +36,12 @@ #include <io.h> #include <direct.h> #include <commdlg.h> +#include <commctrl.h> #include <dlgs.h> #define _CRTDBG_MAP_ALLOC #include <stdlib.h> #include <crtdbg.h> + #include "tttypes.h" #include "ttlib.h" #include "dlglib.h" @@ -54,6 +56,7 @@ #include "helpid.h" #include "asprintf.h" #include "win32helper.h" +#include "compat_win.h" // Oniguruma: Regular expression library #define ONIG_EXTERN extern @@ -2504,6 +2507,56 @@ } #endif +/** + * \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 + * DestroyIcon()\x82\xB7\x82邱\x82\xC6 + */ +static HICON TTLoadIcon(HINSTANCE hinst, const wchar_t *name, 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); + } + else { + cx = GetSystemMetrics(SM_CXICON); + cy = GetSystemMetrics(SM_CYICON); + } +#if 0 // TODO +//#if defined(NTDDI_VISTA) && (NTDDI_VERSION >= NTDDI_VISTA) + // LoadIconWithScaleDown() \x82\xCD vista\x82\xA9\x82\xE7 + hr = LoadIconWithScaleDown(hInst, name, cx, cy, &hIcon); + // LoadIconMetric(); +#else + hr = E_NOTIMPL; +#endif + if(FAILED(hr)) { + int fuLoad = LR_DEFAULTCOLOR; + if (IsWindowsNT4()) { + fuLoad = LR_VGACOLOR; + } +#if 0 + // TODO 9x + hIcon = LoadImageW(hInst, name, IMAGE_ICON, cx, cy, fuLoad); +#else + { + if (HIWORD(name) == 0) { + hIcon = LoadImageA(hInst, (LPCSTR)name, IMAGE_ICON, cx, cy, fuLoad); + } else { + char *nameA = ToCharW(name); + hIcon = LoadImageA(hInst, nameA, IMAGE_ICON, cx, cy, fuLoad); + free(nameA); + } + } +#endif + } + return hIcon; +} + static INT_PTR CALLBACK AboutDlg(HWND Dialog, UINT Message, WPARAM wParam, LPARAM lParam) { static const DlgTextInfo TextInfos[] = { @@ -2517,6 +2570,7 @@ WORD w, h; POINT point; char uimsg[MAX_UIMSG]; + static HICON dlghicon = NULL; #if defined(EFFECT_ENABLED) || defined(TEXTURE_ENABLED) // for animation @@ -2524,7 +2578,6 @@ static int dlgw, dlgh; static HBITMAP dlgbmp = NULL, dlgprevbmp = NULL; static LPDWORD dlgpixel = NULL; - static HICON dlghicon = NULL; const int icon_x = 15, icon_y = 10, icon_w = 32, icon_h = 32; const int ID_EFFECT_TIMER = 1; RECT dlgrc = {0}; @@ -2544,14 +2597,14 @@ case WM_INITDIALOG: // \x83A\x83C\x83R\x83\x93\x82I\x82ɃZ\x83b\x83g { - int fuLoad = LR_DEFAULTCOLOR; HICON hicon; + UINT dpi; +#if defined(EFFECT_ENABLED) || defined(TEXTURE_ENABLED) + int fuLoad = LR_DEFAULTCOLOR; if (IsWindowsNT4()) { fuLoad = LR_VGACOLOR; } - -#if defined(EFFECT_ENABLED) || defined(TEXTURE_ENABLED) hicon = LoadImage(hInst, MAKEINTRESOURCE(IDI_TTERM), IMAGE_ICON, icon_w, icon_h, fuLoad); // Picture Control \x82ɕ`\x89悷\x82\xE9\x82ƁA\x82Ȃ\xBA\x82\xA9\x93\xA7\x89ߐF\x82\xAA\x93\xA7\x89߂ɂȂ炸\x81A\x8D\x95\x82ƂȂ\xC1\x82Ă\xB5\x82܂\xA4\x82\xBD\x82߁A @@ -2558,9 +2611,10 @@ // WM_PAINT \x82ŕ`\x89悷\x82\xE9\x81B dlghicon = hicon; #else - hicon = LoadImage(hInst, MAKEINTRESOURCE(IDI_TTERM), - IMAGE_ICON, 32, 32, fuLoad); + dpi = GetMonitorDpiFromWindow(Dialog); + hicon = TTLoadIcon(hInst, MAKEINTRESOURCEW(IDI_TTERM), dpi); SendDlgItemMessage(Dialog, IDC_TT_ICON, STM_SETICON, (WPARAM)hicon, 0); + dlghicon = hicon; #endif } @@ -2827,7 +2881,18 @@ } break; #endif + case WM_DPICHANGED: { + const UINT new_dpi = LOWORD(wParam); + DestroyIcon(dlghicon); + dlghicon = TTLoadIcon(hInst, MAKEINTRESOURCEW(IDI_TTERM), new_dpi); + SendDlgItemMessage(Dialog, IDC_TT_ICON, STM_SETICON, (WPARAM)dlghicon, 0); + break; + } + case WM_DESTROY: + DestroyIcon(dlghicon); + dlghicon = NULL; + break; } return FALSE; }