[Ttssh2-commit] [8604] AllocControlTextW(), AllocControlTextA() 追加

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2020年 3月 18日 (水) 00:37:37 JST


Revision: 8604
          https://osdn.net/projects/ttssh2/scm/svn/commits/8604
Author:   zmatsuo
Date:     2020-03-18 00:37:37 +0900 (Wed, 18 Mar 2020)
Log Message:
-----------
AllocControlTextW(), AllocControlTextA() 追加

Modified Paths:
--------------
    trunk/teraterm/common/dlglib.c
    trunk/teraterm/common/dlglib.h
    trunk/teraterm/common/dlglib_cpp.cpp
    trunk/ttssh2/ttxssh/auth.c

-------------- next part --------------
Modified: trunk/teraterm/common/dlglib.c
===================================================================
--- trunk/teraterm/common/dlglib.c	2020-03-17 15:37:26 UTC (rev 8603)
+++ trunk/teraterm/common/dlglib.c	2020-03-17 15:37:37 UTC (rev 8604)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 1994-1998 T. Teranishi
- * (C) 2008-2019 TeraTerm Project
+ * (C) 2008-2020 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -35,7 +35,6 @@
 #include <assert.h>
 #include <stdio.h>
 #include <commctrl.h>
-#include <tchar.h>
 #if !defined(_CRTDBG_MAP_ALLOC)
 #define _CRTDBG_MAP_ALLOC
 #endif
@@ -42,6 +41,8 @@
 #include <stdlib.h>
 #include <crtdbg.h>
 #include "ttlib.h"	// for get_lang_font()
+#include "layer_for_unicode.h"
+#include "codeconv.h"
 
 void EnableDlgItem(HWND HDlg, int FirstId, int LastId)
 {
@@ -434,3 +435,33 @@
 	ReleaseDC(NULL, hDC);
 	return info.found;
 }
+
+/**
+ *	hWnd\x82̕\xB6\x8E\x9A\x97\xF1\x82\xF0\x8E擾\x82\xB7\x82\xE9
+ *	\x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82邱\x82\xC6
+ */
+wchar_t *AllocControlTextW(HWND hWnd)
+{
+	int len = GetWindowTextLength(hWnd);
+	wchar_t *strW = malloc(sizeof(wchar_t) * (len + 1));
+	if (strW == NULL) {
+		return NULL;
+	}
+
+	_GetWindowTextW(hWnd, strW, len + 1);
+	strW[len] = 0;
+	return strW;
+}
+
+/**
+ *	hWnd\x82̕\xB6\x8E\x9A\x97\xF1\x82\xF0\x8E擾\x82\xB7\x82\xE9
+ *	\x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82邱\x82\xC6
+ *	AllocControlTextW() \x82\xCC char\x94\xC5
+ */
+char *AllocControlTextA(HWND hWnd)
+{
+	wchar_t *strW = AllocControlTextW(hWnd);
+	char *strA = ToCharW(strW);
+	free(strW);
+	return strA;
+}

Modified: trunk/teraterm/common/dlglib.h
===================================================================
--- trunk/teraterm/common/dlglib.h	2020-03-17 15:37:26 UTC (rev 8603)
+++ trunk/teraterm/common/dlglib.h	2020-03-17 15:37:37 UTC (rev 8604)
@@ -98,13 +98,9 @@
 BOOL IsExistFontA(const char *face, BYTE charset, BOOL strict);
 int GetFontPointFromPixel(HWND hWnd, int pixel);
 int GetFontPixelFromPoint(HWND hWnd, int point);
+wchar_t *AllocControlTextW(HWND hWnd);
+char *AllocControlTextA(HWND hWnd);
 
-#if defined(_UNICODE)
-#define TTSetDlgFont(p1,p2,p3)	TTSetDlgFontW(p1,p2,p3)
-#else
-#define TTSetDlgFont(p1,p2,p3)	TTSetDlgFontA(p1,p2,p3)
-#endif
-
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/teraterm/common/dlglib_cpp.cpp
===================================================================
--- trunk/teraterm/common/dlglib_cpp.cpp	2020-03-17 15:37:26 UTC (rev 8603)
+++ trunk/teraterm/common/dlglib_cpp.cpp	2020-03-17 15:37:37 UTC (rev 8604)
@@ -150,7 +150,7 @@
 	if (logfont.lfHeight < 0) {
 		logfont.lfHeight = GetFontPointFromPixel(NULL, -logfont.lfHeight);
 	}
-	TTSetDlgFont(logfont.lfFaceName, logfont.lfHeight, logfont.lfCharSet);
+	TTSetDlgFontA(logfont.lfFaceName, logfont.lfHeight, logfont.lfCharSet);
 }
 
 

Modified: trunk/ttssh2/ttxssh/auth.c
===================================================================
--- trunk/ttssh2/ttxssh/auth.c	2020-03-17 15:37:26 UTC (rev 8603)
+++ trunk/ttssh2/ttxssh/auth.c	2020-03-17 15:37:37 UTC (rev 8604)
@@ -431,15 +431,7 @@
 
 static char *alloc_control_text(HWND ctl)
 {
-	int len = GetWindowTextLength(ctl);
-	char *result = malloc(len + 1);
-
-	if (result != NULL) {
-		GetWindowText(ctl, result, len + 1);
-		result[len] = 0;
-	}
-
-	return result;
+	return AllocControlTextA(ctl);
 }
 
 static int get_key_file_name(HWND parent, char *buf, int bufsize, PTInstVar pvar)


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