Revision: 9362 https://osdn.net/projects/ttssh2/scm/svn/commits/9362 Author: zmatsuo Date: 2021-08-14 23:43:37 +0900 (Sat, 14 Aug 2021) Log Message: ----------- hGetWindowTextW() を追加 - AllocControlTextW(), AllocControlTextA() を削除 Modified Paths: -------------- trunk/teraterm/common/dlglib.c trunk/teraterm/common/dlglib.h trunk/teraterm/common/win32helper.cpp trunk/teraterm/common/win32helper.h trunk/teraterm/teraterm/sendfiledlg.cpp trunk/ttssh2/ttxssh/auth.c -------------- next part -------------- Modified: trunk/teraterm/common/dlglib.c =================================================================== --- trunk/teraterm/common/dlglib.c 2021-08-14 03:26:50 UTC (rev 9361) +++ trunk/teraterm/common/dlglib.c 2021-08-14 14:43:37 UTC (rev 9362) @@ -489,33 +489,3 @@ 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 2021-08-14 03:26:50 UTC (rev 9361) +++ trunk/teraterm/common/dlglib.h 2021-08-14 14:43:37 UTC (rev 9362) @@ -98,8 +98,6 @@ 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); void ExpandCBWidth(HWND dlg, int ID); wchar_t *GetCommonDialogFilterW(const char *user_filter_mask, const char *UILanguageFile); char *GetCommonDialogFilterA(const char *user_filter_mask, const char *UILanguageFile); Modified: trunk/teraterm/common/win32helper.cpp =================================================================== --- trunk/teraterm/common/win32helper.cpp 2021-08-14 03:26:50 UTC (rev 9361) +++ trunk/teraterm/common/win32helper.cpp 2021-08-14 14:43:37 UTC (rev 9362) @@ -184,3 +184,36 @@ *dir = d; return 0; } + +/** + * 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 + * + * @param[out] text \x90ݒ肳\x82\xEA\x82Ă\xA2\x82镶\x8E\x9A\x97\xF1 + * \x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7free()\x82\xB7\x82\xE9 + * @return \x83G\x83\x89\x81[\x83R\x81[\x83h,0(=NO_ERROR)\x82̂Ƃ\xAB\x83G\x83\x89\x81[\x82Ȃ\xB5 + */ +DWORD hGetWindowTextW(HWND hWnd, wchar_t **text) +{ + int len = GetWindowTextLength(hWnd); + if (len == 0) { + DWORD err = GetLastError(); + if (err != 0) { + *text = NULL; + return err; + } + *text = _wcsdup(L""); + return 0; + } + + wchar_t *strW = (wchar_t *)malloc(sizeof(wchar_t) * (len + 1)); + if (strW == NULL) { + *text = NULL; + return ERROR_NOT_ENOUGH_MEMORY; + } + + GetWindowTextW(hWnd, strW, len + 1); + strW[len] = 0; + *text = strW; + return 0; +} Modified: trunk/teraterm/common/win32helper.h =================================================================== --- trunk/teraterm/common/win32helper.h 2021-08-14 03:26:50 UTC (rev 9361) +++ trunk/teraterm/common/win32helper.h 2021-08-14 14:43:37 UTC (rev 9362) @@ -38,6 +38,7 @@ DWORD hGetPrivateProfileStringW(const wchar_t *section, const wchar_t *key, const wchar_t *def, const wchar_t *ini, wchar_t **str); DWORD hGetFullPathNameW(const wchar_t *lpFileName, wchar_t **fullpath, wchar_t **filepart); DWORD hGetCurrentDirectoryW(wchar_t **dir); +DWORD hGetWindowTextW(HWND hWnd, wchar_t **text); #ifdef __cplusplus } Modified: trunk/teraterm/teraterm/sendfiledlg.cpp =================================================================== --- trunk/teraterm/teraterm/sendfiledlg.cpp 2021-08-14 03:26:50 UTC (rev 9361) +++ trunk/teraterm/teraterm/sendfiledlg.cpp 2021-08-14 14:43:37 UTC (rev 9362) @@ -42,6 +42,7 @@ #include "helpid.h" #include "codeconv.h" #include "asprintf.h" +#include "win32helper.h" #include "sendfiledlg.h" @@ -176,9 +177,9 @@ case WM_COMMAND: switch (wp) { case IDOK | (BN_CLICKED << 16): { - wchar_t *strW = AllocControlTextW(GetDlgItem(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT)); - - const DWORD attr = GetFileAttributesW(strW); + wchar_t *filename; + hGetWindowTextW(GetDlgItem(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT), &filename); + const DWORD attr = GetFileAttributesW(filename); if (attr == INVALID_FILE_ATTRIBUTES || attr & FILE_ATTRIBUTE_DIRECTORY) { static const TTMessageBoxInfoW mbinfo = { "Tera Term", @@ -187,7 +188,7 @@ MB_TASKMODAL | MB_ICONEXCLAMATION }; TTMessageBoxW(hDlgWnd, &mbinfo, data->UILanguageFileW); - free(strW); + free(filename); PostMessage(hDlgWnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlgWnd, IDC_SENDFILE_FILENAME_EDIT), TRUE); @@ -195,7 +196,7 @@ return TRUE; } - data->filename = strW; + data->filename = filename; data->binary = SendMessage(GetDlgItem(hDlgWnd, IDC_SENDFILE_CHECK_BINARY), BM_GETCHECK, 0, 0) == BST_CHECKED ? TRUE Modified: trunk/ttssh2/ttxssh/auth.c =================================================================== --- trunk/ttssh2/ttxssh/auth.c 2021-08-14 03:26:50 UTC (rev 9361) +++ trunk/ttssh2/ttxssh/auth.c 2021-08-14 14:43:37 UTC (rev 9362) @@ -53,6 +53,7 @@ #include "helpid.h" #include "codeconv.h" #include "asprintf.h" +#include "win32helper.h" #define AUTH_START_USER_AUTH_ON_ERROR_END 1 @@ -447,7 +448,12 @@ static char *alloc_control_text(HWND ctl) { - return AllocControlTextA(ctl); + wchar_t *textW; + char *textA; + hGetWindowTextW(ctl, &textW); + textA = ToCharW(textW); + free(textW); + return textA; } static int get_key_file_name(HWND parent, char *buf, int bufsize, PTInstVar pvar)