Revision: 8617 https://osdn.net/projects/ttssh2/scm/svn/commits/8617 Author: zmatsuo Date: 2020-03-24 00:54:38 +0900 (Tue, 24 Mar 2020) Log Message: ----------- ファイルオープンダイアログ _GetOpenFileNameW() を layer_for_unicode に追加 - 次のAPIも追加 - _GetCurrentDirectoryW() - _SetCurrentDirectoryW() - get_OPENFILENAME_SIZEW() 追加 Modified Paths: -------------- trunk/teraterm/common/compat_win.cpp trunk/teraterm/common/compat_win.h trunk/teraterm/common/layer_for_unicode.cpp trunk/teraterm/common/layer_for_unicode.h trunk/teraterm/common/layer_for_unicode_comctl32.cpp trunk/teraterm/common/ttlib.c -------------- next part -------------- Modified: trunk/teraterm/common/compat_win.cpp =================================================================== --- trunk/teraterm/common/compat_win.cpp 2020-03-23 15:54:26 UTC (rev 8616) +++ trunk/teraterm/common/compat_win.cpp 2020-03-23 15:54:38 UTC (rev 8617) @@ -42,8 +42,6 @@ HWND (WINAPI *pCreateWindowExW)(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam); LRESULT (WINAPI *pDefWindowProcW)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); -HPROPSHEETPAGE (WINAPI *pCreatePropertySheetPageW)(LPCPROPSHEETPAGEW constPropSheetPagePointer); -INT_PTR (WINAPI *pPropertySheetW)(LPCPROPSHEETHEADERW constPropSheetHeaderPointer); LRESULT (WINAPI *pSendMessageW)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); LRESULT (WINAPI *pSendDlgItemMessageW)(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam); BOOL (WINAPI *pModifyMenuW)(HMENU hMnu, UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem, LPCWSTR lpNewItem); @@ -69,6 +67,8 @@ LONG_PTR (WINAPI *pSetWindowLongPtrW)(HWND hWnd, int nIndex, LONG_PTR dwNewLong); #endif LRESULT (WINAPI *pCallWindowProcW)(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); +DWORD (WINAPI *pGetCurrentDirectoryW)(DWORD nBufferLength, LPWSTR lpBuffer); +BOOL (WINAPI *pSetCurrentDirectoryW)(LPCWSTR lpPathName); // kernel32.dll DWORD (WINAPI *pGetFileAttributesW)(LPCWSTR lpFileName); @@ -101,6 +101,13 @@ UINT (WINAPI *pDragQueryFileW)(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT cch); BOOL (WINAPI *pShell_NotifyIconW)(DWORD dwMessage, NOTIFYICONDATAW *lpData); +// comctl32 +HPROPSHEETPAGE (WINAPI *pCreatePropertySheetPageW)(LPCPROPSHEETPAGEW constPropSheetPagePointer); +INT_PTR (WINAPI *pPropertySheetW)(LPCPROPSHEETHEADERW constPropSheetHeaderPointer); + +// comdlg32 +BOOL (WINAPI *pGetOpenFileNameW)(LPOPENFILENAMEW Arg1); + /** * GetConsoleWindow() \x82Ɠ\xAF\x82\xB6\x93\xAE\x8D\xEC\x82\xF0\x82\xB7\x82\xE9 * https://support.microsoft.com/ja-jp/help/124103/how-to-obtain-a-console-window-handle-hwnd @@ -204,6 +211,8 @@ { "GetFileAttributesW", (void **)&pGetFileAttributesW }, { "GetPrivateProfileStringW", (void **)&pGetPrivateProfileStringW }, { "OutputDebugStringW", (void **)&pOutputDebugStringW }, + { "GetCurrentDirectoryW", (void **)&pGetCurrentDirectoryW }, + { "SetCurrentDirectoryW", (void **)&pSetCurrentDirectoryW }, #endif { "GetConsoleWindow", (void **)&pGetConsoleWindow }, {}, @@ -233,6 +242,15 @@ {}, }; +static const APIInfo Lists_comdlg32[] = { +#ifndef UNICODE_API_DISABLE + { "GetOpenFileNameW", (void **)&pGetOpenFileNameW }, +#endif + {}, +}; + + + static const DllInfo DllInfos[] = { { _T("user32.dll"), DLL_LOAD_LIBRARY_SYSTEM, DLL_ACCEPT_NOT_EXIST, Lists_user32 }, { _T("msimg32.dll"), DLL_LOAD_LIBRARY_SYSTEM, DLL_ACCEPT_NOT_EXIST, Lists_msimg32 }, @@ -242,6 +260,7 @@ { _T("shell32.dll"), DLL_LOAD_LIBRARY_SYSTEM, DLL_ACCEPT_NOT_EXIST, Lists_shell32 }, { _T("Comctl32.dll"), DLL_LOAD_LIBRARY_SYSTEM, DLL_ACCEPT_NOT_EXIST, Lists_comctl32 }, { _T("hhctrl.ocx"), DLL_LOAD_LIBRARY_SYSTEM, DLL_ACCEPT_NOT_EXIST, Lists_hhctrl }, + { _T("comdlg32.dll"), DLL_LOAD_LIBRARY_SYSTEM, DLL_ACCEPT_NOT_EXIST, Lists_comdlg32 }, {}, }; @@ -273,6 +292,9 @@ pGetFileAttributesW = NULL; pOutputDebugStringW = NULL; pDragQueryFileW = NULL; + pGetCurrentDirectoryW = NULL; + pSetCurrentDirectoryW = NULL; + pGetOpenFileNameW = NULL; } // GetConsoleWindow\x93\xC1\x95ʏ\x88\x97\x9D Modified: trunk/teraterm/common/compat_win.h =================================================================== --- trunk/teraterm/common/compat_win.h 2020-03-23 15:54:26 UTC (rev 8616) +++ trunk/teraterm/common/compat_win.h 2020-03-23 15:54:38 UTC (rev 8617) @@ -121,6 +121,9 @@ extern LRESULT (WINAPI *pCallWindowProcW)(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); extern void (WINAPI *pOutputDebugStringW)(LPCWSTR lpOutputString); +extern DWORD (WINAPI *pGetCurrentDirectoryW)(DWORD nBufferLength, LPWSTR lpBuffer); +extern BOOL (WINAPI *pSetCurrentDirectoryW)(LPCWSTR lpPathName); +extern BOOL (WINAPI *pGetOpenFileNameW)(LPOPENFILENAMEW Arg1); void WinCompatInit(); Modified: trunk/teraterm/common/layer_for_unicode.cpp =================================================================== --- trunk/teraterm/common/layer_for_unicode.cpp 2020-03-23 15:54:26 UTC (rev 8616) +++ trunk/teraterm/common/layer_for_unicode.cpp 2020-03-23 15:54:38 UTC (rev 8617) @@ -556,3 +556,28 @@ OutputDebugStringA(strA); free(strA); } + +DWORD _GetCurrentDirectoryW(DWORD nBufferLength, LPWSTR lpBuffer) +{ + if (pGetCurrentDirectoryW != NULL) { + return pGetCurrentDirectoryW(nBufferLength, lpBuffer); + } + char dir[MAX_PATH]; + DWORD len = GetCurrentDirectoryA(_countof(dir), dir); + wchar_t *strW = ToWcharA(dir); + wcsncpy_s(lpBuffer, nBufferLength, strW, _TRUNCATE); + free(strW); + DWORD r = (DWORD)wcslen(lpBuffer); + return r; +} + +BOOL _SetCurrentDirectoryW(LPCWSTR lpPathName) +{ + if (pSetCurrentDirectoryW != NULL) { + return pSetCurrentDirectoryW(lpPathName); + } + char *strA = ToCharW(lpPathName); + BOOL r = SetCurrentDirectoryA(strA); + free(strA); + return r; +} Modified: trunk/teraterm/common/layer_for_unicode.h =================================================================== --- trunk/teraterm/common/layer_for_unicode.h 2020-03-23 15:54:26 UTC (rev 8616) +++ trunk/teraterm/common/layer_for_unicode.h 2020-03-23 15:54:38 UTC (rev 8617) @@ -35,6 +35,7 @@ #pragma once #include <windows.h> +#include <commdlg.h> // for _GetOpenFileNameW() #ifdef __cplusplus extern "C" { @@ -112,6 +113,8 @@ // kernel32.dll DWORD _GetFileAttributesW(LPCWSTR lpFileName); +DWORD _GetCurrentDirectoryW(DWORD nBufferLength, LPWSTR lpBuffer); +BOOL _SetCurrentDirectoryW(LPCWSTR lpPathName); void _OutputDebugStringW(LPCWSTR lpOutputString); // gdi32.lib @@ -125,6 +128,9 @@ INT_PTR _PropertySheetW(PROPSHEETHEADERW *constPropSheetHeaderPointer); //INT_PTR _PropertySheetW(PROPSHEETHEADERW_V1 *constPropSheetHeaderPointer); +// Comdlg32.lib +BOOL _GetOpenFileNameW(LPOPENFILENAMEW Arg1); + // shell32.lib UINT _DragQueryFileW(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT cch); BOOL _Shell_NotifyIconW(DWORD dwMessage, TT_NOTIFYICONDATAW_V2 *lpData); Modified: trunk/teraterm/common/layer_for_unicode_comctl32.cpp =================================================================== --- trunk/teraterm/common/layer_for_unicode_comctl32.cpp 2020-03-23 15:54:26 UTC (rev 8616) +++ trunk/teraterm/common/layer_for_unicode_comctl32.cpp 2020-03-23 15:54:38 UTC (rev 8617) @@ -95,3 +95,48 @@ return retval; } +static char *ConvertFilter(const wchar_t *filterW) +{ + if (filterW == NULL) { + return NULL; + } + size_t len = 0; + for(;;) { + if (filterW[len] == 0 && filterW[len + 1] == 0) { + len++; + break; + } + len++; + } + len++; + char *filterA = (char *)malloc(len); + ::WideCharToMultiByte(CP_ACP, 0, filterW, (int)len, filterA, (int)len, NULL, NULL); + return filterA; +} + +BOOL _GetOpenFileNameW(LPOPENFILENAMEW ofnW) +{ + if (pGetOpenFileNameW != NULL) { + return pGetOpenFileNameW(ofnW); + } + + char fileA[MAX_PATH]; + WideCharToMultiByte(CP_ACP, 0, ofnW->lpstrFile, -1, fileA, _countof(fileA), NULL,NULL); + + OPENFILENAMEA ofnA; + memset(&ofnA, 0, sizeof(ofnA)); + ofnA.lStructSize = OPENFILENAME_SIZE_VERSION_400A; + ofnA.hwndOwner = ofnW->hwndOwner; + ofnA.lpstrFilter = ConvertFilter(ofnW->lpstrFilter); + ofnA.lpstrFile = fileA; + ofnA.nMaxFile = _countof(fileA); + ofnA.lpstrTitle = ToCharW(ofnW->lpstrTitle); + ofnA.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; + BOOL result = GetOpenFileNameA(&ofnA); + if (result) { + MultiByteToWideChar(CP_ACP, 0, fileA, _countof(fileA), ofnW->lpstrFile, ofnW->nMaxFile); + } + free((void *)ofnA.lpstrFilter); + free((void *)ofnA.lpstrTitle); + return result; +} Modified: trunk/teraterm/common/ttlib.c =================================================================== --- trunk/teraterm/common/ttlib.c 2020-03-23 15:54:26 UTC (rev 8616) +++ trunk/teraterm/common/ttlib.c 2020-03-23 15:54:38 UTC (rev 8617) @@ -1516,6 +1516,16 @@ return OPENFILENAME_SIZE_VERSION_400A; } +// OPENFILENAMEW.lStructSize \x82ɑ\xE3\x93\xFC\x82\xB7\x82\xE9\x92l +DWORD get_OPENFILENAME_SIZEW() +{ + if (IsWindows2000OrLater()) { + return sizeof(OPENFILENAMEW); + } +// return OPENFILENAME_SIZE_VERSION_400W; + return CDSIZEOF_STRUCT(OPENFILENAMEW,lpTemplateName); +} + // convert table for KanjiCodeID and ListID // cf. KanjiList,KanjiListSend // KoreanList,KoreanListSend