• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision9460 (tree)
Time2021-10-08 00:12:10
Authorzmatsuo

Log Message

Aboutbox の Tera Term アイコンを DPI 変更に追従するようにした

- ハンドルリークを修正

Change Summary

Incremental Difference

--- trunk/teraterm/ttpdlg/ttdlg.c (revision 9459)
+++ trunk/teraterm/ttpdlg/ttdlg.c (revision 9460)
@@ -36,10 +36,12 @@
3636 #include <io.h>
3737 #include <direct.h>
3838 #include <commdlg.h>
39+#include <commctrl.h>
3940 #include <dlgs.h>
4041 #define _CRTDBG_MAP_ALLOC
4142 #include <stdlib.h>
4243 #include <crtdbg.h>
44+
4345 #include "tttypes.h"
4446 #include "ttlib.h"
4547 #include "dlglib.h"
@@ -54,6 +56,7 @@
5456 #include "helpid.h"
5557 #include "asprintf.h"
5658 #include "win32helper.h"
59+#include "compat_win.h"
5760
5861 // Oniguruma: Regular expression library
5962 #define ONIG_EXTERN extern
@@ -2504,6 +2507,56 @@
25042507 }
25052508 #endif
25062509
2510+/**
2511+ * デフォルトサイズでアイコンをロードする
2512+ * DestroyIcon()すること
2513+ */
2514+static HICON TTLoadIcon(HINSTANCE hinst, const wchar_t *name, UINT dpi)
2515+{
2516+ HICON hIcon;
2517+ HRESULT hr;
2518+ int cx;
2519+ int cy;
2520+ // - 100%(96dpi?)のとき、GetSystemMetrics(SM_CXICON)=32
2521+ if (pGetSystemMetricsForDpi != NULL) {
2522+ cx = pGetSystemMetricsForDpi(SM_CXICON, dpi);
2523+ cy = pGetSystemMetricsForDpi(SM_CYICON, dpi);
2524+ }
2525+ else {
2526+ cx = GetSystemMetrics(SM_CXICON);
2527+ cy = GetSystemMetrics(SM_CYICON);
2528+ }
2529+#if 0 // TODO
2530+//#if defined(NTDDI_VISTA) && (NTDDI_VERSION >= NTDDI_VISTA)
2531+ // LoadIconWithScaleDown() は vistaから
2532+ hr = LoadIconWithScaleDown(hInst, name, cx, cy, &hIcon);
2533+ // LoadIconMetric();
2534+#else
2535+ hr = E_NOTIMPL;
2536+#endif
2537+ if(FAILED(hr)) {
2538+ int fuLoad = LR_DEFAULTCOLOR;
2539+ if (IsWindowsNT4()) {
2540+ fuLoad = LR_VGACOLOR;
2541+ }
2542+#if 0
2543+ // TODO 9x
2544+ hIcon = LoadImageW(hInst, name, IMAGE_ICON, cx, cy, fuLoad);
2545+#else
2546+ {
2547+ if (HIWORD(name) == 0) {
2548+ hIcon = LoadImageA(hInst, (LPCSTR)name, IMAGE_ICON, cx, cy, fuLoad);
2549+ } else {
2550+ char *nameA = ToCharW(name);
2551+ hIcon = LoadImageA(hInst, nameA, IMAGE_ICON, cx, cy, fuLoad);
2552+ free(nameA);
2553+ }
2554+ }
2555+#endif
2556+ }
2557+ return hIcon;
2558+}
2559+
25072560 static INT_PTR CALLBACK AboutDlg(HWND Dialog, UINT Message, WPARAM wParam, LPARAM lParam)
25082561 {
25092562 static const DlgTextInfo TextInfos[] = {
@@ -2517,6 +2570,7 @@
25172570 WORD w, h;
25182571 POINT point;
25192572 char uimsg[MAX_UIMSG];
2573+ static HICON dlghicon = NULL;
25202574
25212575 #if defined(EFFECT_ENABLED) || defined(TEXTURE_ENABLED)
25222576 // for animation
@@ -2524,7 +2578,6 @@
25242578 static int dlgw, dlgh;
25252579 static HBITMAP dlgbmp = NULL, dlgprevbmp = NULL;
25262580 static LPDWORD dlgpixel = NULL;
2527- static HICON dlghicon = NULL;
25282581 const int icon_x = 15, icon_y = 10, icon_w = 32, icon_h = 32;
25292582 const int ID_EFFECT_TIMER = 1;
25302583 RECT dlgrc = {0};
@@ -2544,14 +2597,14 @@
25442597 case WM_INITDIALOG:
25452598 // アイコンを動的にセット
25462599 {
2547- int fuLoad = LR_DEFAULTCOLOR;
25482600 HICON hicon;
2601+ UINT dpi;
25492602
2603+#if defined(EFFECT_ENABLED) || defined(TEXTURE_ENABLED)
2604+ int fuLoad = LR_DEFAULTCOLOR;
25502605 if (IsWindowsNT4()) {
25512606 fuLoad = LR_VGACOLOR;
25522607 }
2553-
2554-#if defined(EFFECT_ENABLED) || defined(TEXTURE_ENABLED)
25552608 hicon = LoadImage(hInst, MAKEINTRESOURCE(IDI_TTERM),
25562609 IMAGE_ICON, icon_w, icon_h, fuLoad);
25572610 // Picture Control に描画すると、なぜか透過色が透過にならず、黒となってしまうため、
@@ -2558,9 +2611,10 @@
25582611 // WM_PAINT で描画する。
25592612 dlghicon = hicon;
25602613 #else
2561- hicon = LoadImage(hInst, MAKEINTRESOURCE(IDI_TTERM),
2562- IMAGE_ICON, 32, 32, fuLoad);
2614+ dpi = GetMonitorDpiFromWindow(Dialog);
2615+ hicon = TTLoadIcon(hInst, MAKEINTRESOURCEW(IDI_TTERM), dpi);
25632616 SendDlgItemMessage(Dialog, IDC_TT_ICON, STM_SETICON, (WPARAM)hicon, 0);
2617+ dlghicon = hicon;
25642618 #endif
25652619 }
25662620
@@ -2827,7 +2881,18 @@
28272881 }
28282882 break;
28292883 #endif
2884+ case WM_DPICHANGED: {
2885+ const UINT new_dpi = LOWORD(wParam);
2886+ DestroyIcon(dlghicon);
2887+ dlghicon = TTLoadIcon(hInst, MAKEINTRESOURCEW(IDI_TTERM), new_dpi);
2888+ SendDlgItemMessage(Dialog, IDC_TT_ICON, STM_SETICON, (WPARAM)dlghicon, 0);
2889+ break;
2890+ }
28302891
2892+ case WM_DESTROY:
2893+ DestroyIcon(dlghicon);
2894+ dlghicon = NULL;
2895+ break;
28312896 }
28322897 return FALSE;
28332898 }
Show on old repository browser