[Ttssh2-commit] [7333] ttpmacro GUI表示周りをunicode化

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2018年 12月 18日 (火) 23:46:38 JST


Revision: 7333
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/7333
Author:   zmatsuo
Date:     2018-12-18 23:46:36 +0900 (Tue, 18 Dec 2018)
Log Message:
-----------
ttpmacro GUI表示周りをunicode化

Modified Paths:
--------------
    branches/cmake/teraterm/common/tmfc.cpp
    branches/cmake/teraterm/common/tmfc.h
    branches/cmake/teraterm/ttpmacro/CMakeLists.txt
    branches/cmake/teraterm/ttpmacro/ListDlg.cpp
    branches/cmake/teraterm/ttpmacro/ListDlg.h
    branches/cmake/teraterm/ttpmacro/errdlg.cpp
    branches/cmake/teraterm/ttpmacro/errdlg.h
    branches/cmake/teraterm/ttpmacro/inpdlg.cpp
    branches/cmake/teraterm/ttpmacro/inpdlg.h
    branches/cmake/teraterm/ttpmacro/msgdlg.cpp
    branches/cmake/teraterm/ttpmacro/msgdlg.h
    branches/cmake/teraterm/ttpmacro/statdlg.cpp
    branches/cmake/teraterm/ttpmacro/statdlg.h
    branches/cmake/teraterm/ttpmacro/ttl.c
    branches/cmake/teraterm/ttpmacro/ttmacro.h
    branches/cmake/teraterm/ttpmacro/ttmbuff.c
    branches/cmake/teraterm/ttpmacro/ttmdde.c
    branches/cmake/teraterm/ttpmacro/ttmdlg.cpp
    branches/cmake/teraterm/ttpmacro/ttmdlg.h
    branches/cmake/teraterm/ttpmacro/ttmlib.c
    branches/cmake/teraterm/ttpmacro/ttmlib.h
    branches/cmake/teraterm/ttpmacro/ttmmain.cpp
    branches/cmake/teraterm/ttpmacro/ttmparse.c
    branches/cmake/teraterm/ttpmacro/wait4all.c

Added Paths:
-----------
    branches/cmake/teraterm/ttpmacro/ttl_gui.cpp
    branches/cmake/teraterm/ttpmacro/ttl_gui.h

-------------- next part --------------
Modified: branches/cmake/teraterm/common/tmfc.cpp
===================================================================
--- branches/cmake/teraterm/common/tmfc.cpp	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/common/tmfc.cpp	2018-12-18 14:46:36 UTC (rev 7333)
@@ -178,6 +178,13 @@
 	::SetWindowText(m_hWnd, str);
 }
 
+#if defined(UNICODE)
+void TTCWnd::SetWindowTextW(const wchar_t *str)
+{
+	::SetWindowTextW(m_hWnd, str);
+}
+#endif
+
 void TTCWnd::SetWindowTextA(const char *str)
 {
 	::SetWindowTextA(m_hWnd, str);

Modified: branches/cmake/teraterm/common/tmfc.h
===================================================================
--- branches/cmake/teraterm/common/tmfc.h	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/common/tmfc.h	2018-12-18 14:46:36 UTC (rev 7333)
@@ -49,6 +49,9 @@
 	LRESULT SendMessage(UINT msg, WPARAM wp, LPARAM lp);
 	void ShowWindow(int nCmdShow);
 	void SetWindowTextT(const TCHAR *str);
+#if defined(UNICODE)
+	void SetWindowTextW(const wchar_t *str);
+#endif
 	void SetWindowTextA(const char *str);
 	LONG_PTR SetWindowLongPtr(int nIndex, LONG_PTR dwNewLong);
 	LONG_PTR GetWindowLongPtr(int nIndex);

Modified: branches/cmake/teraterm/ttpmacro/CMakeLists.txt
===================================================================
--- branches/cmake/teraterm/ttpmacro/CMakeLists.txt	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/CMakeLists.txt	2018-12-18 14:46:36 UTC (rev 7333)
@@ -14,6 +14,10 @@
     string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
 endif ()
 
+if(USE_UNICODE_API)
+  add_definitions(-DUNICODE -D_UNICODE)
+endif()
+
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/")
 
 set(COMMON_SRC
@@ -33,6 +37,8 @@
   ../common/compat_win.cpp
   ../common/win16api.h
   ../common/win16api.c
+  ../common/codeconv.h
+  ../common/codeconv.cpp
   )
 
 source_group(
@@ -56,6 +62,7 @@
   statdlg.h
   ttl.c
   ttl.h
+  ttl_gui.cpp
   ttm_res.h
   ttmacro.cpp
   ttmacro.h
@@ -80,6 +87,8 @@
   wait4all.h
   ttpmacro.rc
   ttm-version.rc
+  fileread.h
+  fileread.cpp
   ${COMMON_SRC}
   )
 
@@ -94,8 +103,6 @@
   ${SFMT_LIBRARY_DIRS}
   )
 
-set(CMAKE_MFC_FLAG 1)
-
 if (MSVC)
   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DELAYLOAD:iphlpapi.dll /DELAYLOAD:user32.dll")
 endif()

Modified: branches/cmake/teraterm/ttpmacro/ListDlg.cpp
===================================================================
--- branches/cmake/teraterm/ttpmacro/ListDlg.cpp	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/ListDlg.cpp	2018-12-18 14:46:36 UTC (rev 7333)
@@ -29,6 +29,7 @@
 // ListDlg.cpp : \x8E\xC0\x91\x95\x83t\x83@\x83C\x83\x8B
 //
 
+#include <tchar.h>
 #include "tmfc.h"
 #include "teraterm.h"
 #include "ttlib.h"
@@ -37,15 +38,13 @@
 #include "tttypes.h"
 #include "dlglib.h"
 #include "ttmdlg.h"
+#include "ttmacro.h"
 
 #include "ListDlg.h"
 
-extern HINSTANCE GetInstance();
-extern HWND GetHWND();
-
 // CListDlg \x83_\x83C\x83A\x83\x8D\x83O
 
-CListDlg::CListDlg(PCHAR Text, PCHAR Caption, CHAR **Lists, int Selected, int x, int y)
+CListDlg::CListDlg(const TCHAR *Text, const TCHAR *Caption, const TCHAR **Lists, int Selected, int x, int y)
 {
 	m_Text = Text;
 	m_Caption = Caption;
@@ -68,7 +67,7 @@
 		{ IDOK, "BTN_YES" },
 		{ IDCANCEL, "BTN_CANCEL" },
 	};
-	char **p;
+	const TCHAR **p;
 	int ListMaxWidth = 0;
 	int ListWidth;
 	int ListCount = 0;
