[ttssh2-commit] [9474] SetDlgItemIcon() を dlglib_cpp.cpp へ移動

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2021年 10月 17日 (日) 01:11:41 JST


Revision: 9474
          https://osdn.net/projects/ttssh2/scm/svn/commits/9474
Author:   zmatsuo
Date:     2021-10-17 01:11:41 +0900 (Sun, 17 Oct 2021)
Log Message:
-----------
SetDlgItemIcon() を dlglib_cpp.cpp へ移動

Modified Paths:
--------------
    trunk/teraterm/common/dlglib.h
    trunk/teraterm/common/dlglib_cpp.cpp
    trunk/teraterm/ttpdlg/ttdlg.c

-------------- next part --------------
Modified: trunk/teraterm/common/dlglib.h
===================================================================
--- trunk/teraterm/common/dlglib.h	2021-10-16 16:11:30 UTC (rev 9473)
+++ trunk/teraterm/common/dlglib.h	2021-10-16 16:11:41 UTC (rev 9474)
@@ -94,6 +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);
 
 #ifdef __cplusplus
 }

Modified: trunk/teraterm/common/dlglib_cpp.cpp
===================================================================
--- trunk/teraterm/common/dlglib_cpp.cpp	2021-10-16 16:11:30 UTC (rev 9473)
+++ trunk/teraterm/common/dlglib_cpp.cpp	2021-10-16 16:11:41 UTC (rev 9474)
@@ -40,6 +40,7 @@
 #include "ttlib.h"
 #include "codeconv.h"
 #include "asprintf.h"
+#include "compat_win.h"
 
 /**
  *	EndDialog() \x8C݊\xB7\x8A֐\x94
@@ -326,3 +327,100 @@
 	free(UILanguageFileW);
 	return ret;
 }
+
+/**
+ *	\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 // 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;
+		}
+		hIcon = (HICON)LoadImageW(hinst, name, IMAGE_ICON, cx, cy, fuLoad);
+	}
+	return hIcon;
+}
+
+typedef struct {
+	wchar_t *icon_name;
+	HICON icon;
+	WNDPROC prev_proc;
+} IconSubclassData;
+
+static LRESULT IconProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
+{
+	IconSubclassData *data = (IconSubclassData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+	switch (msg) {
+	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);
+		if (icon != NULL) {
+			DestroyIcon(data->icon);
+			data->icon = icon;
+			SendMessage(hwnd, STM_SETICON, (WPARAM)icon, 0);
+		}
+		break;
+	}
+	case WM_NCDESTROY: {
+		LRESULT result = CallWindowProc(data->prev_proc, hwnd, msg, wp, lp);
+		DestroyIcon(data->icon);
+		if (HIWORD(data->icon_name) != 0) {
+			free(data->icon_name);
+		}
+		free(data);
+		return result;
+	}
+	default:
+		break;
+	}
+	return CallWindowProc(data->prev_proc, hwnd, msg, wp, lp);
+}
+
+/**
+ *	\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);
+ */
+void SetDlgItemIcon(HWND dlg, int nID, const wchar_t *name)
+{
+	IconSubclassData *data = (IconSubclassData *)malloc(sizeof(IconSubclassData));
+	data->icon_name = (HIWORD(name) == 0) ? (wchar_t *)name : _wcsdup(name);
+
+	const HINSTANCE hinst = (HINSTANCE)GetWindowLongPtr(dlg, GWLP_HINSTANCE);
+	const UINT dpi = GetMonitorDpiFromWindow(dlg);
+	data->icon = TTLoadIcon(hinst, name, dpi);
+
+	const HWND hWnd = GetDlgItem(dlg, nID);
+	SendMessage(hWnd, STM_SETICON, (WPARAM)data->icon, 0);
+
+	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:11:30 UTC (rev 9473)
+++ trunk/teraterm/ttpdlg/ttdlg.c	2021-10-16 16:11:41 UTC (rev 9474)
@@ -2505,104 +2505,6 @@
 	strncpy_s(buf, buf_size, "unknown compiler");
 }
 #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 // 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;
-		}
-		hIcon = LoadImageW(hInst, name, IMAGE_ICON, cx, cy, fuLoad);
-	}
-	return hIcon;
-}
-
-typedef struct {
-	wchar_t *icon_name;
-	HICON icon;
-	WNDPROC prev_proc;
-} IconSubclassData;
-
-static LRESULT IconProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
-{
-	IconSubclassData *data = (IconSubclassData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
-	switch (msg) {
-	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);
-		if (icon != NULL) {
-			DestroyIcon(data->icon);
-			data->icon = icon;
-			SendMessage(hwnd, STM_SETICON, (WPARAM)icon, 0);
-		}
-		break;
-	}
-	case WM_NCDESTROY: {
-		LRESULT result = CallWindowProc(data->prev_proc, hwnd, msg, wp, lp);
-		DestroyIcon(data->icon);
-		if (HIWORD(data->icon_name) != 0) {
-			free(data->icon_name);
-		}
-		free(data);
-		return result;
-	}
-	default:
-		break;
-	}
-	return CallWindowProc(data->prev_proc, hwnd, msg, wp, lp);
-}
-
-/**
- *	\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);
- */
-void SetDlgItemIcon(HWND dlg, int nID, const wchar_t *name)
-{
-	IconSubclassData *data = (IconSubclassData *)malloc(sizeof(IconSubclassData));
-	data->icon_name = (HIWORD(name) == 0) ? (wchar_t *)name : _wcsdup(name);
-
-	const HINSTANCE hinst = (HINSTANCE)GetWindowLongPtr(dlg, GWLP_HINSTANCE);
-	const UINT dpi = GetMonitorDpiFromWindow(dlg);
-	data->icon = TTLoadIcon(hinst, name, dpi);
-
-	const HWND hWnd = GetDlgItem(dlg, nID);
-	SendMessage(hWnd, STM_SETICON, (WPARAM)data->icon, 0);
-
-	data->prev_proc = (WNDPROC)SetWindowLongPtrW(hWnd, GWLP_WNDPROC, (LONG_PTR)IconProc);
-	SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)data);
-}
-
 static INT_PTR CALLBACK AboutDlg(HWND Dialog, UINT Message, WPARAM wParam, LPARAM lParam)
 {
 	static const DlgTextInfo TextInfos[] = {


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