Revision: 8695 https://osdn.net/projects/ttssh2/scm/svn/commits/8695 Author: zmatsuo Date: 2020-04-12 00:54:55 +0900 (Sun, 12 Apr 2020) Log Message: ----------- Var2Clipb を Unicode 対応にした Modified Paths: -------------- trunk/teraterm/ttpmacro/ttl_gui.cpp -------------- next part -------------- Modified: trunk/teraterm/ttpmacro/ttl_gui.cpp =================================================================== --- trunk/teraterm/ttpmacro/ttl_gui.cpp 2020-04-11 15:54:46 UTC (rev 8694) +++ trunk/teraterm/ttpmacro/ttl_gui.cpp 2020-04-11 15:54:55 UTC (rev 8695) @@ -31,7 +31,9 @@ #include "teraterm.h" #include <stdlib.h> +#define _CRTDBG_MAP_ALLOC #include <stdio.h> +#include <crtdbg.h> #include <string.h> #include <mbstring.h> #include <time.h> @@ -50,6 +52,7 @@ #include "ttl_gui.h" #include "codeconv.h" #include "layer_for_unicode.h" +#include "ttlib.h" // add 'clipb2var' (2006.9.17 maya) WORD TTLClipb2Var() @@ -184,44 +187,16 @@ { WORD Err; TStrVal Str; - HGLOBAL hText; - LPSTR clipbText; - int wide_len; - HGLOBAL wide_hText; - LPWSTR wide_buf; Err = 0; GetStrVal(Str,&Err); if (Err!=0) return Err; - hText = GlobalAlloc(GHND, sizeof(Str)); - clipbText = (LPSTR)GlobalLock(hText); - strncpy_s(clipbText, sizeof(Str), Str, _TRUNCATE); - GlobalUnlock(hText); + BOOL r = CBSetTextW(NULL, wc::fromUtf8(Str), 0); + // 0 == \x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82\xF0\x8AJ\x82\xAF\x82Ȃ\xA9\x82\xC1\x82\xBD + // 1 == \x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82ւ̃R\x83s\x81[\x82ɐ\xAC\x8C\x{1C2D42}\xBD + SetResult(r ? 1 : 0); - wide_len = MultiByteToWideChar(CP_ACP, 0, clipbText, -1, NULL, 0); - wide_hText = GlobalAlloc(GMEM_MOVEABLE, sizeof(WCHAR) * wide_len); - if (wide_hText) { - wide_buf = (LPWSTR)GlobalLock(wide_hText); - MultiByteToWideChar(CP_ACP, 0, clipbText, -1, wide_buf, wide_len); - GlobalUnlock(wide_hText); - } - - if (OpenClipboard(NULL) == 0) { - SetResult(0); - } - else { - EmptyClipboard(); - SetClipboardData(CF_TEXT, hText); - - if (wide_buf) { - SetClipboardData(CF_UNICODETEXT, wide_hText); - } - - CloseClipboard(); - SetResult(1); - } - return Err; }