[ttssh2-commit] [9351] MessageBox() を TTMessageBoxW() へ置き換え

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2021年 8月 10日 (火) 23:42:38 JST


Revision: 9351
          https://osdn.net/projects/ttssh2/scm/svn/commits/9351
Author:   zmatsuo
Date:     2021-08-10 23:42:38 +0900 (Tue, 10 Aug 2021)
Log Message:
-----------
MessageBox() を TTMessageBoxW() へ置き換え

Modified Paths:
--------------
    trunk/teraterm/teraterm/vtwin.cpp

-------------- next part --------------
Modified: trunk/teraterm/teraterm/vtwin.cpp
===================================================================
--- trunk/teraterm/teraterm/vtwin.cpp	2021-08-10 14:42:28 UTC (rev 9350)
+++ trunk/teraterm/teraterm/vtwin.cpp	2021-08-10 14:42:38 UTC (rev 9351)
@@ -1399,11 +1399,13 @@
 	if (cv.Ready && (cv.PortType==IdTCPIP) &&
 	    ((ts.PortFlag & PF_CONFIRMDISCONN) != 0) &&
 	    ! CloseTT) {
-		wchar_t uimsg[MAX_UIMSG];
-		get_lang_msgW("MSG_DISCONNECT_CONF", uimsg, _countof(uimsg),
-					  L"Disconnect?", ts.UILanguageFile);
-		int result = ::MessageBoxW(HVTWin, uimsg, L"Tera Term",
-								   MB_OKCANCEL | MB_ICONEXCLAMATION | MB_DEFBUTTON2);
+		static const TTMessageBoxInfoW info = {
+			"Tera Term",
+			NULL, L"Tera Term",
+			"MSG_DISCONNECT_CONF", L"Disconnect?",
+			MB_OKCANCEL | MB_ICONEXCLAMATION | MB_DEFBUTTON2
+		};
+		int result = TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW);
 		if (result == IDCANCEL) {
 			return;
 		}
@@ -1421,11 +1423,14 @@
 void CVTWindow::OnAllClose()
 {
 	// \x93ˑR\x8FI\x97\xB9\x82\xB3\x82\xB9\x82\xE9\x82Ɗ댯\x82Ȃ̂ŁA\x82\xA9\x82Ȃ炸\x83\x86\x81[\x83U\x82ɖ₢\x8D\x87\x82킹\x82\xF0\x8Fo\x82\xB7\x82悤\x82ɂ\xB7\x82\xE9\x81B
-	// (2013.8.17 yutaka)
-	wchar_t uimsg[MAX_UIMSG];
-
-	get_lang_msgW("MSG_ALL_TERMINATE_CONF", uimsg, _countof(uimsg), L"Terminate ALL Tera Term(s)?", ts.UILanguageFile);
-	if (::MessageBoxW(HVTWin, uimsg, L"Tera Term", MB_OKCANCEL | MB_ICONERROR | MB_DEFBUTTON2) == IDCANCEL)
+	static const TTMessageBoxInfoW info = {
+		"Tera Term",
+		NULL, L"Tera Term",
+		"MSG_ALL_TERMINATE_CONF", L"Terminate ALL Tera Term(s)?",
+		MB_OKCANCEL | MB_ICONERROR | MB_DEFBUTTON2
+	};
+	int result = TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW);
+	if (result == IDCANCEL)
 		return;
 
 	BroadcastClosingMessage(HVTWin);
@@ -3632,14 +3637,13 @@
 
 	if (CreateProcess(NULL, Command, NULL, NULL, FALSE, 0,
 	                  NULL, NULL, &si, &pi) == 0) {
-		wchar_t buf[80];
-		wchar_t uimsg[MAX_UIMSG];
-		wchar_t uimsg2[MAX_UIMSG];
-		get_lang_msgW("MSG_ERROR", uimsg, _countof(uimsg), L"ERROR", ts.UILanguageFile);
-		get_lang_msgW("MSG_EXEC_TT_ERROR", uimsg2, _countof(uimsg2),
-					  L"Can't execute Tera Term. (%d)", ts.UILanguageFile);
-		_snwprintf_s(buf, _countof(buf), _TRUNCATE, uimsg2, GetLastError());
-		::MessageBoxW(NULL, buf, uimsg, MB_OK | MB_ICONWARNING);
+		static const TTMessageBoxInfoW info = {
+			"Tera Term",
+			"MSG_ERROR", L"ERROR",
+			"MSG_EXEC_TT_ERROR", L"Can't execute Tera Term. (%d)",
+			MB_OK | MB_ICONWARNING
+		};
+		TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW, GetLastError());
 	} else {
 		CloseHandle(pi.hThread);
 		CloseHandle(pi.hProcess);
@@ -3672,8 +3676,6 @@
 	char cygterm[MAX_PATH];
 	STARTUPINFO si;
 	PROCESS_INFORMATION pi;
-	wchar_t uimsg[MAX_UIMSG];
-	wchar_t uimsg2[MAX_UIMSG];
 
 	if (strlen(ts.CygwinDirectory) > 0) {
 		if (SearchPath(ts.CygwinDirectory, "bin\\cygwin1", ".dll", sizeof(file), file, &filename) > 0) {
@@ -3693,10 +3695,15 @@
 		}
 	}
 
-	get_lang_msgW("MSG_ERROR", uimsg, _countof(uimsg), L"ERROR", ts.UILanguageFile);
-	get_lang_msgW("MSG_FIND_CYGTERM_DIR_ERROR", uimsg2, sizeof(uimsg2),
-				  L"Can't find Cygwin directory.", ts.UILanguageFile);
-	::MessageBoxW(NULL, uimsg2, uimsg, MB_OK | MB_ICONWARNING);
+	{
+		static const TTMessageBoxInfoW info = {
+			"Tera Term",
+			"MSG_ERROR", L"ERROR",
+			"MSG_FIND_CYGTERM_DIR_ERROR", L"Can't find Cygwin directory.",
+			MB_OK | MB_ICONWARNING
+		};
+		TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW);
+	}
 	return;
 
 found_dll:;