@@ -86,7 +85,7 @@
 	while (*p) {
 		SIZE size;
 		SendDlgItemMessage(IDC_LISTBOX, LB_ADDSTRING, 0, (LPARAM)(*p));
-		GetTextExtentPoint32(DC, *p, strlen(*p), &size);
+		GetTextExtentPoint32(DC, *p, _tcslen(*p), &size);
 		ListWidth = size.cx;
 		if (ListWidth > ListMaxWidth) {
 			ListMaxWidth = ListWidth;

Modified: branches/cmake/teraterm/ttpmacro/ListDlg.h
===================================================================
--- branches/cmake/teraterm/ttpmacro/ListDlg.h	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/ListDlg.h	2018-12-18 14:46:36 UTC (rev 7333)
@@ -31,15 +31,15 @@
 class CListDlg : public TTCDialog
 {
 public:
-	CListDlg(PCHAR Text, PCHAR Caption, CHAR **Lists, int Selected, int x, int y);
+	CListDlg(const TCHAR *Text, const TCHAR *Caption, const TCHAR **Lists, int Selected, int x, int y);
 	INT_PTR DoModal();
 	int m_SelectItem;
 
 private:
 	enum { IDD = IDD_LISTDLG };
-	PCHAR m_Text;
-	PCHAR m_Caption;
-	CHAR **m_Lists;
+	const TCHAR *m_Text;
+	const TCHAR *m_Caption;
+	const TCHAR **m_Lists;
 	int m_Selected;
 	int PosX, PosY, init_WW, WW, WH, TW, TH, BH, BW, LW, LH;
 	SIZE s;

Modified: branches/cmake/teraterm/ttpmacro/errdlg.cpp
===================================================================
--- branches/cmake/teraterm/ttpmacro/errdlg.cpp	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/errdlg.cpp	2018-12-18 14:46:36 UTC (rev 7333)
@@ -31,6 +31,7 @@
 
 #include <windowsx.h>
 #include <stdio.h>
+#include <tchar.h>
 #include "tmfc.h"
 #include "teraterm.h"
 #include "ttlib.h"
@@ -45,13 +46,11 @@
 #include "ttmparse.h"
 #include "htmlhelp.h"
 #include "dlglib.h"
+#include "ttmacro.h"
 
-extern HINSTANCE GetInstance();
-extern HWND GetHWND();
-
 // CErrDlg dialog
 
-CErrDlg::CErrDlg(PCHAR Msg, PCHAR Line, int x, int y, int lineno, int start, int end, PCHAR FileName)
+CErrDlg::CErrDlg(const TCHAR *Msg, const TCHAR *Line, int x, int y, int lineno, int start, int end, const TCHAR *FileName)
 {
 	MsgStr = Msg;
 	LineStr = Line;
@@ -79,7 +78,7 @@
 	};
 	RECT R;
 	HDC TmpDC;
-	char buf[MaxLineLen*2], buf2[10];
+	TCHAR buf[MaxLineLen*2], buf2[10];
 	int i, len;
 
 	SetDlgTexts(m_hWnd, TextInfos, _countof(TextInfos), UILanguageFile);
@@ -89,22 +88,22 @@
 	// \x8Ds\x94ԍ\x86\x82\xF0\x90擪\x82ɂ‚\xAF\x82\xE9\x81B
 	// \x83t\x83@\x83C\x83\x8B\x96\xBC\x82\xE0\x82‚\xAF\x82\xE9\x81B
 	// \x83G\x83\x89\x81[\x89ӏ\x8A\x82Ɉ\xF3\x82\xF0\x82‚\xAF\x82\xE9\x81B
-	_snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s:%d:", MacroFileName, LineNo);
+	_sntprintf_s(buf, _countof(buf), _TRUNCATE, _T("%s:%d:"), MacroFileName, LineNo);
 	SetDlgItemText(IDC_ERRLINE, buf);
 
-	len = strlen(LineStr);
+	len = _tcslen(LineStr);
 	buf[0] = 0;
 	for (i = 0 ; i < len ; i++) {
 		if (i == StartPos)
-			strncat_s(buf, sizeof(buf), "<<<", _TRUNCATE);
+			_tcsncat_s(buf, _countof(buf), _T("<<<"), _TRUNCATE);
 		if (i == EndPos)
-			strncat_s(buf, sizeof(buf), ">>>", _TRUNCATE);
+			_tcsncat_s(buf, _countof(buf), _T(">>>"), _TRUNCATE);
 		buf2[0] = LineStr[i];
 		buf2[1] = 0;
-		strncat_s(buf, sizeof(buf), buf2, _TRUNCATE);
+		_tcsncat_s(buf, _countof(buf), buf2, _TRUNCATE);
 	}
 	if (EndPos == len)
-		strncat_s(buf, sizeof(buf), ">>>", _TRUNCATE);
+		_tcsncat_s(buf, _countof(buf), _T(">>>"), _TRUNCATE);
 	SetDlgItemText(IDC_EDIT_ERRLINE, buf);
 
 	if (PosX<=GetMonitorLeftmost(PosX, PosY)-100) {

Modified: branches/cmake/teraterm/ttpmacro/errdlg.h
===================================================================
--- branches/cmake/teraterm/ttpmacro/errdlg.h	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/errdlg.h	2018-12-18 14:46:36 UTC (rev 7333)
@@ -35,17 +35,18 @@
 class CErrDlg : public TTCDialog
 {
 public:
-	CErrDlg(PCHAR Msg, PCHAR Line, int x, int y, int lineno, int start, int end, PCHAR FileName);
+	CErrDlg(const TCHAR *Msg, const TCHAR *Line, int x, int y, int lineno, int start, int end, const TCHAR *FileName);
 	INT_PTR DoModal();
 
 private:
 	enum { IDD = IDD_ERRDLG };
 
-	PCHAR MsgStr, LineStr;
+	const TCHAR *MsgStr;
+	const TCHAR *LineStr;
 	int PosX, PosY;
 	int LineNo;
 	int StartPos, EndPos;
-	PCHAR MacroFileName;
+	const TCHAR *MacroFileName;
 
 	virtual BOOL OnInitDialog();
 	BOOL OnCommand(WPARAM wp, LPARAM lp);

Modified: branches/cmake/teraterm/ttpmacro/inpdlg.cpp
===================================================================
--- branches/cmake/teraterm/ttpmacro/inpdlg.cpp	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/inpdlg.cpp	2018-12-18 14:46:36 UTC (rev 7333)
@@ -35,15 +35,13 @@
 #include "ttm_res.h"
 #include "ttmlib.h"
 #include "dlglib.h"
+#include "ttmacro.h"
 
 #include "inpdlg.h"
 
-extern HINSTANCE GetInstance();
-extern HWND GetHWND();
-
 // CInpDlg dialog
-CInpDlg::CInpDlg(PCHAR Input, PCHAR Text, PCHAR Title,
-                 PCHAR Default, BOOL Paswd,
+CInpDlg::CInpDlg(TCHAR *Input, const TCHAR *Text, const TCHAR *Title,
+                 const TCHAR *Default, BOOL Paswd,
                  int x, int y)
 {
 	InputStr = Input;

Modified: branches/cmake/teraterm/ttpmacro/inpdlg.h
===================================================================
--- branches/cmake/teraterm/ttpmacro/inpdlg.h	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/inpdlg.h	2018-12-18 14:46:36 UTC (rev 7333)
@@ -34,8 +34,8 @@
 class CInpDlg : public TTCDialog
 {
 public:
-	CInpDlg(PCHAR Input, PCHAR Text, PCHAR Title,
-	        PCHAR Default, BOOL Paswd,
+	CInpDlg(TCHAR *Input, const TCHAR *Text, const TCHAR *Title,
+	        const TCHAR *Default, BOOL Paswd,
 	        int x, int y);
 	INT_PTR DoModal();
 
@@ -42,7 +42,10 @@
 private:
 	enum { IDD = IDD_INPDLG };
 
-	PCHAR InputStr, TextStr, TitleStr, DefaultStr;
+	TCHAR *InputStr;
+	const TCHAR *TextStr;
+	const TCHAR *TitleStr;
+	const TCHAR *DefaultStr;
 	BOOL PaswdFlag;
 	int PosX, PosY, init_WW, WW, WH, TW, TH, BH, BW, EW, EH;
 	SIZE s;

Modified: branches/cmake/teraterm/ttpmacro/msgdlg.cpp
===================================================================
--- branches/cmake/teraterm/ttpmacro/msgdlg.cpp	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/msgdlg.cpp	2018-12-18 14:46:36 UTC (rev 7333)
@@ -38,15 +38,13 @@
 #include "tmfc.h"
 #include "dlglib.h"
 #include "ttmdlg.h"
+#include "ttmacro.h"
 
 #include "msgdlg.h"
 
-extern HINSTANCE GetInstance();
-extern HWND GetHWND();
-
 // CMsgDlg dialog
 
-CMsgDlg::CMsgDlg(PCHAR Text, PCHAR Title, BOOL YesNo,
+CMsgDlg::CMsgDlg(const TCHAR *Text, const TCHAR *Title, BOOL YesNo,
                  int x, int y)
 {
 	TextStr = Text;

Modified: branches/cmake/teraterm/ttpmacro/msgdlg.h
===================================================================
--- branches/cmake/teraterm/ttpmacro/msgdlg.h	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/msgdlg.h	2018-12-18 14:46:36 UTC (rev 7333)
@@ -34,13 +34,14 @@
 class CMsgDlg : public TTCDialog
 {
 public:
-	CMsgDlg(PCHAR Text, PCHAR Title, BOOL YesNo, int x, int y);
+	CMsgDlg(const TCHAR *Text, const TCHAR *Title, BOOL YesNo, int x, int y);
 	INT_PTR DoModal();
 
 private:
 	enum { IDD = IDD_MSGDLG };
 
-	PCHAR TextStr, TitleStr;
+	const TCHAR *TextStr;
+	const TCHAR *TitleStr;
 	BOOL YesNoFlag;
 	int  PosX, PosY, init_WW, WW, WH, TW, TH, BH, BW;
 	SIZE s;

Modified: branches/cmake/teraterm/ttpmacro/statdlg.cpp
===================================================================
--- branches/cmake/teraterm/ttpmacro/statdlg.cpp	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/statdlg.cpp	2018-12-18 14:46:36 UTC (rev 7333)
@@ -51,7 +51,7 @@
 
 extern HINSTANCE GetInstance();
 
-BOOL CStatDlg::Create(PCHAR Text, PCHAR Title, int x, int y)
+BOOL CStatDlg::Create(const TCHAR *Text, const TCHAR *Title, int x, int y)
 {
 	TextStr = Text;
 	TitleStr = Title;
@@ -62,7 +62,7 @@
 	return TTCDialog::Create(hInst, GetDesktopWindow(), CStatDlg::IDD);
 }
 
-void CStatDlg::Update(PCHAR Text, PCHAR Title, int x, int y)
+void CStatDlg::Update(const TCHAR *Text, const TCHAR *Title, int x, int y)
 {
 	RECT R;
 

Modified: branches/cmake/teraterm/ttpmacro/statdlg.h
===================================================================
--- branches/cmake/teraterm/ttpmacro/statdlg.h	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/statdlg.h	2018-12-18 14:46:36 UTC (rev 7333)
@@ -32,12 +32,13 @@
 class CStatDlg : public TTCDialog
 {
 public:
-	BOOL Create(PCHAR Text, PCHAR Title, int x, int y);
-	void Update(PCHAR Text, PCHAR Title, int x, int y);
+	BOOL Create(const TCHAR *Text, const TCHAR *Title, int x, int y);
+	void Update(const TCHAR *Text, const TCHAR *Title, int x, int y);
 	void Bringup();
 	enum { IDD = IDD_STATDLG };
 private:
-	PCHAR TextStr, TitleStr;
+	const TCHAR *TextStr;
+	const TCHAR *TitleStr;
 	int  PosX, PosY, init_WW, WW, WH, TW, TH;
 	SIZE s;
 //	HFONT DlgFont;

Modified: branches/cmake/teraterm/ttpmacro/ttl.c
===================================================================
--- branches/cmake/teraterm/ttpmacro/ttl.c	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/ttl.c	2018-12-18 14:46:36 UTC (rev 7333)
@@ -29,6 +29,9 @@
 
 /* TTMACRO.EXE, Tera Term Language interpreter */
 
+#undef UNICODE
+#undef _UNICODE
+
 #include "teraterm.h"
 #include <stdlib.h>
 #include <stdio.h>
@@ -68,6 +71,7 @@
 #include <iptypes.h>
 #include <iphlpapi.h>
 #include "win16api.h"
+#include "ttl_gui.h"
 
 #define TTERMCOMMAND "TTERMPRO /D="
 #define CYGTERMCOMMAND "cyglaunch -o /D="
@@ -448,6 +452,7 @@
 	return Err;
 }
 
+#if 0
 // add 'clipb2var' (2006.9.17 maya)
 WORD TTLClipb2Var()
 {
@@ -575,7 +580,9 @@
 
 	return Err;
 }
+#endif
 
+#if 0
 // add 'var2clipb' (2006.9.17 maya)
 WORD TTLVar2Clipb()
 {
@@ -621,6 +628,7 @@
 
 	return Err;
 }
+#endif
 
 WORD TTLCloseSBox()
 {
@@ -1511,6 +1519,7 @@
 	return Err;
 }
 
+#if 0
 // add 'filenamebox' (2007.9.13 maya)
 WORD TTLFilenameBox()
 {
@@ -1570,6 +1579,7 @@
 	}
 	return Err;
 }
+#endif
 
 WORD TTLFileOpen()
 {
@@ -2576,7 +2586,7 @@
 	return Err;
 }
 
-
+#if 0
 WORD TTLGetPassword()
 {
 	TStrVal Str, Str2, Temp2;
@@ -2620,6 +2630,7 @@
 	SetResult(result);  // 成功可否を設定する。
 	return Err;
 }
+#endif
 
 // setpassword 'password.dat' 'mypassword' passowrd
 WORD TTLSetPassword()
@@ -3039,6 +3050,7 @@
 	return Err;
 }
 
+#if 0
 WORD TTLInputBox(BOOL Paswd)
 {
 	TStrVal Str1, Str2, Str3;
@@ -3084,6 +3096,7 @@
 		OpenInpDlg(StrVarPtr(VarId),Str1,Str2,Str3,Paswd);
 	return Err;
 }
+#endif
 
 WORD TTLInt2Str()
 {
@@ -3394,6 +3407,7 @@
 	return Err;
 }
 
+#if 0
 WORD TTLDirnameBox()
 {
 	TStrVal Title;
@@ -3558,6 +3572,7 @@
 	MessageCommand(IdMsgBox, &Err);
 	return Err;
 }
+#endif
 
 WORD TTLNext()
 {

Added: branches/cmake/teraterm/ttpmacro/ttl_gui.cpp
===================================================================
--- branches/cmake/teraterm/ttpmacro/ttl_gui.cpp	                        (rev 0)
+++ branches/cmake/teraterm/ttpmacro/ttl_gui.cpp	2018-12-18 14:46:36 UTC (rev 7333)
@@ -0,0 +1,621 @@
+/*
+ * Copyright (C) 1994-1998 T. Teranishi
+ * (C) 2005-2018 TeraTerm Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* TTMACRO.EXE, Tera Term Language interpreter */
+
+#include "teraterm.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <mbstring.h>
+#include <time.h>
+#include <errno.h>
+#include "ttmdlg.h"
+#include "ttmbuff.h"
+#include "ttmparse.h"
+#include "ttmdde.h"
+#include "ttmlib.h"
+#include "ttlib.h"
+#include "ttmenc.h"
+#include "tttypes.h"
+#include "ttmonig.h"
+#include "ttmacro.h"
+#include "ttl.h"
+#include "ttl_gui.h"
+#include "codeconv.h"
+
+// add 'clipb2var' (2006.9.17 maya)
+WORD TTLClipb2Var()
+{
+	WORD Err;
+	TVarId VarId;
+	HGLOBAL hText;
+	LPSTR clipbText;
+	char buf[MaxStrLen];
+	int Num = 0;
+	char *newbuff;
+	static char *cbbuff;
+	static int cbbuffsize, cblen;
+	HANDLE wide_hText;
+	LPWSTR wide_buf;
+	int mb_len;
+	UINT Cf;
+
+	Err = 0;
+	GetStrVar(&VarId, &Err);
+	if (Err!=0) return Err;
+
+	// get 2nd arg(optional) if given
+	if (CheckParameterGiven()) {
+		GetIntVal(&Num, &Err);
+	}
+
+	if ((Err==0) && (GetFirstChar()!=0))
+		Err = ErrSyntax;
+	if (Err!=0) return Err;
+
+	if (Num == 0) {
+		if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
+			Cf = CF_UNICODETEXT;
+		}
+		else if (IsClipboardFormatAvailable(CF_TEXT)) {
+			Cf = CF_TEXT;
+		}
+		else {
+			cblen = 0;
+			SetResult(0);
+			return Err;
+		}
+		if (OpenClipboard(NULL) == 0) {
+			cblen = 0;
+			SetResult(0);
+			return Err;
+		}
+
+		if (Cf == CF_UNICODETEXT) {
+			wide_hText = GetClipboardData(CF_UNICODETEXT);
+			if (wide_hText != NULL) {
+				wide_buf = (LPWSTR)GlobalLock(wide_hText);
+				mb_len = WideCharToMultiByte(CP_ACP, 0, wide_buf, -1, NULL, 0, NULL, NULL);
+				hText = GlobalAlloc(GMEM_MOVEABLE, sizeof(CHAR) * mb_len);
+				clipbText = (LPSTR)GlobalLock(hText);
+				if (hText != NULL) {
+					WideCharToMultiByte(CP_ACP, 0, wide_buf, -1, clipbText, mb_len, NULL, NULL);
+
+					cblen = strlen(clipbText);
+					if (cbbuffsize <= cblen) {
+						if ((newbuff = (char *)realloc(cbbuff, cblen + 1)) == NULL) {
+							// realloc failed. fall back to old mode.
+							cblen = 0;
+							strncpy_s(buf,sizeof(buf),clipbText,_TRUNCATE);
+							GlobalUnlock(hText);
+							CloseClipboard();
+							SetStrVal(VarId, buf);
+							SetResult(3);
+							return Err;
+						}
+						cbbuff = newbuff;
+						cbbuffsize = cblen + 1;
+					}
+					strncpy_s(cbbuff, cbbuffsize, clipbText, _TRUNCATE);
+
+					GlobalUnlock(hText);
+					GlobalFree(hText);
+				}
+				GlobalUnlock(wide_hText);
+			}
+			else {
+				cblen = 0;
+			}
+		}
+		else if (Cf == CF_TEXT) {
+			hText = GetClipboardData(CF_TEXT);
+			if (hText != NULL) {
+				clipbText = (LPSTR)GlobalLock(hText);
+				cblen = strlen(clipbText);
+				if (cbbuffsize <= cblen) {
+					if ((newbuff = (char *)realloc(cbbuff, cblen + 1)) == NULL) {
+						// realloc failed. fall back to old mode.
+						cblen = 0;
+						strncpy_s(buf,sizeof(buf),clipbText,_TRUNCATE);
+						GlobalUnlock(hText);
+						CloseClipboard();
+						SetStrVal(VarId, buf);
+						SetResult(3);
+						return Err;
+					}
+					cbbuff = newbuff;
+					cbbuffsize = cblen + 1;
+				}
+				strncpy_s(cbbuff, cbbuffsize, clipbText, _TRUNCATE);
+				GlobalUnlock(hText);
+			}
+			else {
+				cblen = 0;
+			}
+		}
+		CloseClipboard();
+	}
+
+	if (cbbuff != NULL && Num >= 0 && Num * (MaxStrLen - 1) < cblen) {
+		if (strncpy_s(buf ,sizeof(buf), cbbuff + Num * (MaxStrLen-1), _TRUNCATE) == STRUNCATE)
+			SetResult(2); // Copied string is truncated.
+		else {
+			SetResult(1);
+		}
+		SetStrVal(VarId, buf);
+	}
+	else {
+		SetResult(0);
+	}
+
+	return Err;
+}
+
+// add 'var2clipb' (2006.9.17 maya)
+WORD TTLVar2Clipb()
+{
+	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);
+
+	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;
+}
+
+// add 'filenamebox' (2007.9.13 maya)
+WORD TTLFilenameBox()
+{
+	TStrVal Str1;
+	WORD Err, ValType;
+	TVarId VarId;
+	OPENFILENAME ofn;
+	TCHAR uimsg[MAX_UIMSG];
+	BOOL SaveFlag = FALSE;
+	TStrVal InitDir = "";
+	tc InitDirT;
+	BOOL ret;
+
+	Err = 0;
+	GetStrVal(Str1,&Err);
+	tc Str1T = Str1;
+
+	if (Err!=0) return Err;
+
+	// get 2nd arg(optional) if given
+	if (CheckParameterGiven()) { // dialogtype
+		GetIntVal(&SaveFlag, &Err);
+		if (Err!=0) return Err;
+
+		// get 3rd arg(optional) if given
+		if (CheckParameterGiven()) { // initdir
+			GetStrVal(InitDir, &Err);
+			if (Err!=0) return Err;
+			InitDirT = InitDir;
+		}
+	}
+
+	if ((Err==0) && (GetFirstChar()!=0))
+		Err = ErrSyntax;
+	if (Err!=0) return Err;
+
+	SetInputStr("");
+	if (CheckVar("inputstr", &ValType, &VarId) && (ValType==TypString)) {
+#if defined(UNICODE)
+		TCHAR filename[MaxStrLen];
+#endif
+		memset(&ofn, 0, sizeof(OPENFILENAME));
+		ofn.lStructSize     = sizeof(OPENFILENAME);
+		ofn.hwndOwner       = GetHWND();
+		ofn.lpstrTitle      = Str1T;
+#if defined(UNICODE)
+		ofn.lpstrFile       = filename;
+		ofn.nMaxFile        = _countof(filename);
+#else
+		ofn.lpstrFile       = StrVarPtr(VarId);
+		ofn.nMaxFile        = MaxStrLen;
+#endif
+		get_lang_msgT("FILEDLG_ALL_FILTER", uimsg, _countof(uimsg), _T("All(*.*)\\0*.*\\0\\0"), UILanguageFile);
+		ofn.lpstrFilter     = uimsg;
+		ofn.lpstrInitialDir = NULL;
+		if (strlen(InitDir) > 0) {
+			ofn.lpstrInitialDir = InitDirT;
+		}
+		BringupWindow(GetHWND());
+		if (SaveFlag) {
+			ofn.Flags = OFN_OVERWRITEPROMPT;
+			ret = GetSaveFileName(&ofn);
+		}
+		else {
+			ret = GetOpenFileName(&ofn);
+		}
+
+#if defined(UNICODE)
+		char *dest = StrVarPtr(VarId);
+		::WideCharToMultiByte(CP_ACP, 0, 
+							  filename, MaxStrLen,
+							  dest, MaxStrLen,
+							  NULL,NULL);
+#endif
+		SetResult(ret);
+	}
+	return Err;
+}
+
+WORD TTLDirnameBox()
+{
+	TStrVal Title;
+	WORD Err, ValType;
+	TVarId VarId;
+	char buf[MAX_PATH];
+	TStrVal InitDir = "";
+	BOOL ret;
+
+	Err = 0;
+	GetStrVal(Title, &Err);
+	if (Err != 0) return Err;
+
+	// get 2nd arg(optional) if given
+	if (CheckParameterGiven()) { // initdir
+		GetStrVal(InitDir, &Err);
+		if (Err != 0) return Err;
+	}
+
+	if ((Err == 0) && (GetFirstChar() != 0))
+		Err = ErrSyntax;
+	if (Err != 0) return Err;
+
+	SetInputStr("");
+	if (CheckVar("inputstr", &ValType, &VarId) &&
+	    (ValType == TypString)) {
+		BringupWindow(GetHWND());
+		if (doSelectFolder(GetHWND(), buf, sizeof(buf), InitDir, Title)) {
+			SetInputStr(buf);
+			ret = 1;
+		}
+		else {
+			ret = 0;
+		}
+		SetResult(ret);
+	}
+	return Err;
+}
+
+int MessageCommand(int BoxId, LPWORD Err)
+{
+	TStrVal Str1, Str2;
+	int sp = 0;
+	int ret;
+	int i, ary_size;
+	int sel = 0;
+	TVarId VarId;
+
+	*Err = 0;
+	GetStrVal2(Str1, Err, TRUE);
+	GetStrVal2(Str2, Err, TRUE);
+	if (*Err!=0) return 0;
+
+	if (BoxId != IdListBox) {
+		// get 3rd arg(optional) if given
+		if (CheckParameterGiven()) {
+			GetIntVal(&sp, Err);
+		}
+		if ((*Err==0) && (GetFirstChar()!=0))
+			*Err = ErrSyntax;
+		if (*Err!=0) return 0;
+	}
+
+	if (sp) {
+		RestoreNewLine(Str1);
+	}
+
+	if (BoxId==IdMsgBox) {
+		ret = OpenMsgDlg(tc::fromUtf8(Str1),tc::fromUtf8(Str2),FALSE);
+		// メッセージボックスをキャンセルすると、マクロの終了とする。
+		// (2008.8.5 yutaka)
+		if (ret == IDCANCEL) {
+			TTLStatus = IdTTLEnd;
+		}
+	} else if (BoxId==IdYesNoBox) {
+		ret = OpenMsgDlg(tc::fromUtf8(Str1),tc::fromUtf8(Str2),TRUE);
+		// メッセージボックスをキャンセルすると、マクロの終了とする。
+		// (2008.8.6 yutaka)
+		if (ret == IDCLOSE) {
+			TTLStatus = IdTTLEnd;
+		}
+		return (ret);
+	}
+	else if (BoxId==IdStatusBox) {
+		OpenStatDlg(tc::fromUtf8(Str1),tc::fromUtf8(Str2));
+
+	} else if (BoxId==IdListBox) {
+		//  リストボックスの選択肢を取得する。
+		GetStrAryVar(&VarId, Err);
+
+		if (CheckParameterGiven()) {
+			GetIntVal(&sel, Err);
+		}
+		if (*Err==0 && GetFirstChar()!=0)
+			*Err = ErrSyntax;
+		if (*Err!=0) return 0;
+
+		ary_size = GetStrAryVarSize(VarId);
+		if (sel < 0 || sel >= ary_size) {
+			sel = 0;
+		}
+
+		const TCHAR **s = (const TCHAR **)calloc(ary_size + 1, sizeof(TCHAR *));
+		if (s == NULL) {
+			*Err = ErrFewMemory;
+			return -1;
+		}
+		for (i = 0 ; i < ary_size ; i++) {
+			TVarId VarId2;
+			VarId2 = GetStrVarFromArray(VarId, i, Err);
+			if (*Err!=0) return -1;
+			s[i] = ToTcharA(StrVarPtr(VarId2));
+		}
+		if (s[0] == NULL) {
+			*Err = ErrSyntax;
+			return -1;
+		}
+
+		// return 
+		//   0以上: 選択項目
+		//   -1: キャンセル
+		//	 -2: close
+		ret = OpenListDlg(tc::fromUtf8(Str1), tc::fromUtf8(Str2), s, sel);
+
+		for (i = 0 ; i < ary_size ; i++) {
+			free((void *)s[i]);
+		}
+		free(s);
+
+		// リストボックスの閉じるボタン(&確認ダイアログ)で、マクロの終了とする。
+		if (ret == -2) {
+			TTLStatus = IdTTLEnd;
+		}
+		return (ret);
+
+	}
+	return 0;
+}
+
+// リストボックス
+// (2013.3.13 yutaka)
+WORD TTLListBox()
+{
+	WORD Err;
+	int ret;
+
+	ret = MessageCommand(IdListBox, &Err);
+	SetResult(ret);
+	return Err;
+}
+
+WORD TTLMessageBox()
+{
+	WORD Err;
+
+	MessageCommand(IdMsgBox, &Err);
+	return Err;
+}
+
+/* ttmparse.cから移動 */
+extern "C" void DispErr(WORD Err)
+{
+	const TCHAR *Msg;
+	int i;
+	int no, start, end;
+	char *filename;
+
+	Msg = _T("Unknown error message number.");
+
+	switch (Err) {
+		case ErrCloseParent: Msg = _T("\")\" expected."); break;
+		case ErrCantCall: Msg = _T("Can't call sub."); break;
+		case ErrCantConnect: Msg = _T("Can't link macro."); break;
+		case ErrCantOpen: Msg = _T("Can't open file."); break;
+		case ErrDivByZero: Msg = _T("Divide by zero."); break;
+		case ErrInvalidCtl: Msg = _T("Invalid control."); break;
+		case ErrLabelAlreadyDef: Msg = _T("Label already defined."); break;
+		case ErrLabelReq: Msg = _T("Label requiered."); break;
+		case ErrLinkFirst: Msg = _T("Link macro first. Use 'connect' macro."); break;
+		case ErrStackOver: Msg = _T("Stack overflow."); break;
+		case ErrSyntax: Msg = _T("Syntax error."); break;
+		case ErrTooManyLabels: Msg = _T("Too many labels."); break;
+		case ErrTooManyVar: Msg = _T("Too many variables."); break;
+		case ErrTypeMismatch: Msg = _T("Type mismatch."); break;
+		case ErrVarNotInit: Msg = _T("Variable not initialized."); break;
+		case ErrCloseComment: Msg = _T("\"*/\" expected."); break;
+		case ErrOutOfRange: Msg = _T("Index out of range."); break;
+		case ErrCloseBracket: Msg = _T("\"]\" expected."); break;
+		case ErrFewMemory: Msg = _T("Can't allocate memory."); break;
+		case ErrNotSupported: Msg = _T("Unknown command."); break;
+	}
+
+	no = GetLineNo();
+	start = LineParsePtr;
+	end = LinePtr;
+	if (start == end)
+		end = LineLen;
+
+	filename = GetMacroFileName();
+
+	i = OpenErrDlg(Msg, tc::fromUtf8(LineBuff), no, start, end, (tc)filename);
+	if (i==IDOK) TTLStatus = IdTTLEnd;
+}
+
+WORD TTLGetPassword()
+{
+	TStrVal Str, Str2, Temp2;
+	char Temp[512];
+	WORD Err;
+	TVarId VarId;
+	int result = 0;  /* failure */
+
+	Err = 0;
+	GetStrVal(Str,&Err);
+	GetStrVal(Str2,&Err);
+	GetStrVar(&VarId,&Err);
+	if ((Err==0) && (GetFirstChar()!=0))
+		Err = ErrSyntax;
+	if (Err!=0) return Err;
+	SetStrVal(VarId,"");
+	if (Str[0]==0) return Err;
+	if (Str2[0]==0) return Err;
+
+	GetAbsPath(Str,sizeof(Str));
+
+	GetPrivateProfileStringA("Password",Str2,"",
+							 Temp,sizeof(Temp), Str);
+	if (Temp[0]==0) // password not exist
+	{
+#if defined(UNICODE)
+		tc Str2T = Str2;
+		TCHAR input_string[MaxStrLen];
+		OpenInpDlg(input_string, Str2T, _T("Enter password"), _T(""), TRUE);
+		WideCharToMultiByte(CP_ACP, 0,
+							input_string, -1,
+							Temp2, _countof(Temp2),
+							NULL, NULL);
+#else
+		OpenInpDlg(Temp2, Str2, _T("Enter password"), _T(""), TRUE);
+#endif
+		if (Temp2[0]!=0) {
+			Encrypt(Temp2,Temp);
+			if (WritePrivateProfileStringA("Password",Str2,Temp, Str) != 0) {
+				result = 1;  /* success */
+			}
+		}
+	}
+	else {// password exist
+		Decrypt(Temp,Temp2);
+		result = 1;  /* success */
+	}
+
+	SetStrVal(VarId,Temp2);
+
+	SetResult(result);  // 成功可否を設定する。
+	return Err;
+}
+
+WORD TTLInputBox(BOOL Paswd)
+{
+	TStrVal Str1, Str2, Str3;
+	WORD Err, ValType, P;
+	TVarId VarId;
+	int sp = 0;
+
+	Err = 0;
+	GetStrVal(Str1,&Err);
+	GetStrVal(Str2,&Err);
+	if (Err!=0) return Err;
+
+	if (!Paswd && CheckParameterGiven()) {
+		// get 3rd arg(optional)
+		P = LinePtr;
+		GetStrVal(Str3,&Err);
+		if (Err == ErrTypeMismatch) {
+			strncpy_s(Str3,sizeof(Str3),"",_TRUNCATE);
+			LinePtr = P;
+			Err = 0;
+		}
+	}
+	else {
+		strncpy_s(Str3,sizeof(Str3),"",_TRUNCATE);
+	}
+
+	// get 4th(3rd) arg(optional) if given
+	if (CheckParameterGiven()) {
+		GetIntVal(&sp, &Err);
+	}
+
+	if ((Err==0) && (GetFirstChar()!=0))
+		Err = ErrSyntax;
+	if (Err!=0) return Err;
+
+	if (sp) {
+		RestoreNewLine(Str1);
+	}
+
+	SetInputStr("");
+	if (CheckVar("inputstr",&ValType,&VarId) && (ValType==TypString)) {
+#if defined(UNICODE)
+		tc Str1T = Str1;
+		tc Str2T = Str2;
+		tc Str3T = Str3;
+		TCHAR input_string[MaxStrLen];
+		OpenInpDlg(input_string,Str1T,Str2T,Str3T,Paswd);
+		char *output = StrVarPtr(VarId);
+		WideCharToMultiByte(CP_ACP, 0,
+							input_string, -1,
+							output, MaxStrLen,
+							NULL, NULL);
+#else
+		OpenInpDlg(StrVarPtr(VarId),Str1,Str2,Str3,Paswd);
+#endif
+	}
+	return Err;
+}

Added: branches/cmake/teraterm/ttpmacro/ttl_gui.h
===================================================================
--- branches/cmake/teraterm/ttpmacro/ttl_gui.h	                        (rev 0)
+++ branches/cmake/teraterm/ttpmacro/ttl_gui.h	2018-12-18 14:46:36 UTC (rev 7333)
@@ -0,0 +1,26 @@
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+WORD TTLVar2Clipb();
+WORD TTLClipb2Var();
+WORD TTLFilenameBox();
+WORD TTLDirnameBox();
+
+#define IdMsgBox 1
+#define IdYesNoBox 2
+#define IdStatusBox 3
+#define IdListBox 4
+#define LISTBOX_ITEM_NUM 10
+
+int MessageCommand(int BoxId, LPWORD Err);
+WORD TTLListBox();
+WORD TTLMessageBox();
+WORD TTLGetPassword();
+WORD TTLInputBox(BOOL Paswd);
+
+#ifdef __cplusplus
+}
+#endif

Modified: branches/cmake/teraterm/ttpmacro/ttmacro.h
===================================================================
--- branches/cmake/teraterm/ttpmacro/ttmacro.h	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/ttmacro.h	2018-12-18 14:46:36 UTC (rev 7333)
@@ -51,3 +51,6 @@
 	DECLARE_MESSAGE_MAP()
 };
 #endif
+
+HINSTANCE GetInstance();
+HWND GetHWND();

Modified: branches/cmake/teraterm/ttpmacro/ttmbuff.c
===================================================================
--- branches/cmake/teraterm/ttpmacro/ttmbuff.c	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/ttmbuff.c	2018-12-18 14:46:36 UTC (rev 7333)
@@ -36,6 +36,7 @@
 #include "ttmparse.h"
 #include "ttlib.h"
 #include "fileread.h"
+#include "fileread.h"
 
 #include "ttmbuff.h"
 
@@ -142,8 +143,8 @@
 
 	BuffPtr[IBuff] = 0;
 
-	Buff[IBuff] = LoadFileAA(FileName, &Len);
-//	Buff[IBuff] = LoadFileU8A(FileName, &Len);
+//	Buff[IBuff] = LoadFileAA(FileName, &Len);
+	Buff[IBuff] = LoadFileU8A(FileName, &Len);
 	if (Buff[IBuff] == NULL) {
 		BuffLen[IBuff] = 0;
 		return FALSE;

Modified: branches/cmake/teraterm/ttpmacro/ttmdde.c
===================================================================
--- branches/cmake/teraterm/ttpmacro/ttmdde.c	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/ttmdde.c	2018-12-18 14:46:36 UTC (rev 7333)
@@ -29,6 +29,9 @@
 
 // TTMACRO.EXE, DDE routines
 
+#undef UNICODE
+#undef _UNICODE
+
 #include "teraterm.h"
 #include <stdio.h>
 #include <stdlib.h>

Modified: branches/cmake/teraterm/ttpmacro/ttmdlg.cpp
===================================================================
--- branches/cmake/teraterm/ttpmacro/ttmdlg.cpp	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/ttmdlg.cpp	2018-12-18 14:46:36 UTC (rev 7333)
@@ -33,6 +33,7 @@
 #include <direct.h>
 #include <commdlg.h>
 #include <crtdbg.h>
+#include <tchar.h>
 
 #include "teraterm.h"
 #include "ttm_res.h"
@@ -46,6 +47,7 @@
 #include "ListDlg.h"
 #include "ttmlib.h"
 #include "ttmdlg.h"
+#include "ttmacro.h"
 
 #ifdef _DEBUG
 #define malloc(l)     _malloc_dbg((l), _NORMAL_BLOCK, __FILE__, __LINE__)
@@ -56,9 +58,6 @@
 #define _strdup(s)	  _strdup_dbg((s), _NORMAL_BLOCK, __FILE__, __LINE__)
 #endif
 
-extern HINSTANCE GetInstance();
-extern HWND GetHWND();
-
 char HomeDir[MAXPATHLEN];
 char FileName[MAX_PATH];
 char TopicName[11];
@@ -81,7 +80,7 @@
 	PCHAR start, cur, next;
 
 	// Get home directory
-	if (GetModuleFileName(GetInstance(), FileName,sizeof(FileName)) == 0) {
+	if (GetModuleFileNameA(GetInstance(), FileName,sizeof(FileName)) == 0) {
 		return;
 	}
 	ExtractDirName(FileName,HomeDir);
@@ -93,7 +92,7 @@
 	SleepFlag = FALSE;
 	*IOption = FALSE;
 	*VOption = FALSE;
-	Param = GetCommandLine();
+	Param = GetCommandLineA();
 
 	ParamsSize = 50;
 	Params = (char **)malloc(sizeof(char*) * ParamsSize);
@@ -172,18 +171,24 @@
 
 BOOL GetFileName(HWND HWin)
 {
-	char FNFilter[31];
+	TCHAR FNFilter[64];
 	OPENFILENAME FNameRec;
-	char uimsg[MAX_UIMSG], uimsg2[MAX_UIMSG];
+	TCHAR uimsg[MAX_UIMSG];
+#if defined(UNICODE)
+	TCHAR FileNameT[MAX_PATH];
+#endif
 
 	if (FileName[0]!=0) {
 		return FALSE;
 	}
+#if defined(UNICODE)
+	MultiByteToWideChar(CP_ACP, 0,
+						FileName, -1, FileNameT, _countof(FileNameT));
+#endif
 
-	memset(FNFilter, 0, sizeof(FNFilter));
 	memset(&FNameRec, 0, sizeof(OPENFILENAME));
-	get_lang_msg("FILEDLG_OPEN_MACRO_FILTER", uimsg, sizeof(uimsg), "Macro files (*.ttl)\\0*.ttl\\0\\0", UILanguageFile);
-	memcpy(FNFilter, uimsg, sizeof(FNFilter));
+	get_lang_msgT("FILEDLG_OPEN_MACRO_FILTER_", FNFilter, _countof(FNFilter),
+				  _T("Macro files (*.ttl)\\0*.ttl\\0all\\0*.*\\0\\0"), UILanguageFile);
 
 	// sizeof(OPENFILENAME) \x82ł\xCD Windows98/NT \x82ŏI\x97\xB9\x82\xB5\x82Ă\xB5\x82܂\xA4\x82\xBD\x82\xDF (2006.8.14 maya)
 	FNameRec.lStructSize = get_OPENFILENAME_SIZE();
@@ -190,8 +195,13 @@
 	FNameRec.hwndOwner	 = HWin;
 	FNameRec.lpstrFilter	 = FNFilter;
 	FNameRec.nFilterIndex  = 1;
+#if defined(UNICODE)
+	FNameRec.lpstrFile  = FileNameT;
+	FNameRec.nMaxFile  = _countof(FileNameT);
+#else
 	FNameRec.lpstrFile  = FileName;
 	FNameRec.nMaxFile  = sizeof(FileName);
+#endif
 	// \x88ȑO\x93ǂݍ\x9E\x82\xF1\x82\xBE .ttl \x83t\x83@\x83C\x83\x8B\x82̃p\x83X\x82\xF0\x8BL\x89\xAF\x82ł\xAB\x82\xE9\x82悤\x82ɁA\x8F\x89\x8A\xFA\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82\xF0\x8CŒ\xE8\x82ɂ\xB5\x82Ȃ\xA2\x81B
 	// (2008.4.7 yutaka)
 #if 0
@@ -198,10 +208,17 @@
 	FNameRec.lpstrInitialDir = HomeDir;
 #endif
 	FNameRec.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
-	FNameRec.lpstrDefExt = "TTL";
-	get_lang_msg("FILEDLG_OPEN_MACRO_TITLE", uimsg2, sizeof(uimsg2), "MACRO: Open macro", UILanguageFile);
-	FNameRec.lpstrTitle = uimsg2;
+	FNameRec.lpstrDefExt = _T("TTL");
+	get_lang_msgT("FILEDLG_OPEN_MACRO_TITLE",
+				  uimsg, _countof(uimsg), _T("MACRO: Open macro"), UILanguageFile);
+	FNameRec.lpstrTitle = uimsg;
 	if (GetOpenFileName(&FNameRec)) {
+#if defined(UNICODE)
+		WideCharToMultiByte(CP_ACP, 0,
+							FileNameT, -1,
+							FileName, _countof(FileName),
+							NULL, NULL);
+#endif
 		strncpy_s(ShortName, sizeof(ShortName), &(FileName[FNameRec.nFileOffset]), _TRUNCATE);
 	}
 	else {
@@ -226,26 +243,26 @@
 	}
 }
 
-void OpenInpDlg(PCHAR Buff, PCHAR Text, PCHAR Caption,
-                PCHAR Default, BOOL Paswd)
+void OpenInpDlg(TCHAR *Input, const TCHAR *Text, const TCHAR *Caption,
+                const TCHAR *Default, BOOL Paswd)
 {
-	CInpDlg InpDlg(Buff,Text,Caption,Default,Paswd,DlgPosX,DlgPosY);
+	CInpDlg InpDlg(Input,Text,Caption,Default,Paswd,DlgPosX,DlgPosY);
 	InpDlg.DoModal();
 }
 
-int OpenErrDlg(PCHAR Msg, PCHAR Line, int lineno, int start, int end, PCHAR FileName)
+int OpenErrDlg(const TCHAR *Msg, const TCHAR *Line, int lineno, int start, int end, const TCHAR *FileName)
 {
 	CErrDlg ErrDlg(Msg,Line,DlgPosX,DlgPosY, lineno, start, end, FileName);
 	return ErrDlg.DoModal();
 }
 
-int OpenMsgDlg(PCHAR Text, PCHAR Caption, BOOL YesNo)
+int OpenMsgDlg(const TCHAR *Text, const TCHAR *Caption, BOOL YesNo)
 {
 	CMsgDlg MsgDlg(Text,Caption,YesNo,DlgPosX,DlgPosY);
 	return MsgDlg.DoModal();
 }
 
-void OpenStatDlg(PCHAR Text, PCHAR Caption)
+void OpenStatDlg(const TCHAR *Text, const TCHAR *Caption)
 {
 	if (StatDlg==NULL) {
 		StatDlg = new CStatDlg();
@@ -279,7 +296,7 @@
  * @retval -1		cancel\x83{\x83^\x83\x93
  * @retval -2		close\x83{\x83^\x83\x93
  */
-int OpenListDlg(PCHAR Text, PCHAR Caption, CHAR **Lists, int Selected)
+int OpenListDlg(const TCHAR *Text, const TCHAR *Caption, const TCHAR **Lists, int Selected)
 {
 	HINSTANCE hInst = GetInstance();
 	HWND hWnd = GetHWND();

Modified: branches/cmake/teraterm/ttpmacro/ttmdlg.h
===================================================================
--- branches/cmake/teraterm/ttpmacro/ttmdlg.h	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/ttmdlg.h	2018-12-18 14:46:36 UTC (rev 7333)
@@ -40,15 +40,15 @@
 void ParseParam(PBOOL IOption, PBOOL VOption);
 BOOL GetFileName(HWND HWin);
 void SetDlgPos(int x, int y);
-void OpenInpDlg(PCHAR Buff, PCHAR Text, PCHAR Caption,
-                PCHAR Default, BOOL Paswd);
-int OpenErrDlg(PCHAR Msg, PCHAR Line, int lineno, int start, int end, PCHAR FileName);
-int OpenMsgDlg(PCHAR Text, PCHAR Caption, BOOL YesNo);
-void OpenStatDlg(PCHAR Text, PCHAR Caption);
+void OpenInpDlg(TCHAR *Input, const TCHAR *Text, const TCHAR *Caption,
+                const TCHAR *Default, BOOL Paswd);
+int OpenErrDlg(const TCHAR *Msg, const TCHAR *Line, int lineno, int start, int end, const TCHAR *FileName);
+int OpenMsgDlg(const TCHAR *Text, const TCHAR *Caption, BOOL YesNo);
+void OpenStatDlg(const TCHAR *Text, const TCHAR *Caption);
 void CloseStatDlg();
 void BringupStatDlg();
 
-int OpenListDlg(PCHAR Text, PCHAR Caption, CHAR **Lists, int Selected);
+int OpenListDlg(const TCHAR *Text, const TCHAR *Caption, const TCHAR **Lists, int Selected);
 
 extern char HomeDir[MAXPATHLEN];
 extern char FileName[MAX_PATH];

Modified: branches/cmake/teraterm/ttpmacro/ttmlib.c
===================================================================
--- branches/cmake/teraterm/ttpmacro/ttmlib.c	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/ttmlib.c	2018-12-18 14:46:36 UTC (rev 7333)
@@ -34,11 +34,12 @@
 #include <string.h>
 #include <direct.h>
 #include <shlobj.h>
+#include <tchar.h>
 
 static char CurrentDir[MAXPATHLEN];
 
 typedef struct {
-	char *name;
+	const char *name;
 	int csidl;
 } SpFolder;
 
@@ -62,10 +63,10 @@
 	{ NULL,                -1}
 };
 
-void CalcTextExtent(HDC DC, PCHAR Text, LPSIZE s)
+void CalcTextExtent(HDC DC, const TCHAR *Text, LPSIZE s)
 {
   int W, H, i, i0;
-  char Temp[512];
+  TCHAR Temp[512];
   DWORD dwExt;
 
   W = 0;
@@ -77,7 +78,7 @@
 	   (Text[i]!=0x0d) &&
 	   (Text[i]!=0x0a))
       i++;
-    memcpy(Temp,&Text[i0],i-i0);
+    memcpy(Temp,&Text[i0],sizeof(TCHAR) * (i-i0));
     Temp[i-i0] = 0;
     if (Temp[0]==0)
     {
@@ -84,7 +85,7 @@
      Temp[0] = 0x20;
      Temp[1] = 0;
     }
-    dwExt = GetTabbedTextExtent(DC,Temp,strlen(Temp),0,NULL);
+    dwExt = GetTabbedTextExtent(DC,Temp,_tcslen(Temp),0,NULL);
     s->cx = LOWORD(dwExt);
     s->cy = HIWORD(dwExt);
     if (s->cx > W) W = s->cx;
@@ -158,7 +159,7 @@
 		return 0;
 	}
 
-	SHGetPathFromIDList(pidl, Path);
+	SHGetPathFromIDListA(pidl, Path);
 	CoTaskMemFree(pidl);
 
 	strncpy_s(dest, dest_len, Path, _TRUNCATE);
@@ -227,7 +228,7 @@
 	if (Font) {
 		prevFont = (HFONT)SelectObject(TmpDC, Font);
 	}
-	CalcTextExtent(TmpDC, (PCHAR)Text, textSize);
+	CalcTextExtent(TmpDC, Text, textSize);
 	if (Font && prevFont != NULL) {
 		SelectObject(TmpDC, prevFont);
 	}
@@ -236,9 +237,9 @@
 
 int MessageBoxHaltScript(HWND hWnd, const char *UILanguageFile)
 {
-	char uimsg[MAX_UIMSG];
-	char uimsg2[MAX_UIMSG];
-	get_lang_msg("MSG_MACRO_CONF", uimsg, sizeof(uimsg), "MACRO: confirmation", UILanguageFile);
-	get_lang_msg("MSG_MACRO_HALT_SCRIPT", uimsg2, sizeof(uimsg2), "Are you sure that you want to halt this macro script?", UILanguageFile);
+	TCHAR uimsg[MAX_UIMSG];
+	TCHAR uimsg2[MAX_UIMSG];
+	get_lang_msgT("MSG_MACRO_CONF", uimsg, _countof(uimsg), _T("MACRO: confirmation"), UILanguageFile);
+	get_lang_msgT("MSG_MACRO_HALT_SCRIPT", uimsg2, _countof(uimsg2), _T("Are you sure that you want to halt this macro script?"), UILanguageFile);
 	return MessageBox(hWnd, uimsg2, uimsg, MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2);
 }

Modified: branches/cmake/teraterm/ttpmacro/ttmlib.h
===================================================================
--- branches/cmake/teraterm/ttpmacro/ttmlib.h	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/ttmlib.h	2018-12-18 14:46:36 UTC (rev 7333)
@@ -35,7 +35,7 @@
 
 extern char UILanguageFile[MAX_PATH];
 
-void CalcTextExtent(HDC DC, PCHAR Text, LPSIZE s);
+void CalcTextExtent(HDC DC, const TCHAR *Text, LPSIZE s);
 void CalcTextExtent2(HWND hWnd, HFONT Font, const TCHAR *Text, LPSIZE textSize);	// TODO name
 void TTMGetDir(PCHAR Dir, int destlen);
 void TTMSetDir(PCHAR Dir);

Modified: branches/cmake/teraterm/ttpmacro/ttmmain.cpp
===================================================================
--- branches/cmake/teraterm/ttpmacro/ttmmain.cpp	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/ttmmain.cpp	2018-12-18 14:46:36 UTC (rev 7333)
@@ -32,6 +32,7 @@
 #include <windows.h>
 #include <commctrl.h>
 #include <stdio.h>
+#include <tchar.h>
 #include "teraterm.h"
 #include "ttm_res.h"
 #include "ttmdlg.h"
@@ -49,6 +50,7 @@
 #include "wait4all.h"
 
 #include "tmfc.h"
+#include "codeconv.h"
 
 extern HINSTANCE GetInstance();
 
@@ -280,7 +282,7 @@
 	HDC TmpDC;
 	int CRTWidth, CRTHeight;
 	RECT Rect;
-	char Temp[MAX_PATH + 8]; // MAX_PATH + "MACRO - "(8)
+	TCHAR Temp[MAX_PATH + 8]; // MAX_PATH + "MACRO - "(8)
 	BOOL IOption, VOption;
 	int CmdShow;
 	int fuLoad = LR_DEFAULTCOLOR;
@@ -335,8 +337,8 @@
 	// wait4all
 	register_macro_window(GetSafeHwnd());
 #endif
-	strncpy_s(Temp, sizeof(Temp), "MACRO - ", _TRUNCATE);
-	strncat_s(Temp, sizeof(Temp), ShortName, _TRUNCATE);
+	_tcsncpy_s(Temp, _countof(Temp), _T("MACRO - "), _TRUNCATE);
+	_tcsncat_s(Temp, _countof(Temp), (tc)ShortName, _TRUNCATE);
 	SetWindowText(Temp);
 
 	// send the initialization signal to TT
@@ -393,16 +395,16 @@
 
 BOOL CCtrlWindow::OnCommand(WPARAM wParam, LPARAM lParam)
 {
-	char uimsg[MAX_UIMSG];
+	TCHAR uimsg[MAX_UIMSG];
 
 	switch (LOWORD(wParam)) {
 	case IDC_CTRLPAUSESTART:
 		if (Pause) {
-			get_lang_msg("BTN_PAUSE", uimsg, sizeof(uimsg),  "Pau&se", UILanguageFile);
+			get_lang_msgT("BTN_PAUSE", uimsg, _countof(uimsg),  _T("Pau&se"), UILanguageFile);
 			SetDlgItemText(IDC_CTRLPAUSESTART, uimsg);
 		}
 		else {
-			get_lang_msg("BTN_START", uimsg, sizeof(uimsg),  "&Start", UILanguageFile);
+			get_lang_msgT("BTN_START", uimsg, _countof(uimsg),  _T("&Start"), UILanguageFile);
 			SetDlgItemText(IDC_CTRLPAUSESTART, uimsg);
 		}
 		Pause = ! Pause;
@@ -448,7 +450,7 @@
 {
 	PAINTSTRUCT ps;
 	HDC dc;
-	char buf[128];
+	TCHAR buf[128];
 
 	dc = BeginPaint(&ps);
 
@@ -456,8 +458,8 @@
 	// added line buffer (2005.7.22 yutaka)
 	// added MACRO filename (2013.9.8 yutaka)
 	// \x83t\x83@\x83C\x83\x8B\x96\xBC\x82̖\x96\x94\xF6\x82͏ȗ\xAA\x95\\x8E\xA6\x82Ƃ\xB7\x82\xE9\x81B(2014.12.30 yutaka)
-	SetDlgItemText(IDC_FILENAME, GetMacroFileName());
-	_snprintf_s(buf, sizeof(buf), _TRUNCATE, ":%d:%s", GetLineNo(), GetLineBuffer());
+	SetDlgItemText(IDC_FILENAME, (tc)GetMacroFileName());
+	_sntprintf_s(buf, _countof(buf), _TRUNCATE, _T(":%d:%s"), GetLineNo(), (const TCHAR *)(tc)GetLineBuffer());
 	SetDlgItemText(IDC_LINENO, buf);
 
 	if (::IsIconic(m_hWnd)) {

Modified: branches/cmake/teraterm/ttpmacro/ttmparse.c
===================================================================
--- branches/cmake/teraterm/ttpmacro/ttmparse.c	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/ttmparse.c	2018-12-18 14:46:36 UTC (rev 7333)
@@ -37,6 +37,7 @@
 #include "ttmdlg.h"
 #include "ttmparse.h"
 #include "ttmbuff.h"
+#include "codeconv.h"
 
 #ifdef _DEBUG
 
@@ -126,6 +127,7 @@
 	GlobalFree(HStrBuff);
 }
 
+#if 0	// ttl_gui.c\x82ɂƂ肠\x82\xA6\x82\xB8\x8E\x9D\x82\xC1\x82Ă\xA2\x82\xC1\x82\xBD
 void DispErr(WORD Err)
 {
 	char Msg[41];
@@ -166,9 +168,10 @@
 
 	filename = GetMacroFileName();
 
-	i = OpenErrDlg(Msg, LineBuff, no, start, end, filename);
+	i = OpenErrDlg((tc)Msg, (tc)LineBuff, no, start, end, (tc)filename);
 	if (i==IDOK) TTLStatus = IdTTLEnd;
 }
+#endif
 
 void LockVar()
 {

Modified: branches/cmake/teraterm/ttpmacro/wait4all.c
===================================================================
--- branches/cmake/teraterm/ttpmacro/wait4all.c	2018-12-18 14:46:19 UTC (rev 7332)
+++ branches/cmake/teraterm/ttpmacro/wait4all.c	2018-12-18 14:46:36 UTC (rev 7333)
@@ -32,6 +32,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <windows.h>
+#include <tchar.h>
 #include "wait4all.h"
 #include "ttlib.h"
 
@@ -40,7 +41,7 @@
 static int function_disable = 1;  
 
 // \x8B\xA4\x97L\x83\x81\x83\x82\x83\x8A\x83t\x83H\x81[\x83}\x83b\x83g\x8Ag\x92\xA3\x8E\x9E\x82́A\x88ȉ\xBA\x82̖\xBC\x8F̂\xF0\x95ύX\x82\xB7\x82邱\x82ƁB
-#define TTM_FILEMAPNAME "ttm_memfilemap_1"
+#define TTM_FILEMAPNAME _T("ttm_memfilemap_1")
 
 // \x8B\xA4\x97L\x83\x81\x83\x82\x83\x8A\x82̃t\x83H\x81[\x83}\x83b\x83g
 typedef struct {
@@ -61,7 +62,7 @@
 static BOOL QuoteFlag;
 
 // \x94r\x91\xBC\x90\xA7\x8C\xE4
-#define MUTEX_NAME "Mutex Object for macro shmem"
+#define MUTEX_NAME _T("Mutex Object for macro shmem")
 static HANDLE hMutex = NULL;
 
 // \x8B\xA4\x97L\x83\x81\x83\x82\x83\x8A\x83C\x83\x93\x83f\x83b\x83N\x83X
@@ -79,7 +80,7 @@
 static int open_macro_shmem(void)
 {
 	HMap = CreateFileMapping(
-		(HANDLE) 0xFFFFFFFF, NULL, PAGE_READWRITE,
+		INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
 		0, sizeof(TMacroShmem), TTM_FILEMAPNAME);
 	if (HMap == NULL)
 		return FALSE;


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