[Ttssh2-commit] [8962] layer_for_unicode ファイル選択ダイアログでいくつかのメンバーの初期化を追加

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2020年 11月 1日 (日) 02:21:07 JST


Revision: 8962
          https://osdn.net/projects/ttssh2/scm/svn/commits/8962
Author:   zmatsuo
Date:     2020-11-01 02:21:06 +0900 (Sun, 01 Nov 2020)
Log Message:
-----------
layer_for_unicode ファイル選択ダイアログでいくつかのメンバーの初期化を追加

- _GetOpenFileNameW(), _GetSaveFileNameW()
- OPENFILENAMEW.Flags に OFN_ENABLETEMPLATE を指定されても動作するようになった
- lpstrFilter の文字列が崩れることがあったので修正

Modified Paths:
--------------
    trunk/teraterm/common/layer_for_unicode_comctl32.cpp

-------------- next part --------------
Modified: trunk/teraterm/common/layer_for_unicode_comctl32.cpp
===================================================================
--- trunk/teraterm/common/layer_for_unicode_comctl32.cpp	2020-10-31 17:20:54 UTC (rev 8961)
+++ trunk/teraterm/common/layer_for_unicode_comctl32.cpp	2020-10-31 17:21:06 UTC (rev 8962)
@@ -33,6 +33,7 @@
   */
 
 #include <windows.h>
+#include <assert.h>
 
 #include "codeconv.h"
 #include "compat_win.h"
@@ -100,17 +101,18 @@
 	if (filterW == NULL) {
 		return NULL;
 	}
-	size_t len = 0;
+	size_t lenW = 0;
 	for(;;) {
-		if (filterW[len] == 0 && filterW[len + 1] == 0) {
-			len++;
+		if (filterW[lenW] == 0 && filterW[lenW + 1] == 0) {
+			lenW++;
 			break;
 		}
-		len++;
+		lenW++;
 	}
-	len++;
-	char *filterA = (char *)malloc(len);
-	::WideCharToMultiByte(CP_ACP, 0, filterW, (int)len, filterA, (int)len, NULL, NULL);
+	lenW++;
+	size_t lenA = lenW * 2;		// x2\x82̌\xA9\x8D\x9E\x82\xDD
+	char *filterA = (char *)malloc(lenA);
+	::WideCharToMultiByte(CP_ACP, 0, filterW, (int)lenW, filterA, (int)lenA, NULL, NULL);
 	return filterA;
 }
 
@@ -124,14 +126,25 @@
 	ofnA.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
 	ofnA.hwndOwner = ofnW->hwndOwner;
 	ofnA.lpstrFilter = ConvertFilter(ofnW->lpstrFilter);
+	ofnA.nFilterIndex = ofnW->nFilterIndex;
 	ofnA.lpstrFile = fileA;
 	ofnA.nMaxFile = _countof(fileA);
 	ofnA.lpstrTitle = ToCharW(ofnW->lpstrTitle);
 	ofnA.Flags = ofnW->Flags;
+	ofnA.lCustData = ofnW->lCustData;
+	ofnA.lpfnHook = ofnW->lpfnHook;
+	ofnA.lpTemplateName = (LPCSTR)ofnW->lpTemplateName;
+	ofnA.hInstance = ofnW->hInstance;
 	BOOL result = fn(&ofnA);
 	if (result) {
 		MultiByteToWideChar(CP_ACP, 0, fileA, _countof(fileA), ofnW->lpstrFile, ofnW->nMaxFile);
 	}
+#if _DEBUG
+	else {
+		DWORD err = CommDlgExtendedError();
+		assert(err == 0);
+	}
+#endif
 	free((void *)ofnA.lpstrFilter);
 	free((void *)ofnA.lpstrTitle);
 	return result;


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