@@ -3705,10 +3712,13 @@
 	if (envptr != NULL) {
 		envbufflen = strlen(file) + strlen(envptr) + 7; // "PATH="(5) + ";"(1) + NUL(1)
 		if ((envbuff = (char *)malloc(envbufflen)) == NULL) {
-			get_lang_msgW("MSG_ERROR", uimsg, _countof(uimsg), L"ERROR", ts.UILanguageFile);
-			get_lang_msgW("MSG_CYGTERM_ENV_ALLOC_ERROR", uimsg2, _countof(uimsg2),
-						  L"Can't allocate memory for environment variable.", ts.UILanguageFile);
-			::MessageBoxW(NULL, uimsg2, uimsg, MB_OK | MB_ICONWARNING);
+			static const TTMessageBoxInfoW info = {
+				"Tera Term",
+				"MSG_ERROR", L"ERROR",
+				"MSG_CYGTERM_ENV_ALLOC_ERROR", L"Can't allocate memory for environment variable.",
+				MB_OK | MB_ICONWARNING
+			};
+			TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW);
 			free(envptr);
 			return;
 		}
@@ -3717,10 +3727,13 @@
 	} else {
 		envbufflen = strlen(file) + 6; // "PATH="(5) + NUL(1)
 		if ((envbuff = (char *)malloc(envbufflen)) == NULL) {
-			get_lang_msgW("MSG_ERROR", uimsg, _countof(uimsg), L"ERROR", ts.UILanguageFile);
-			get_lang_msgW("MSG_CYGTERM_ENV_ALLOC_ERROR", uimsg2, _countof(uimsg2),
-						  L"Can't allocate memory for environment variable.", ts.UILanguageFile);
-			::MessageBoxW(NULL, uimsg2, uimsg, MB_OK | MB_ICONWARNING);
+			static const TTMessageBoxInfoW info = {
+				"Tera Term",
+				"MSG_ERROR", L"ERROR",
+				"MSG_CYGTERM_ENV_ALLOC_ERROR", L"Can't allocate memory for environment variable.",
+				MB_OK | MB_ICONWARNING
+			};
+			TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW);
 			return;
 		}
 		_snprintf_s(envbuff, envbufflen, _TRUNCATE, "PATH=%s", file);
