Revision: 9445 https://osdn.net/projects/ttssh2/scm/svn/commits/9445 Author: zmatsuo Date: 2021-09-23 20:25:18 +0900 (Thu, 23 Sep 2021) Log Message: ----------- doSelectFolderW() のフォルダ選択を IFileOpenDialog に切り替え - 従来は SHBrowseForFolderW() を使用していた - IFileOpenDialog は Vista以降 - Visual Studio 2010 以前のときは従来と同じ - IFileOpenDialog が SDK にないため Modified Paths: -------------- trunk/teraterm/common/ttlib_static_cpp.cpp -------------- next part -------------- Modified: trunk/teraterm/common/ttlib_static_cpp.cpp =================================================================== --- trunk/teraterm/common/ttlib_static_cpp.cpp 2021-09-23 11:25:03 UTC (rev 9444) +++ trunk/teraterm/common/ttlib_static_cpp.cpp 2021-09-23 11:25:18 UTC (rev 9445) @@ -1070,6 +1070,53 @@ return download; } +#if defined(__MINGW32__) || _MSC_VER >= 1600 // VS2010+ +static BOOL doSelectFolderWCOM(HWND hWnd, const wchar_t *def, const wchar_t *msg, wchar_t **folder) +{ + IFileOpenDialog *pDialog; + HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_IFileOpenDialog, (void **)&pDialog); + if (FAILED(hr)) { + *folder = NULL; + return FALSE; + } + + DWORD options; + pDialog->GetOptions(&options); + pDialog->SetOptions(options | FOS_PICKFOLDERS); + pDialog->SetTitle(msg); + { + IShellItem *psi; + hr = SHCreateItemFromParsingName(def, NULL, IID_IShellItem, (void **)&psi); + if (SUCCEEDED(hr)) { + hr = pDialog->SetFolder(psi); + psi->Release(); + } + } + hr = pDialog->Show(hWnd); + + BOOL result = FALSE; + if (SUCCEEDED(hr)) { + IShellItem *pItem; + hr = pDialog->GetResult(&pItem); + if (SUCCEEDED(hr)) { + PWSTR pPath; + hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pPath); + if (SUCCEEDED(hr)) { + *folder = wcsdup(pPath); + CoTaskMemFree(pPath); + result = TRUE; + } + } + } + + if (!result) { + // cancel(or some error) + *folder = NULL; + } + pDialog->Release(); + return result; +} +#else static int CALLBACK BrowseCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) { switch(uMsg) { @@ -1091,18 +1138,7 @@ return 0; } -/** - * \x83t\x83H\x83\x8B\x83_\x82\xF0\x91I\x91\xF0\x82\xB7\x82\xE9 - * SHBrowseForFolderW() \x82\xF0\x83R\x81[\x83\x8B\x82\xB7\x82\xE9 - * - * @param[in] def \x91I\x91\xF0\x83t\x83H\x83\x8B\x83_\x82̏\x89\x8A\xFA\x92l(\x93\xC1\x82Ɏw\x92肵\x82Ȃ\xA2\x82Ƃ\xAB\x82\xCD NULL or "") - * @param[out] **folder \x91I\x91\xF0\x82\xB5\x82\xBD\x83t\x83H\x83\x8B\x83_\x82̃t\x83\x8B\x83p\x83X(\x83L\x83\x83\x83\x93\x83Z\x83\x8B\x8E\x9E\x82̓Z\x83b\x83g\x82\xB3\x82\xEA\x82Ȃ\xA2) - * \x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82邱\x82\xC6(\x83L\x83\x83\x83\x93\x83Z\x83\x8B\x8E\x9E\x82\xCDfree()\x95s\x97v) - * @retval TRUE \x91I\x91\xF0\x82\xB5\x82\xBD - * @retval FALSE \x83L\x83\x83\x83\x93\x83Z\x83\x8B\x82\xB5\x82\xBD - * - */ -BOOL doSelectFolderW(HWND hWnd, const wchar_t *def, const wchar_t *msg, wchar_t **folder) +static BOOL doSelectFolderWAPI(HWND hWnd, const wchar_t *def, const wchar_t *msg, wchar_t **folder) { wchar_t buf[MAX_PATH]; BROWSEINFOW bi = {}; @@ -1128,7 +1164,29 @@ CoTaskMemFree(pidlBrowse); return TRUE; } +#endif +/** + * \x83t\x83H\x83\x8B\x83_\x82\xF0\x91I\x91\xF0\x82\xB7\x82\xE9 + * SHBrowseForFolderW() \x82\xF0\x83R\x81[\x83\x8B\x82\xB7\x82\xE9 + * + * @param[in] def \x91I\x91\xF0\x83t\x83H\x83\x8B\x83_\x82̏\x89\x8A\xFA\x92l(\x93\xC1\x82Ɏw\x92肵\x82Ȃ\xA2\x82Ƃ\xAB\x82\xCD NULL or "") + * @param[out] **folder \x91I\x91\xF0\x82\xB5\x82\xBD\x83t\x83H\x83\x8B\x83_\x82̃t\x83\x8B\x83p\x83X(\x83L\x83\x83\x83\x93\x83Z\x83\x8B\x8E\x9E\x82̓Z\x83b\x83g\x82\xB3\x82\xEA\x82Ȃ\xA2) + * \x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82邱\x82\xC6(\x83L\x83\x83\x83\x93\x83Z\x83\x8B\x8E\x9E\x82\xCDfree()\x95s\x97v) + * @retval TRUE \x91I\x91\xF0\x82\xB5\x82\xBD + * @retval FALSE \x83L\x83\x83\x83\x93\x83Z\x83\x8B\x82\xB5\x82\xBD + * + */ +BOOL doSelectFolderW(HWND hWnd, const wchar_t *def, const wchar_t *msg, wchar_t **folder) +{ + // TODO \x97\xBC\x97\xA7\x82\xB5\x82\xBD\x82\xA2 +#if defined(__MINGW32__) || _MSC_VER >= 1600 // VS2010+ + return doSelectFolderWCOM(hWnd, def, msg, folder); +#else + return doSelectFolderWAPI(hWnd, def, msg, folder); +#endif +} + /* fit a filename to the windows-filename format */ /* FileName must contain filename part only. */ void FitFileNameW(wchar_t *FileName, size_t destlen, const wchar_t *DefExt)