• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythongamewindowsbathyscaphephpguic翻訳omegattwitterframeworktestbtronarduinovb.net計画中(planning stage)directxpreviewerゲームエンジンdom

Tera Termの個人的な作業用リポジトリ


Commit MetaInfo

修订版e3c9dfb37c2867c68f2837c062e3ba1cf4d6018e (tree)
时间2020-03-24 00:54:38
作者zmatsuo <zmatsuo@user...>
Commiterzmatsuo

Log Message

ファイルオープンダイアログ _GetOpenFileNameW() を layer_for_unicode に追加

- 次のAPIも追加

- _GetCurrentDirectoryW()
- _SetCurrentDirectoryW()

- get_OPENFILENAME_SIZEW() 追加

git-svn-id: svn+ssh://svn.osdn.net/svnroot/ttssh2/trunk@8617 f5f01b69-1e22-0410-acbf-894ab4bd6246

更改概述

差异

--- a/teraterm/common/compat_win.cpp
+++ b/teraterm/common/compat_win.cpp
@@ -42,8 +42,6 @@ ATOM (WINAPI *pRegisterClassW)(const WNDCLASSW *lpWndClass);
4242 HWND (WINAPI *pCreateWindowExW)(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight,
4343 HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);
4444 LRESULT (WINAPI *pDefWindowProcW)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
45-HPROPSHEETPAGE (WINAPI *pCreatePropertySheetPageW)(LPCPROPSHEETPAGEW constPropSheetPagePointer);
46-INT_PTR (WINAPI *pPropertySheetW)(LPCPROPSHEETHEADERW constPropSheetHeaderPointer);
4745 LRESULT (WINAPI *pSendMessageW)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
4846 LRESULT (WINAPI *pSendDlgItemMessageW)(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam);
4947 BOOL (WINAPI *pModifyMenuW)(HMENU hMnu, UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem, LPCWSTR lpNewItem);
@@ -69,6 +67,8 @@ LONG (WINAPI *pSetWindowLongW)(HWND hWnd, int nIndex, LONG dwNewLong);
6967 LONG_PTR (WINAPI *pSetWindowLongPtrW)(HWND hWnd, int nIndex, LONG_PTR dwNewLong);
7068 #endif
7169 LRESULT (WINAPI *pCallWindowProcW)(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
70+DWORD (WINAPI *pGetCurrentDirectoryW)(DWORD nBufferLength, LPWSTR lpBuffer);
71+BOOL (WINAPI *pSetCurrentDirectoryW)(LPCWSTR lpPathName);
7272
7373 // kernel32.dll
7474 DWORD (WINAPI *pGetFileAttributesW)(LPCWSTR lpFileName);
@@ -101,6 +101,13 @@ int (WINAPI *pGetWindowTextLengthW)(HWND hWnd);
101101 UINT (WINAPI *pDragQueryFileW)(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT cch);
102102 BOOL (WINAPI *pShell_NotifyIconW)(DWORD dwMessage, NOTIFYICONDATAW *lpData);
103103
104+// comctl32
105+HPROPSHEETPAGE (WINAPI *pCreatePropertySheetPageW)(LPCPROPSHEETPAGEW constPropSheetPagePointer);
106+INT_PTR (WINAPI *pPropertySheetW)(LPCPROPSHEETHEADERW constPropSheetHeaderPointer);
107+
108+// comdlg32
109+BOOL (WINAPI *pGetOpenFileNameW)(LPOPENFILENAMEW Arg1);
110+
104111 /**
105112 * GetConsoleWindow() と同じ動作をする
106113 * https://support.microsoft.com/ja-jp/help/124103/how-to-obtain-a-console-window-handle-hwnd
@@ -204,6 +211,8 @@ static const APIInfo Lists_kernel32[] = {
204211 { "GetFileAttributesW", (void **)&pGetFileAttributesW },
205212 { "GetPrivateProfileStringW", (void **)&pGetPrivateProfileStringW },
206213 { "OutputDebugStringW", (void **)&pOutputDebugStringW },
214+ { "GetCurrentDirectoryW", (void **)&pGetCurrentDirectoryW },
215+ { "SetCurrentDirectoryW", (void **)&pSetCurrentDirectoryW },
207216 #endif
208217 { "GetConsoleWindow", (void **)&pGetConsoleWindow },
209218 {},
@@ -233,6 +242,15 @@ static const APIInfo Lists_hhctrl[] = {
233242 {},
234243 };
235244
245+static const APIInfo Lists_comdlg32[] = {
246+#ifndef UNICODE_API_DISABLE
247+ { "GetOpenFileNameW", (void **)&pGetOpenFileNameW },
248+#endif
249+ {},
250+};
251+
252+
253+
236254 static const DllInfo DllInfos[] = {
237255 { _T("user32.dll"), DLL_LOAD_LIBRARY_SYSTEM, DLL_ACCEPT_NOT_EXIST, Lists_user32 },
238256 { _T("msimg32.dll"), DLL_LOAD_LIBRARY_SYSTEM, DLL_ACCEPT_NOT_EXIST, Lists_msimg32 },
@@ -242,6 +260,7 @@ static const DllInfo DllInfos[] = {
242260 { _T("shell32.dll"), DLL_LOAD_LIBRARY_SYSTEM, DLL_ACCEPT_NOT_EXIST, Lists_shell32 },
243261 { _T("Comctl32.dll"), DLL_LOAD_LIBRARY_SYSTEM, DLL_ACCEPT_NOT_EXIST, Lists_comctl32 },
244262 { _T("hhctrl.ocx"), DLL_LOAD_LIBRARY_SYSTEM, DLL_ACCEPT_NOT_EXIST, Lists_hhctrl },
263+ { _T("comdlg32.dll"), DLL_LOAD_LIBRARY_SYSTEM, DLL_ACCEPT_NOT_EXIST, Lists_comdlg32 },
245264 {},
246265 };
247266
@@ -273,6 +292,9 @@ void WinCompatInit()
273292 pGetFileAttributesW = NULL;
274293 pOutputDebugStringW = NULL;
275294 pDragQueryFileW = NULL;
295+ pGetCurrentDirectoryW = NULL;
296+ pSetCurrentDirectoryW = NULL;
297+ pGetOpenFileNameW = NULL;
276298 }
277299
278300 // GetConsoleWindow特別処理
--- a/teraterm/common/compat_win.h
+++ b/teraterm/common/compat_win.h
@@ -121,6 +121,9 @@ extern LONG_PTR (WINAPI *pSetWindowLongPtrW)(HWND hWnd, int nIndex, LONG_PTR dwN
121121 extern LRESULT (WINAPI *pCallWindowProcW)(WNDPROC lpPrevWndFunc,
122122 HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
123123 extern void (WINAPI *pOutputDebugStringW)(LPCWSTR lpOutputString);
124+extern DWORD (WINAPI *pGetCurrentDirectoryW)(DWORD nBufferLength, LPWSTR lpBuffer);
125+extern BOOL (WINAPI *pSetCurrentDirectoryW)(LPCWSTR lpPathName);
126+extern BOOL (WINAPI *pGetOpenFileNameW)(LPOPENFILENAMEW Arg1);
124127
125128 void WinCompatInit();
126129
--- a/teraterm/common/layer_for_unicode.cpp
+++ b/teraterm/common/layer_for_unicode.cpp
@@ -556,3 +556,28 @@ void _OutputDebugStringW(LPCWSTR lpOutputString)
556556 OutputDebugStringA(strA);
557557 free(strA);
558558 }
559+
560+DWORD _GetCurrentDirectoryW(DWORD nBufferLength, LPWSTR lpBuffer)
561+{
562+ if (pGetCurrentDirectoryW != NULL) {
563+ return pGetCurrentDirectoryW(nBufferLength, lpBuffer);
564+ }
565+ char dir[MAX_PATH];
566+ DWORD len = GetCurrentDirectoryA(_countof(dir), dir);
567+ wchar_t *strW = ToWcharA(dir);
568+ wcsncpy_s(lpBuffer, nBufferLength, strW, _TRUNCATE);
569+ free(strW);
570+ DWORD r = (DWORD)wcslen(lpBuffer);
571+ return r;
572+}
573+
574+BOOL _SetCurrentDirectoryW(LPCWSTR lpPathName)
575+{
576+ if (pSetCurrentDirectoryW != NULL) {
577+ return pSetCurrentDirectoryW(lpPathName);
578+ }
579+ char *strA = ToCharW(lpPathName);
580+ BOOL r = SetCurrentDirectoryA(strA);
581+ free(strA);
582+ return r;
583+}
--- a/teraterm/common/layer_for_unicode.h
+++ b/teraterm/common/layer_for_unicode.h
@@ -35,6 +35,7 @@
3535 #pragma once
3636
3737 #include <windows.h>
38+#include <commdlg.h> // for _GetOpenFileNameW()
3839
3940 #ifdef __cplusplus
4041 extern "C" {
@@ -112,6 +113,8 @@ LRESULT _CallWindowProcW(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wPar
112113
113114 // kernel32.dll
114115 DWORD _GetFileAttributesW(LPCWSTR lpFileName);
116+DWORD _GetCurrentDirectoryW(DWORD nBufferLength, LPWSTR lpBuffer);
117+BOOL _SetCurrentDirectoryW(LPCWSTR lpPathName);
115118 void _OutputDebugStringW(LPCWSTR lpOutputString);
116119
117120 // gdi32.lib
@@ -125,6 +128,9 @@ HPROPSHEETPAGE _CreatePropertySheetPageW(LPCPROPSHEETPAGEW_V1 constPropSheetPage
125128 INT_PTR _PropertySheetW(PROPSHEETHEADERW *constPropSheetHeaderPointer);
126129 //INT_PTR _PropertySheetW(PROPSHEETHEADERW_V1 *constPropSheetHeaderPointer);
127130
131+// Comdlg32.lib
132+BOOL _GetOpenFileNameW(LPOPENFILENAMEW Arg1);
133+
128134 // shell32.lib
129135 UINT _DragQueryFileW(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT cch);
130136 BOOL _Shell_NotifyIconW(DWORD dwMessage, TT_NOTIFYICONDATAW_V2 *lpData);
--- a/teraterm/common/layer_for_unicode_comctl32.cpp
+++ b/teraterm/common/layer_for_unicode_comctl32.cpp
@@ -95,3 +95,48 @@ INT_PTR _PropertySheetW(PROPSHEETHEADERW *psh)
9595 return retval;
9696 }
9797
98+static char *ConvertFilter(const wchar_t *filterW)
99+{
100+ if (filterW == NULL) {
101+ return NULL;
102+ }
103+ size_t len = 0;
104+ for(;;) {
105+ if (filterW[len] == 0 && filterW[len + 1] == 0) {
106+ len++;
107+ break;
108+ }
109+ len++;
110+ }
111+ len++;
112+ char *filterA = (char *)malloc(len);
113+ ::WideCharToMultiByte(CP_ACP, 0, filterW, (int)len, filterA, (int)len, NULL, NULL);
114+ return filterA;
115+}
116+
117+BOOL _GetOpenFileNameW(LPOPENFILENAMEW ofnW)
118+{
119+ if (pGetOpenFileNameW != NULL) {
120+ return pGetOpenFileNameW(ofnW);
121+ }
122+
123+ char fileA[MAX_PATH];
124+ WideCharToMultiByte(CP_ACP, 0, ofnW->lpstrFile, -1, fileA, _countof(fileA), NULL,NULL);
125+
126+ OPENFILENAMEA ofnA;
127+ memset(&ofnA, 0, sizeof(ofnA));
128+ ofnA.lStructSize = OPENFILENAME_SIZE_VERSION_400A;
129+ ofnA.hwndOwner = ofnW->hwndOwner;
130+ ofnA.lpstrFilter = ConvertFilter(ofnW->lpstrFilter);
131+ ofnA.lpstrFile = fileA;
132+ ofnA.nMaxFile = _countof(fileA);
133+ ofnA.lpstrTitle = ToCharW(ofnW->lpstrTitle);
134+ ofnA.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
135+ BOOL result = GetOpenFileNameA(&ofnA);
136+ if (result) {
137+ MultiByteToWideChar(CP_ACP, 0, fileA, _countof(fileA), ofnW->lpstrFile, ofnW->nMaxFile);
138+ }
139+ free((void *)ofnA.lpstrFilter);
140+ free((void *)ofnA.lpstrTitle);
141+ return result;
142+}
--- a/teraterm/common/ttlib.c
+++ b/teraterm/common/ttlib.c
@@ -1516,6 +1516,16 @@ DWORD get_OPENFILENAME_SIZE()
15161516 return OPENFILENAME_SIZE_VERSION_400A;
15171517 }
15181518
1519+// OPENFILENAMEW.lStructSize に代入する値
1520+DWORD get_OPENFILENAME_SIZEW()
1521+{
1522+ if (IsWindows2000OrLater()) {
1523+ return sizeof(OPENFILENAMEW);
1524+ }
1525+// return OPENFILENAME_SIZE_VERSION_400W;
1526+ return CDSIZEOF_STRUCT(OPENFILENAMEW,lpTemplateName);
1527+}
1528+
15191529 // convert table for KanjiCodeID and ListID
15201530 // cf. KanjiList,KanjiListSend
15211531 // KoreanList,KoreanListSend