@@ -3742,10 +3755,13 @@
 
 	if (CreateProcess(NULL, cygterm, NULL, NULL, FALSE, 0,
 	                  NULL, NULL, &si, &pi) == 0) {
-		get_lang_msgW("MSG_ERROR", uimsg, _countof(uimsg), L"ERROR", ts.UILanguageFile);
-		get_lang_msgW("MSG_EXEC_CYGTERM_ERROR", uimsg2, _countof(uimsg2),
-		              L"Can't execute Cygterm.", ts.UILanguageFile);
-		::MessageBoxW(NULL, uimsg2, uimsg, MB_OK | MB_ICONWARNING);
+		static const TTMessageBoxInfoW info = {
+			"Tera Term",
+			"MSG_ERROR", L"ERROR",
+			"MSG_EXEC_CYGTERM_ERROR", L"Can't execute Cygterm.",
+			MB_OK | MB_ICONWARNING
+		};
+		TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW);
 	} else {
 		CloseHandle(pi.hThread);
 		CloseHandle(pi.hProcess);
@@ -3768,14 +3784,13 @@
 
 	if (CreateProcess(exename, NULL, NULL, NULL, FALSE, 0,
 	                  NULL, NULL, &si, &pi) == 0) {
-		wchar_t buf[80];
-		wchar_t uimsg[MAX_UIMSG];
-		wchar_t uimsg2[MAX_UIMSG];
-		get_lang_msgW("MSG_ERROR", uimsg, _countof(uimsg), L"ERROR", ts.UILanguageFile);
-		get_lang_msgW("MSG_EXEC_TTMENU_ERROR", uimsg2, _countof(uimsg2),
-					  L"Can't execute TeraTerm Menu. (%d)", ts.UILanguageFile);
-		_snwprintf_s(buf, _countof(buf), _TRUNCATE, uimsg2, GetLastError());
-		::MessageBoxW(NULL, buf, uimsg, MB_OK | MB_ICONWARNING);
+		static const TTMessageBoxInfoW info = {
+			"Tera Term",
+			"MSG_ERROR", L"ERROR",
+			"MSG_EXEC_TTMENU_ERROR", L"Can't execute TeraTerm Menu. (%d)",
+			MB_OK | MB_ICONWARNING
+		};
+		TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW, GetLastError());
 	} else {
 		CloseHandle(pi.hThread);
 		CloseHandle(pi.hProcess);
@@ -3801,14 +3816,13 @@
 
 	if (CreateProcess(NULL, LogMeTT, NULL, NULL, FALSE, 0,
 	                  NULL, NULL, &si, &pi) == 0) {
-		wchar_t buf[80];
-		wchar_t uimsg[MAX_UIMSG];
-		wchar_t uimsg2[MAX_UIMSG];
-		get_lang_msgW("MSG_ERROR", uimsg, _countof(uimsg), L"ERROR", ts.UILanguageFile);
-		get_lang_msgW("MSG_EXEC_LOGMETT_ERROR", uimsg2, _countof(uimsg2),
-					  L"Can't execute LogMeTT. (%d)", ts.UILanguageFile);
-		_snwprintf_s(buf, _countof(buf), _TRUNCATE, uimsg2, GetLastError());
-		::MessageBoxW(NULL, buf, uimsg, MB_OK | MB_ICONWARNING);
+		static const TTMessageBoxInfoW info = {
+			"Tera Term",
+			"MSG_ERROR", L"ERROR",
+			"MSG_EXEC_LOGMETT_ERROR", L"Can't execute LogMeTT. (%d)",
+			MB_OK | MB_ICONWARNING
+		};
+		TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW, GetLastError());
 	} else {
 		CloseHandle(pi.hThread);
 		CloseHandle(pi.hProcess);
@@ -3846,7 +3860,7 @@
 				NULL, L"Can not create a `%s' file.",
 				MB_OK | MB_ICONERROR
 			};
-			TTMessageBoxA(m_hWnd, &mbinfo, ts.UILanguageFile, filename);
+			TTMessageBoxW(m_hWnd, &mbinfo, ts.UILanguageFileW, filename);
 		}
 		free(info.filename);
 	}
@@ -3856,11 +3870,13 @@
 {
 	if (!FLogIsOpendText()) {
 		// \x91I\x91\xF0\x82ł\xAB\x82Ȃ\xA2\x82̂ŌĂ΂\xEA\x82Ȃ\xA2\x82͂\xB8
-		char uimsg[MAX_UIMSG];
-		get_lang_msg("MSG_ERROR", uimsg, sizeof(uimsg), "ERROR", ts.UILanguageFile);
-		get_lang_msg("MSG_COMMENT_LOG_OPEN_ERROR", ts.UIMsg, sizeof(ts.UIMsg),
-		             "It is not opened by the log file yet.", ts.UILanguageFile);
-		::MessageBox(NULL, ts.UIMsg, uimsg, MB_OK|MB_ICONEXCLAMATION);
+		static const TTMessageBoxInfoW info = {
+			"Tera Term",
+			"MSG_ERROR", L"ERROR",
+			"MSG_COMMENT_LOG_OPEN_ERROR", L"It is not opened by the log file yet.",
+			MB_OK | MB_ICONWARNING
+		};
+		TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW);
 		return;
 	}
 	FLogAddCommentDlg(m_hInst, HVTWin);
@@ -3898,7 +3914,7 @@
 			"MSG_VIEW_LOGFILE_ERROR", L"Can't view logging file. (%d)",
 			MB_OK | MB_ICONWARNING
 		};
