[Ttssh2-commit] [7546] ttpmacro 高DPI対応

scmno****@osdn***** scmno****@osdn*****
2019年 4月 3日 (水) 01:27:06 JST


Revision: 7546
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/7546
Author:   zmatsuo
Date:     2019-04-03 01:27:06 +0900 (Wed, 03 Apr 2019)
Log Message:
-----------
ttpmacro 高DPI対応

Modified Paths:
--------------
    trunk/teraterm/common/dllutil.cpp
    trunk/teraterm/ttpmacro/ListDlg.cpp
    trunk/teraterm/ttpmacro/errdlg.cpp
    trunk/teraterm/ttpmacro/inpdlg.cpp
    trunk/teraterm/ttpmacro/msgdlg.cpp
    trunk/teraterm/ttpmacro/statdlg.cpp
    trunk/teraterm/ttpmacro/ttl.c
    trunk/teraterm/ttpmacro/ttmacro.cpp
    trunk/teraterm/ttpmacro/ttmacro.h
    trunk/teraterm/ttpmacro/ttmdlg.cpp
    trunk/teraterm/ttpmacro/ttmlib.c
    trunk/teraterm/ttpmacro/ttmlib.h
    trunk/teraterm/ttpmacro/ttmmain.cpp
    trunk/teraterm/ttpmacro/ttmparse.c

-------------- next part --------------
Modified: trunk/teraterm/common/dllutil.cpp
===================================================================
--- trunk/teraterm/common/dllutil.cpp	2019-04-02 16:26:49 UTC (rev 7545)
+++ trunk/teraterm/common/dllutil.cpp	2019-04-02 16:27:06 UTC (rev 7546)
@@ -37,6 +37,7 @@
 #define malloc(l)     _malloc_dbg((l), _NORMAL_BLOCK, __FILE__, __LINE__)
 #define free(p)       _free_dbg((p), _NORMAL_BLOCK)
 #define _strdup(s)	  _strdup_dbg((s), _NORMAL_BLOCK, __FILE__, __LINE__)
+#define	realloc(p, l) _realloc_dbg((p), (l),  _NORMAL_BLOCK, __FILE__, __LINE__)
 #endif
 
 typedef struct {

Modified: trunk/teraterm/ttpmacro/ListDlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ListDlg.cpp	2019-04-02 16:26:49 UTC (rev 7545)
+++ trunk/teraterm/ttpmacro/ListDlg.cpp	2019-04-02 16:27:06 UTC (rev 7546)
@@ -68,11 +68,9 @@
 	};
 	char **p;
 	int ListMaxWidth = 0;
-	int ListWidth;
 	int ListCount = 0;
 	HDC DC;
 	RECT R;
-	HDC TmpDC;
 	HWND HList, HOk;
 
 	SetDlgTexts(m_hWnd, TextInfos, _countof(TextInfos), UILanguageFile);
@@ -83,6 +81,7 @@
 	p = m_Lists;
 	while (*p) {
 		SIZE size;
+		int ListWidth;
 		SendDlgItemMessage(IDC_LISTBOX, LB_ADDSTRING, 0, (LPARAM)(*p));
 		GetTextExtentPoint32(DC, *p, strlen(*p), &size);
 		ListWidth = size.cx;
@@ -94,7 +93,7 @@
 	}
 
 	SendDlgItemMessage(IDC_LISTBOX, LB_SETHORIZONTALEXTENT, (ListMaxWidth + 5), 0);
-	::ReleaseDC(m_hWnd, DC);
+	::ReleaseDC(HList, DC);
 
 	if (m_Selected < 0 || m_Selected >= ListCount) {
 		m_Selected = 0;
@@ -105,9 +104,7 @@
 	SetDlgItemText(IDC_LISTTEXT, m_Text);
 	SetWindowText(m_Caption);
 
-	TmpDC = ::GetDC(GetDlgItem(IDC_LISTTEXT));
-	CalcTextExtent(TmpDC,m_Text,&s);
-	::ReleaseDC(GetDlgItem(IDC_LISTTEXT), TmpDC);
+	CalcTextExtent(GetDlgItem(IDC_LISTTEXT), NULL, m_Text,&s);
 	TW = s.cx + s.cx/10;
 	TH = s.cy;
 
@@ -162,7 +159,7 @@
 	::GetClientRect(m_hWnd, &R);
 	CW = R.right-R.left;
 	CH = R.bottom-R.top;
-
+#define CONTROL_GAP_W	14
 	// \x8F\x89\x89\xF1\x82̂\xDD
 	if (is_init) {
 		// \x83e\x83L\x83X\x83g\x83R\x83\x93\x83g\x83\x8D\x81[\x83\x8B\x83T\x83C\x83Y\x82\xF0\x95␳
@@ -174,8 +171,8 @@
 		WH = TH + LH + (int)(BH*1.5) + (WH - CH);
 		init_WW = WW;
 		// \x83\x8A\x83X\x83g\x83{\x83b\x83N\x83X\x83T\x83C\x83Y\x82̌v\x8EZ
-		if (LW < WW - BW - 14*3) {
-			LW = WW - BW - 14*3;
+		if (LW < CW - BW - CONTROL_GAP_W * 3) {
+			LW = CW - BW - CONTROL_GAP_W * 3;
 		}
 	}
 	else {
@@ -189,9 +186,9 @@
 	HList = ::GetDlgItem(GetSafeHwnd(), IDC_LISTBOX);
 
 	::MoveWindow(HText,(TW-s.cx)/2,LH+BH,TW,TH,TRUE);
-	::MoveWindow(HList,14,BH/2,LW,LH,TRUE);
-	::MoveWindow(HOk,14+14+LW,BH/2,BW,BH,TRUE);
-	::MoveWindow(HCancel,14+14+LW,BH*2,BW,BH,TRUE);
+	::MoveWindow(HList,CONTROL_GAP_W,BH/2,LW,LH,TRUE);
+	::MoveWindow(HOk,CONTROL_GAP_W+CONTROL_GAP_W+LW,BH/2,BW,BH,TRUE);
+	::MoveWindow(HCancel,CONTROL_GAP_W+CONTROL_GAP_W+LW,BH*2,BW,BH,TRUE);
 
 	if (PosX<=GetMonitorLeftmost(PosX, PosY)-100) {
 		::GetWindowRect(m_hWnd, &R);

Modified: trunk/teraterm/ttpmacro/errdlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/errdlg.cpp	2019-04-02 16:26:49 UTC (rev 7545)
+++ trunk/teraterm/ttpmacro/errdlg.cpp	2019-04-02 16:27:06 UTC (rev 7546)
@@ -31,23 +31,21 @@
 
 #include <windowsx.h>
 #include <stdio.h>
+
 #include "tmfc.h"
 #include "teraterm.h"
 #include "ttlib.h"
 #include "ttm_res.h"
-
 #include "tttypes.h"
 #include "ttcommon.h"
 #include "helpid.h"
-
-#include "errdlg.h"
 #include "ttmlib.h"
 #include "ttmparse.h"
 #include "htmlhelp.h"
 #include "dlglib.h"
+#include "ttmacro.h"
 
-extern HINSTANCE GetInstance();
-extern HWND GetHWND();
+#include "errdlg.h"
 
 // CErrDlg dialog
 

Modified: trunk/teraterm/ttpmacro/inpdlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/inpdlg.cpp	2019-04-02 16:26:49 UTC (rev 7545)
+++ trunk/teraterm/ttpmacro/inpdlg.cpp	2019-04-02 16:27:06 UTC (rev 7546)
@@ -35,12 +35,11 @@
 #include "ttm_res.h"
 #include "ttmlib.h"
 #include "dlglib.h"
+#include "ttmacro.h"
+#include "compat_win.h"
 
 #include "inpdlg.h"
 
-extern HINSTANCE GetInstance();
-extern HWND GetHWND();
-
 // CInpDlg dialog
 CInpDlg::CInpDlg(PCHAR Input, PCHAR Text, PCHAR Title,
                  PCHAR Default, BOOL Paswd,
@@ -76,7 +75,7 @@
 	SetDlgItemText(IDC_INPTEXT,TextStr);
 	SetDlgItemText(IDC_INPEDIT,DefaultStr);
 
-	CalcTextExtent2(GetDlgItem(IDC_STATTEXT), NULL, TextStr, &s);
+	CalcTextExtent(GetDlgItem(IDC_INPTEXT), NULL, TextStr, &s);
 	TW = s.cx + s.cx/10;
 	TH = s.cy;
 
@@ -189,6 +188,13 @@
 	switch(msg) {
 	case WM_EXITSIZEMOVE:
 		return OnExitSizeMove(wp, lp);
+	case WM_DPICHANGED: {
+		RECT rect;
+		::GetWindowRect(m_hWnd, &rect);
+		WW = rect.right - rect.left;
+		WH = rect.bottom - rect.top;
+		break;
 	}
+	}
 	return FALSE;
 }

Modified: trunk/teraterm/ttpmacro/msgdlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/msgdlg.cpp	2019-04-02 16:26:49 UTC (rev 7545)
+++ trunk/teraterm/ttpmacro/msgdlg.cpp	2019-04-02 16:27:06 UTC (rev 7546)
@@ -39,6 +39,7 @@
 #include "dlglib.h"
 #include "ttmdlg.h"
 #include "ttmacro.h"
+#include "compat_win.h"
 
 #include "msgdlg.h"
 
@@ -81,7 +82,7 @@
 
 	SetWindowText(TitleStr);
 	SetDlgItemText(IDC_MSGTEXT,TextStr);
-	CalcTextExtent2(GetDlgItem(IDC_STATTEXT), NULL, TextStr, &s);
+	CalcTextExtent(GetDlgItem(IDC_MSGTEXT), NULL, TextStr, &s);
 	TW = s.cx + s.cx/10;
 	TH = s.cy;
 
@@ -106,7 +107,7 @@
 	RECT R;
 
 	GetWindowRect(&R);
-	if (R.bottom-R.top == WH && R.right-R.left == WW) {
+		if (R.bottom-R.top == WH && R.right-R.left == WW) {
 		// \x83T\x83C\x83Y\x82\xAA\x95ς\xED\x82\xC1\x82Ă\xA2\x82Ȃ\xAF\x82\xEA\x82Ή\xBD\x82\xE0\x82\xB5\x82Ȃ\xA2
 	}
 	else if (R.bottom-R.top != WH || R.right-R.left < init_WW) {
@@ -206,6 +207,13 @@
 	switch(msg) {
 	case WM_EXITSIZEMOVE:
 		return OnExitSizeMove(wp, lp);
+	case WM_DPICHANGED: {
+		RECT rect;
+		::GetWindowRect(m_hWnd, &rect);
+		WW = rect.right - rect.left;
+		WH = rect.bottom - rect.top;
+		break;
 	}
+	}
 	return FALSE;
 }

Modified: trunk/teraterm/ttpmacro/statdlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/statdlg.cpp	2019-04-02 16:26:49 UTC (rev 7545)
+++ trunk/teraterm/ttpmacro/statdlg.cpp	2019-04-02 16:27:06 UTC (rev 7546)
@@ -37,14 +37,12 @@
 #include "ttmlib.h"
 #include "tmfc.h"
 #include "tttypes.h"
+#include "ttmacro.h"
 
 #include "statdlg.h"
 
 // CStatDlg dialog
 
-
-extern HINSTANCE GetInstance();
-
 BOOL CStatDlg::Create(PCHAR Text, PCHAR Title, int x, int y)
 {
 	TextStr = Text;
@@ -73,7 +71,7 @@
 	if (Text!=NULL) {
 		SIZE textSize;
 		HWND hWnd = GetDlgItem(IDC_STATTEXT);
-		CalcTextExtent2(hWnd, NULL, Text, &textSize);
+		CalcTextExtent(hWnd, NULL, Text, &textSize);
 		TW = textSize.cx + textSize.cx/10;	// (cx * (1+0.1)) ?
 		TH = textSize.cy;
 		s = textSize;			// TODO s!?

Modified: trunk/teraterm/ttpmacro/ttl.c
===================================================================
--- trunk/teraterm/ttpmacro/ttl.c	2019-04-02 16:26:49 UTC (rev 7545)
+++ trunk/teraterm/ttpmacro/ttl.c	2019-04-02 16:27:06 UTC (rev 7546)
@@ -3522,6 +3522,7 @@
 		// return 
 		//   0\x88ȏ\xE3: \x91I\x91\xF0\x8D\x80\x96\xDA
 		//   -1: \x83L\x83\x83\x83\x93\x83Z\x83\x8B
+		//	 -2: close
 		ret = OpenListDlg(Str1, Str2, s, sel);
 
 		for (i = 0 ; i < ary_size ; i++) {
@@ -3529,6 +3530,10 @@
 		}
 		free(s);
 
+		// \x83\x8A\x83X\x83g\x83{\x83b\x83N\x83X\x82̕‚\xB6\x82\xE9\x83{\x83^\x83\x93(&\x8Am\x94F\x83_\x83C\x83A\x83\x8D\x83O)\x82ŁA\x83}\x83N\x83\x8D\x82̏I\x97\xB9\x82Ƃ\xB7\x82\xE9\x81B
+		if (ret == -2) {
+			TTLStatus = IdTTLEnd;
+		}
 		return (ret);
 
 	}

Modified: trunk/teraterm/ttpmacro/ttmacro.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ttmacro.cpp	2019-04-02 16:26:49 UTC (rev 7545)
+++ trunk/teraterm/ttpmacro/ttmacro.cpp	2019-04-02 16:27:06 UTC (rev 7546)
@@ -33,54 +33,52 @@
 #include <crtdbg.h>
 #include <windows.h>
 #include <commctrl.h>
+
 #include "teraterm.h"
+#include "compat_w95.h"
+#include "compat_win.h"
+#include "ttmdlg.h"
+#include "tmfc.h"
+#include "dlglib.h"
+#include "dllutil.h"
+
 #include "ttm_res.h"
 #include "ttmmain.h"
 #include "ttl.h"
-
 #include "ttmacro.h"
 #include "ttmlib.h"
 #include "ttlib.h"
 
-#include "compat_w95.h"
-#include "compat_win.h"
-#include "ttmdlg.h"
-#include "tmfc.h"
-
 #ifdef _DEBUG
 #define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
 #endif
 
 char UILanguageFile[MAX_PATH];
+static HWND CtrlWnd;
+static HINSTANCE hInst;
+
 static BOOL Busy;
-static HINSTANCE hInst;
 static CCtrlWindow *pCCtrlWindow;
 
-static void init()
+HINSTANCE GetInstance()
 {
-	typedef BOOL (WINAPI *pSetDllDir)(LPCSTR);
-	typedef BOOL (WINAPI *pSetDefDllDir)(DWORD);
+	return hInst;
+}
 
-	HMODULE module;
-	pSetDllDir setDllDir;
-	pSetDefDllDir setDefDllDir;
+HWND GetHWND()
+{
+	return CtrlWnd;
+}
 
-	if ((module = GetModuleHandle("kernel32.dll")) != NULL) {
-		if ((setDefDllDir = (pSetDefDllDir)GetProcAddress(module, "SetDefaultDllDirectories")) != NULL) {
-			// SetDefaultDllDirectories() \x82\xAA\x8Eg\x82\xA6\x82\xE9\x8Fꍇ\x82́A\x8C\x9F\x8D\xF5\x83p\x83X\x82\xF0 %WINDOWS%\system32 \x82݂̂ɐݒ肷\x82\xE9
-			(*setDefDllDir)((DWORD)0x00000800); // LOAD_LIBRARY_SEARCH_SYSTEM32
-		}
-		else if ((setDllDir = (pSetDllDir)GetProcAddress(module, "SetDllDirectoryA")) != NULL) {
-			// SetDefaultDllDirectories() \x82\xAA\x8Eg\x82\xA6\x82Ȃ\xAD\x82Ă\xE0\x81ASetDllDirectory() \x82\xAA\x8Eg\x82\xA6\x82\xE9\x8Fꍇ\x82\xCD
-			// \x83J\x83\x8C\x83\x93\x83g\x83f\x83B\x83\x8C\x83N\x83g\x83\x8A\x82\xBE\x82\xAF\x82ł\xE0\x8C\x9F\x8D\xF5\x83p\x83X\x82\xA9\x82\xE7\x82͂\xB8\x82\xB5\x82Ă\xA8\x82\xAD\x81B
-			(*setDllDir)("");
-		}
-	}
-
+static void init()
+{
+	DLLInit();
 	WinCompatInit();
 	if (pSetThreadDpiAwarenessContext) {
 		pSetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
 	}
+	// messagebox\x82̃t\x83H\x83\x93\x83g\x82ɐݒ肷\x82\xE9
+	SetDialogFont(NULL, NULL, NULL);
 }
 
 // TTMACRO main engine
@@ -107,18 +105,6 @@
 
 // CCtrlApp theApp;
 
-static HWND CtrlWnd;
-
-HINSTANCE GetInstance()
-{
-	return hInst;
-}
-
-HWND GetHWND()
-{
-	return CtrlWnd;
-}
-
 /////////////////////////////////////////////////////////////////////////////
 
 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst,
@@ -125,7 +111,6 @@
                    LPSTR lpszCmdLine, int nCmdShow)
 {
 	hInst = hInstance;
-	static HMODULE HTTSET = NULL;
 	LONG lCount = 0;
 	DWORD SleepTick = 1;
 
@@ -140,9 +125,7 @@
 	Busy = TRUE;
 	pCCtrlWindow = new CCtrlWindow();
 	pCCtrlWindow->Create();
-//	pCCtrlWindow->ShowWindow(SW_SHOW);
-//	tmpWnd->ShowWindow(SW_SHOW);
-	Busy = FALSE;  
+	Busy = FALSE;
 
 	HWND hWnd = pCCtrlWindow->GetSafeHwnd();
 	CtrlWnd = hWnd;
@@ -150,18 +133,6 @@
 	//////////////////////////////////////////////////////////////////////
 	MSG msg;
 	while (GetMessage(&msg, NULL, 0, 0)) {
-#if 0
-		bool message_processed = false;
-		if (m_pMainWnd->m_hAccel != NULL) {
-			if (!MetaKey(ts.MetaKey)) {
-				// matakey\x82\xAA\x89\x9F\x82\xB3\x82\xEA\x82Ă\xA2\x82Ȃ\xA2
-				if (TranslateAccelerator(m_pMainWnd->m_hWnd , m_pMainWnd->m_hAccel, &msg)) {
-					// \x83A\x83N\x83Z\x83\x89\x83\x8C\x81[\x83^\x81[\x83L\x81[\x82\xF0\x8F\x88\x97\x9D\x82\xB5\x82\xBD
-					message_processed = true;
-				}
-			}
-		}
-#endif
 
 		if (IsDialogMessage(hWnd, &msg) != 0) {
 			/* \x8F\x88\x97\x9D\x82\xB3\x82ꂽ*/
@@ -169,12 +140,6 @@
 			TranslateMessage(&msg);
 			DispatchMessage(&msg);
 		}
-#if 0
-		if (!message_processed) {
-			TranslateMessage(&msg);
-			DispatchMessage(&msg);
-		}
-#endif
 
 		while (!PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE)) {
 			// \x83\x81\x83b\x83Z\x81[\x83W\x82\xAA\x82Ȃ\xA2
@@ -193,8 +158,6 @@
 		}
 	}
 
-	//////////////////////////////////////////////////////////////////////
-
 	// TODO \x82\xB7\x82łɕ‚\xB6\x82\xE7\x82\xEA\x82Ă\xA2\x82\xE9\x81A\x82\xB1\x82̏\x88\x97\x9D\x95s\x97v?
 	if (pCCtrlWindow) {
 		pCCtrlWindow->DestroyWindow();

Modified: trunk/teraterm/ttpmacro/ttmacro.h
===================================================================
--- trunk/teraterm/ttpmacro/ttmacro.h	2019-04-02 16:26:49 UTC (rev 7545)
+++ trunk/teraterm/ttpmacro/ttmacro.h	2019-04-02 16:27:06 UTC (rev 7546)
@@ -29,28 +29,5 @@
 
 /* TTMACRO.EXE, main */
 
-/////////////////////////////////////////////////////////////////////////////
-// CCtrlApp:
-
-#if 0
-class CCtrlApp : public CWinApp
-{
-public:
-	CCtrlApp();
-	BOOL Busy;
-
-	//{{AFX_VIRTUAL(CCtrlApp)
-	public:
-	virtual BOOL InitInstance();
-	virtual int ExitInstance();
-	virtual BOOL OnIdle(LONG lCount);
-	//}}AFX_VIRTUAL
-
-	//{{AFX_MSG(CCtrlApp)
-	//}}AFX_MSG
-	DECLARE_MESSAGE_MAP()
-};
-#endif
-
 HINSTANCE GetInstance();
 HWND GetHWND();

Modified: trunk/teraterm/ttpmacro/ttmdlg.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ttmdlg.cpp	2019-04-02 16:26:49 UTC (rev 7545)
+++ trunk/teraterm/ttpmacro/ttmdlg.cpp	2019-04-02 16:27:06 UTC (rev 7546)
@@ -46,6 +46,8 @@
 #include "statdlg.h"
 #include "ListDlg.h"
 #include "ttmlib.h"
+#include "ttmacro.h"
+
 #include "ttmdlg.h"
 
 #ifdef _DEBUG
@@ -57,9 +59,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];

Modified: trunk/teraterm/ttpmacro/ttmlib.c
===================================================================
--- trunk/teraterm/ttpmacro/ttmlib.c	2019-04-02 16:26:49 UTC (rev 7545)
+++ trunk/teraterm/ttpmacro/ttmlib.c	2019-04-02 16:27:06 UTC (rev 7546)
@@ -35,6 +35,7 @@
 #include <direct.h>
 #include <shlobj.h>
 
+#include "compat_win.h"
 #include "ttmlib.h"
 
 static char CurrentDir[MAXPATHLEN];
@@ -64,44 +65,62 @@
 	{ NULL,                -1}
 };
 
-void CalcTextExtent(HDC DC, const char *Text, LPSIZE s)
+/**
+ * \x95\xB6\x8E\x9A\x82\xF0\x95`\x89悵\x82\xBD\x8E\x9E\x82̃T\x83C\x83Y\x82\xF0\x8EZ\x8Fo\x82\xB7\x82\xE9
+ *	@param[in]	hWnd
+ *	@param[in]	Font	\x83t\x83H\x83\x93\x83g\x83n\x83\x93\x83h\x83\x8B
+ *						NULL\x82̎\x9E\x82\xCDhWnd\x82ɐݒ肳\x82\xEA\x82Ă\xA2\x82\xE9\x83t\x83H\x83\x93\x83g
+ *	@param[in]	Text	\x95`\x89悷\x82\xE9\x83e\x83L\x83X\x83g
+ *	@param[out]	size	\x95`\x89\xE6\x83T\x83C\x83Y(cx,cy)
+ */
+void CalcTextExtent(HWND hWnd, HFONT hFont, const char *Text, LPSIZE s)
 {
-  int W, H, i, i0;
-  char Temp[512];
-  DWORD dwExt;
+	HDC DC = GetDC(hWnd);
+	int W, H, i, i0;
+	char Temp[512];
+	DWORD dwExt;
+	HFONT prevFont;
+	if (hFont == NULL) {
+		hFont = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0);
+	}
+	prevFont = (HFONT)SelectObject(DC, hFont);
 
-  W = 0;
-  H = 0;
-  i = 0;
-  do {
-    i0 = i;
-    while ((Text[i]!=0) &&
-	   (Text[i]!=0x0d) &&
-	   (Text[i]!=0x0a))
-      i++;
-    memcpy(Temp,&Text[i0],i-i0);
-    Temp[i-i0] = 0;
-    if (Temp[0]==0)
-    {
-     Temp[0] = 0x20;
-     Temp[1] = 0;
-    }
-    dwExt = GetTabbedTextExtent(DC,Temp,strlen(Temp),0,NULL);
-    s->cx = LOWORD(dwExt);
-    s->cy = HIWORD(dwExt);
-    if (s->cx > W) W = s->cx;
-    H = H + s->cy;
-    if (Text[i]!=0)
-    {
-      i++;
-      if ((Text[i]==0x0a) &&
-	  (Text[i-1]==0x0d))
-	i++;
-    }
-  } while (Text[i]!=0);
-  if ((i-i0 == 0) && (H > s->cy)) H = H - s->cy;
-  s->cx = W;
-  s->cy = H;
+	W = 0;
+	H = 0;
+	i = 0;
+	do {
+		i0 = i;
+		while ((Text[i]!=0) &&
+			   (Text[i]!=0x0d) &&
+			   (Text[i]!=0x0a))
+			i++;
+		memcpy(Temp,&Text[i0],i-i0);
+		Temp[i-i0] = 0;
+		if (Temp[0]==0)
+		{
+			Temp[0] = 0x20;
+			Temp[1] = 0;
+		}
+		dwExt = GetTabbedTextExtent(DC,Temp,strlen(Temp),0,NULL);
+		s->cx = LOWORD(dwExt);
+		s->cy = HIWORD(dwExt);
+		if (s->cx > W) W = s->cx;
+		H = H + s->cy;
+		if (Text[i]!=0)
+		{
+			i++;
+			if ((Text[i]==0x0a) &&
+				(Text[i-1]==0x0d))
+				i++;
+		}
+	} while (Text[i]!=0);
+	if ((i-i0 == 0) && (H > s->cy)) H = H - s->cy;
+	s->cx = W;
+	s->cy = H;
+	if (prevFont != NULL) {
+		SelectObject(DC, prevFont);
+	}
+	ReleaseDC(hWnd, DC);
 }
 
 void TTMGetDir(PCHAR Dir, int destlen)
@@ -219,23 +238,6 @@
 	}
 }
 
-/**
- * \x95\xB6\x8E\x9A\x82\xF0\x95`\x89悵\x82\xBD\x8E\x9E\x82ǂ\xF1\x82Ȕ͈͂ɂȂ邩\x8Cv\x8EZ\x82\xB7\x82\xE9
- */
-void CalcTextExtent2(HWND hWnd, HFONT Font, const TCHAR *Text, LPSIZE textSize)
-{
-	HDC TmpDC = GetDC(hWnd);
-	HFONT prevFont = NULL;
-	if (Font) {
-		prevFont = (HFONT)SelectObject(TmpDC, Font);
-	}
-	CalcTextExtent(TmpDC, (PCHAR)Text, textSize);
-	if (Font && prevFont != NULL) {
-		SelectObject(TmpDC, prevFont);
-	}
-	ReleaseDC(hWnd, TmpDC);
-}
-
 int MessageBoxHaltScript(HWND hWnd)//, const char *UILanguageFile)
 {
 	char uimsg[MAX_UIMSG];

Modified: trunk/teraterm/ttpmacro/ttmlib.h
===================================================================
--- trunk/teraterm/ttpmacro/ttmlib.h	2019-04-02 16:26:49 UTC (rev 7545)
+++ trunk/teraterm/ttpmacro/ttmlib.h	2019-04-02 16:27:06 UTC (rev 7546)
@@ -29,6 +29,10 @@
 
 // TTMACRO.EXE, misc routines
 
+#pragma once
+
+#include <windows.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -35,8 +39,7 @@
 
 extern char UILanguageFile[MAX_PATH];
 
-void CalcTextExtent(HDC DC, const char *Text, LPSIZE s);
-void CalcTextExtent2(HWND hWnd, HFONT Font, const TCHAR *Text, LPSIZE textSize);	// TODO name
+void CalcTextExtent(HWND hWnd, HFONT Font, const char *Text, LPSIZE s);
 void TTMGetDir(PCHAR Dir, int destlen);
 void TTMSetDir(PCHAR Dir);
 int GetAbsPath(PCHAR FName, int destlen);

Modified: trunk/teraterm/ttpmacro/ttmmain.cpp
===================================================================
--- trunk/teraterm/ttpmacro/ttmmain.cpp	2019-04-02 16:26:49 UTC (rev 7545)
+++ trunk/teraterm/ttpmacro/ttmmain.cpp	2019-04-02 16:27:06 UTC (rev 7546)
@@ -32,6 +32,7 @@
 #include <windows.h>
 #include <commctrl.h>
 #include <stdio.h>
+
 #include "teraterm.h"
 #include "ttm_res.h"
 #include "ttmdlg.h"
@@ -38,20 +39,15 @@
 #include "ttl.h"
 #include "ttmparse.h"
 #include "ttmdde.h"
-
 #include "ttmmain.h"
 #include "ttmbuff.h"
 #include "ttmlib.h"
 #include "dlglib.h"
-
 #include "ttlib.h"
-
 #include "wait4all.h"
-
 #include "tmfc.h"
+#include "ttmacro.h"
 
-extern HINSTANCE GetInstance();
-
 static void ClientToScreen(HWND hWnd, RECT *rect)
 {
 	POINT pos;

Modified: trunk/teraterm/ttpmacro/ttmparse.c
===================================================================
--- trunk/teraterm/ttpmacro/ttmparse.c	2019-04-02 16:26:49 UTC (rev 7545)
+++ trunk/teraterm/ttpmacro/ttmparse.c	2019-04-02 16:27:06 UTC (rev 7546)
@@ -33,10 +33,17 @@
 #include <string.h>
 #include <stdio.h>
 #include <ctype.h>
+#include <crtdbg.h>
 #include "ttmdlg.h"
 #include "ttmparse.h"
 #include "ttmbuff.h"
 
+#ifdef _DEBUG
+#define calloc(c, s)  _calloc_dbg((c), (s), _NORMAL_BLOCK, __FILE__, __LINE__)
+#define malloc(l)     _malloc_dbg((l), _NORMAL_BLOCK, __FILE__, __LINE__)
+#define free(p)       _free_dbg((p), _NORMAL_BLOCK)
+#endif
+
 /* C\x8C\xBE\x8C\xEA\x83X\x83^\x83C\x83\x8B\x82̃R\x83\x81\x83\x93\x83g\x82\xF0\x83T\x83|\x81[\x83g\x82\xB7\x82邩\x82ǂ\xA4\x82\xA9 (2009.7.2 yutaka) */
 #define SUPPORT_C_STYLE_COMMENT
 static int commenting = 0;   /* C\x8C\xBE\x8C\xEA\x83R\x83\x81\x83\x93\x83g */


Ttssh2-commit メーリングリストの案内