-		TTMessageBoxA(m_hWnd, &mbinfo, ts.UILanguageFile, error);
+		TTMessageBoxW(m_hWnd, &mbinfo, ts.UILanguageFileW, error);
 	} else {
 		CloseHandle(pi.hThread);
 		CloseHandle(pi.hProcess);
@@ -3963,14 +3979,13 @@
 
 	if (CreateProcess(NULL, Command, NULL, NULL, FALSE, 0,
 	                  NULL, NULL, &si, &pi) == 0) {
-		wchar_t buf[80];
-		wchar_t uimsgW[MAX_UIMSG];
-		wchar_t uimsgW2[MAX_UIMSG];
-		get_lang_msgW("MSG_ERROR", uimsgW, _countof(uimsgW), L"ERROR", ts.UILanguageFile);
-		get_lang_msgW("MSG_EXEC_TT_ERROR", uimsgW2, _countof(uimsgW2),
-		              L"Can't execute Tera Term. (%d)", ts.UILanguageFile);
-		_snwprintf_s(buf, _countof(buf), _TRUNCATE, uimsgW2, GetLastError());
-		::MessageBoxW(NULL, buf, uimsgW, MB_OK | MB_ICONWARNING);
+		static const TTMessageBoxInfoW info = {
+			"Tera Term",
+			"MSG_ERROR", L"ERROR",
+			"MSG_EXEC_TT_ERROR", L"Can't execute Tera Term. (%d)",
+			MB_OK | MB_ICONWARNING
+		};
+		TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW, GetLastError());
 	} else {
 		CloseHandle(pi.hThread);
 		CloseHandle(pi.hProcess);
@@ -4108,11 +4123,14 @@
 	if ((cv.PortType==IdTCPIP) &&
 	    ((ts.PortFlag & PF_CONFIRMDISCONN) != 0) &&
 	    (confirm)) {
-		wchar_t uimsg[MAX_UIMSG];
-		get_lang_msgW("MSG_DISCONNECT_CONF", uimsg, _countof(uimsg),
-					  L"Disconnect?", ts.UILanguageFile);
-		if (::MessageBoxW(HVTWin, uimsg, L"Tera Term",
-						  MB_OKCANCEL | MB_ICONEXCLAMATION | MB_DEFBUTTON2)==IDCANCEL) {
+		static const TTMessageBoxInfoW info = {
+			"Tera Term",
+			NULL, L"Tera Term",
+			"MSG_DISCONNECT_CONF", L"Disconnect?",
+			MB_OKCANCEL | MB_ICONEXCLAMATION | MB_DEFBUTTON2
+		};
+		int result = TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW);
+		if (result == IDCANCEL) {
 			return;
 		}
 	}
@@ -4664,17 +4682,19 @@
 		return;
 	}
 
-	// \x8F\x91\x82\xAB\x8D\x9E\x82݂ł\xAB\x82邩\x82̔\xBB\x95ʂ\xF0\x92lj\xC1 (2005.11.3 yutaka)
-	if ((ret = _access(ts.SetupFName, 0x02)) != 0) {
-		if (errno != ENOENT) {  // \x83t\x83@\x83C\x83\x8B\x82\xAA\x82\xB7\x82łɑ\xB6\x8D݂\xB7\x82\xE9\x8Fꍇ\x82̂݃G\x83\x89\x81[\x82Ƃ\xB7\x82\xE9 (2005.12.13 yutaka)
-			wchar_t uimsg[MAX_UIMSG];
-			wchar_t uimsg2[MAX_UIMSG];
-			get_lang_msgW("MSG_TT_ERROR", uimsg, _countof(uimsg), L"Tera Term: ERROR", ts.UILanguageFile);
-			get_lang_msgW("MSG_SAVESETUP_PERMISSION_ERROR", uimsg2, _countof(uimsg2),
-						  L"TERATERM.INI file doesn't have the writable permission.", ts.UILanguageFile);
-			::MessageBoxW(HVTWin, uimsg2, uimsg, MB_OK|MB_ICONEXCLAMATION);
-			return;
-		}
+	// \x8F\x91\x82\xAB\x8D\x9E\x82݂ł\xAB\x82邩?
+	const DWORD attr = GetFileAttributesW(ts.SetupFNameW);
+	if ((attr & FILE_ATTRIBUTE_DIRECTORY ) == 0 && (attr & FILE_ATTRIBUTE_READONLY) != 0) {
+		// \x83t\x83H\x83\x8B\x83_\x82ł͂Ȃ\xAD\x81A\x93ǂݎ\xE6\x82\xE8\x90\xEA\x97p\x82\xBE\x82\xC1\x82\xBD\x8Fꍇ
+		static const TTMessageBoxInfoW info = {
+			"Tera Term",
+			"MSG_TT_ERROR", L"Tera Term: ERROR",
+			"MSG_SAVESETUP_PERMISSION_ERROR", L"TERATERM.INI file doesn't have the writable permission.",
+			MB_OK|MB_ICONEXCLAMATION
+		};
+		TTMessageBoxW(HVTWin, &info, ts.UILanguageFileW);
+		free(PrevSetupFNW);
+		return;
 	}
 
 	if (LoadTTSET())


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