[ttssh2-commit] [10403] コモンダイアログ用APIを追加、ファイル ttcommdlg.cpp,h を追加

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2022年 12月 11日 (日) 21:08:07 JST


Revision: 10403
          https://osdn.net/projects/ttssh2/scm/svn/commits/10403
Author:   zmatsuo
Date:     2022-12-11 21:08:07 +0900 (Sun, 11 Dec 2022)
Log Message:
-----------
コモンダイアログ用APIを追加、ファイル ttcommdlg.cpp,h を追加

- 次のAPIを追加
- TTGetOpenFileNameW()
- TTGetSaveFileNameW()
- TTSHBrowseForFolderW()
- APIはMAX_PATH文字長以上のファイル名を扱えるようにした
- TODO
  - TTGetOpenFileNameW(), TTGetSaveFileNameW() の内部を修正
  - IFileOpenDialog を使用する

Modified Paths:
--------------
    trunk/teraterm/common/CMakeLists.txt
    trunk/teraterm/common/common_static.v16.vcxproj
    trunk/teraterm/common/common_static.v8.vcproj
    trunk/teraterm/common/ttlib.c
    trunk/teraterm/common/ttlib.h
    trunk/teraterm/common/ttlib_static_cpp.cpp
    trunk/teraterm/keycode/keycode.v8.vcproj
    trunk/teraterm/ttpcmn/ttpcmn.v8.vcproj
    trunk/teraterm/ttpmacro/ttpmacro.v8.vcproj
    trunk/teraterm/ttptek/ttptek.v8.vcproj

Added Paths:
-----------
    trunk/teraterm/common/ttcommdlg.cpp
    trunk/teraterm/common/ttcommdlg.h

-------------- next part --------------
Modified: trunk/teraterm/common/CMakeLists.txt
===================================================================
--- trunk/teraterm/common/CMakeLists.txt	2022-12-11 12:07:56 UTC (rev 10402)
+++ trunk/teraterm/common/CMakeLists.txt	2022-12-11 12:08:07 UTC (rev 10403)
@@ -37,6 +37,8 @@
   tmfc_propdlg.cpp
   tmfc_propdlg.h
   tmfc_property.cpp
+  ttcommdlg.cpp
+  ttcommdlg.h
   ttgdiplus.cpp
   ttgdiplus.h
   ttknownfolders.c

Modified: trunk/teraterm/common/common_static.v16.vcxproj
===================================================================
--- trunk/teraterm/common/common_static.v16.vcxproj	2022-12-11 12:07:56 UTC (rev 10402)
+++ trunk/teraterm/common/common_static.v16.vcxproj	2022-12-11 12:08:07 UTC (rev 10403)
@@ -149,6 +149,7 @@
     <ClCompile Include="dllutil.cpp" />
     <ClCompile Include="getcontent.cpp" />
     <ClCompile Include="i18n_static.c" />
+    <ClCompile Include="ttcommdlg.cpp" />
     <ClCompile Include="ttgdiplus.cpp" />
     <ClCompile Include="ttknownfolders.c" />
     <ClCompile Include="ttlib_charset.cpp" />
@@ -172,6 +173,7 @@
     <ClInclude Include="codeconv.h" />
     <ClInclude Include="getcontent.h" />
     <ClInclude Include="tmfc_propdlg.h" />
+    <ClInclude Include="ttcommon.h" />
     <ClInclude Include="ttgdiplus.h" />
     <ClInclude Include="ttknownfolders.h" />
     <ClInclude Include="ttlib.h" />

Modified: trunk/teraterm/common/common_static.v8.vcproj
===================================================================
--- trunk/teraterm/common/common_static.v8.vcproj	2022-12-11 12:07:56 UTC (rev 10402)
+++ trunk/teraterm/common/common_static.v8.vcproj	2022-12-11 12:08:07 UTC (rev 10403)
@@ -297,6 +297,14 @@
 			>
 		</File>
 		<File
+			RelativePath=".\ttcommdlg.cpp"
+			>
+		</File>
+		<File
+			RelativePath=".\ttcommdlg.h"
+			>
+		</File>
+		<File
 			RelativePath=".\ttgdiplus.cpp"
 			>
 		</File>

Added: trunk/teraterm/common/ttcommdlg.cpp
===================================================================
--- trunk/teraterm/common/ttcommdlg.cpp	                        (rev 0)
+++ trunk/teraterm/common/ttcommdlg.cpp	2022-12-11 12:08:07 UTC (rev 10403)
@@ -0,0 +1,290 @@
+/*
+ * Copyright (C) 2008- TeraTerm Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define _CRTDBG_MAP_ALLOC
+#include <stdlib.h>
+#include <crtdbg.h>
+#include <windows.h>
+#include <shlobj.h>
+#include <assert.h>
+
+#include "win32helper.h"
+#include "ttlib.h"
+
+#include "ttcommdlg.h"
+
+static int CALLBACK BrowseCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
+{
+	switch(uMsg) {
+	case BFFM_INITIALIZED: {
+		// \x8F\x89\x8A\x{227B39E}
+		const wchar_t *folder = (wchar_t *)lpData;
+		if (folder != NULL && folder[0] != 0) {
+			// \x83t\x83H\x83\x8B\x83_\x82\xF0\x91I\x91\xF0\x8F\xF3\x91Ԃɂ\xB7\x82\xE9
+			//		\x83t\x83H\x83\x8B\x83_\x82\xAA\x91\xB6\x8D݂\xB5\x82Ȃ\xA2\x82Ƃ\xAB\x82\xCD 0 \x82\xAA\x95Ԃ\xC1\x82Ă\xAD\x82\xE9
+			SendMessageW(hwnd, BFFM_SETSELECTIONW, (WPARAM)TRUE, (LPARAM)folder);
+		}
+		break;
+	}
+	default:
+		break;
+	}
+	return 0;
+}
+
+/**
+ *	API\x94\xC5,\x8CÂ\xA2
+ */
+static BOOL TTSHBrowseForFolderWAPI(TTBROWSEINFOW *bi, const wchar_t *def, wchar_t **folder)
+{
+	wchar_t buf[MAX_PATH];	// PIDL\x8C`\x8E\xAE\x82Ŏ󂯎\xE6\x82\xE9\x82̂Ń_\x83~\x81[,\x88ꉞMAX_PATH\x92\xB7\x82Ŏ󂯂\xE9
+	BROWSEINFOW b = {};
+	b.hwndOwner = bi->hwndOwner;
+	b.pidlRoot = 0;	// 0 = from desktop
+	b.pszDisplayName = buf;
+	b.lpszTitle = bi->lpszTitle;
+	b.ulFlags = bi->ulFlags;
+	if (def != NULL && def[0] != 0) {
+		if (GetFileAttributesW(def) == INVALID_FILE_ATTRIBUTES) {
+			MessageBoxA(bi->hwndOwner, "Not found folder", "Tera Term", MB_OK | MB_ICONERROR);
+		}
+		else {
+			b.lpfn = BrowseCallback;
+			b.lParam = (LPARAM)def;
+		}
+	}
+	LPITEMIDLIST pidl = SHBrowseForFolderW(&b);
+	if (pidl == NULL) {
+		*folder = NULL;
+		return FALSE;
+	}
+
+	// PIDL\x8C`\x8E\xAE\x82̖߂\xE8\x92l\x82̃t\x83@\x83C\x83\x8B\x83V\x83X\x83e\x83\x80\x82̃p\x83X\x82ɕϊ\xB7
+#if _MSC_VER > 1400
+	// VS2005\x82Ŏg\x82\xA6\x82\xE9SDK\x82ɂ\xCDSHGetPathFromIDListEx()\x82\xAA\x93\xFC\x82\xC1\x82Ă\xA2\x82Ȃ\xA2
+	if (true) {
+		size_t len = MAX_PATH / 2;
+		wchar_t *path = NULL;
+		do {
+			wchar_t *p;
+			len *= 2;
+			if (len >= SHRT_MAX) {
+				free(path);
+				return FALSE;
+			}
+			p = (wchar_t *)realloc(path, len);
+			if (p == NULL) {
+				free(path);
+				return FALSE;
+			}
+			path = p;
+		} while (!SHGetPathFromIDListEx(pidl, path, (DWORD)len, GPFIDL_DEFAULT));
+		*folder = path;
+	}
+	else
+#endif
+	{
+		wchar_t buf[MAX_PATH];
+		if (!SHGetPathFromIDListW(pidl, buf)) {
+			return FALSE;
+		}
+		*folder = _wcsdup(buf);
+	}
+	CoTaskMemFree(pidl);
+	return TRUE;
+}
+
+/**
+ *	SHBrowseForFolderW() \x82قڌ݊\xB7\x8A֐\x94
+ *
+ *	@param	TTBROWSEINFOW
+ *		- BROWSEINFOW \x82̑\xE3\x82\xED\x82\xE8\x82\xC9 TTBROWSEINFOW \x82\xF0\x8Eg\x82\xA4
+ *		- \x8E\x9F\x82̃\x81\x83\x93\x83o\x82\xAA\x82Ȃ\xA2
+ *  	  - BROWSEINFOW.lpfn
+ *		  - BROWSEINFOW.lParam
+ *		  - BROWSEINFOW.iImage
+ *		- folder \x88\xF8\x90\x94\x82ɑI\x91\xF0\x83t\x83H\x83\x8B\x83_\x82\xAA\x93\xFC\x82\xE9
+ *	@param	def		\x83f\x83t\x83H\x83\x8B\x83g\x83t\x83H\x83\x8B\x83_
+ *					\x8Ew\x92肵\x82Ȃ\xA2\x82Ƃ\xAB\x82\xCDNULL
+ *	@param	folder	\x8Ew\x92肳\x82ꂽ\x83t\x83H\x83\x8B\x83_
+ *					\x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82邱\x82\xC6
+ *					MAX_PATH\x8F\xE3\x8C\xC0\x82Ȃ\xB5
+ */
+BOOL TTSHBrowseForFolderW(TTBROWSEINFOW *bi, const wchar_t *def, wchar_t **folder)
+{
+#if _MSC_VER == 1400 // VS2005\x82̏ꍇ
+	// 2005\x82Ŏg\x82\xA6\x82\xE9SDK\x82ɂ\xCDIFileOpenDialog\x82\xAA\x82Ȃ\xA2
+	return TTSHBrowseForFolderWAPI(bi, def, folder);
+#else
+	IFileOpenDialog *pDialog;
+	HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_IFileOpenDialog, (void **)&pDialog);
+	if (FAILED(hr)) {
+		// IFileOpenDialog \x82\xAA\x8Eg\x82\xA6\x82Ȃ\xA2OS, Vista\x88ȑO
+		return TTSHBrowseForFolderWAPI(bi, def, folder);
+	}
+
+	DWORD options;
+	pDialog->GetOptions(&options);
+	pDialog->SetOptions(options | FOS_PICKFOLDERS);
+	pDialog->SetTitle(bi->lpszTitle);
+	{
+		IShellItem *psi;
+		hr = SHCreateItemFromParsingName(def, NULL, IID_IShellItem, (void **)&psi);
+		if (SUCCEEDED(hr)) {
+			hr = pDialog->SetFolder(psi);
+			psi->Release();
+		}
+	}
+	hr = pDialog->Show(bi->hwndOwner);
+
+	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;
+#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)
+{
+	TTBROWSEINFOW bi = {};
+	bi.hwndOwner = hWnd;
+	bi.lpszTitle = msg;
+	bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_EDITBOX | BIF_NEWDIALOGSTYLE;
+
+	return TTSHBrowseForFolderW(&bi, def, folder);
+}
+
+static BOOL GetOpenSaveFileNameW(const TTOPENFILENAMEW *ofn, bool save, wchar_t **filename)
+{
+	// GetSaveFileNameW(), GetOpenFileNameW() \x82\xAA\x83J\x83\x8C\x83\x93\x83g\x83t\x83H\x83\x8B\x83_\x82\xF0\x95ύX\x82\xB5\x82Ă\xB5\x82܂\xA4\x82\xBD\x82\xDF
+	wchar_t *curdir;
+	hGetCurrentDirectoryW(&curdir);
+
+	// \x8F\x89\x8A\xFA\x83t\x83H\x83\x8B\x83_
+	wchar_t *init_dir = NULL;
+	if (ofn->lpstrFile != NULL) {
+		// \x8F\x89\x8A\xFA\x83t\x83@\x83C\x83\x8B\x8Ew\x92肠\x82\xE8
+		if (!IsRelativePathW(ofn->lpstrFile)) {
+			// \x8F\x89\x8A\xFA\x83t\x83@\x83C\x83\x8B\x82\xAA\x90\xE2\x91΃p\x83X\x82Ȃ\xE7\x83p\x83X\x82\xF0\x8E\xE6\x82\xE8\x8Fo\x82\xB5\x82ď\x89\x8A\xFA\x83t\x83H\x83\x8B\x83_\x82ɂ\xB7\x82\xE9
+			init_dir = _wcsdup(ofn->lpstrFile);
+			wchar_t *p = wcsrchr(init_dir, L'\\');
+			if (p != NULL) {
+				*p = L'\0';
+			}
+		}
+	}
+	else {
+		if (ofn->lpstrInitialDir != NULL) {
+			// \x8F\x89\x8A\xFA\x83t\x83H\x83\x8B\x83_\x8Ew\x92肠\x82\xE8
+			init_dir = _wcsdup(ofn->lpstrInitialDir);
+		}
+	}
+
+	wchar_t File[MAX_PATH];
+	if (GetFileAttributesW(ofn->lpstrFile) != INVALID_FILE_ATTRIBUTES) {
+		wcsncpy_s(File, _countof(File), ofn->lpstrFile, _TRUNCATE);
+	}
+	else {
+		File[0] = 0;
+	}
+
+	OPENFILENAMEW o = {};
+	o.lStructSize = get_OPENFILENAME_SIZEW();
+	o.hwndOwner = ofn->hwndOwner;
+	o.lpstrFilter = ofn->lpstrFilter;
+	o.lpstrFile = File;
+	o.nMaxFile = _countof(File);
+	o.lpstrTitle = ofn->lpstrTitle;
+	o.lpstrInitialDir = init_dir;
+	o.Flags = ofn->Flags;
+	BOOL ok = save ? GetSaveFileNameW(&o) : GetOpenFileNameW(&o);
+#if defined(_DEBUG)
+	if (!ok) {
+		DWORD Err = GetLastError();
+		DWORD DlgErr = CommDlgExtendedError();
+		assert(Err == 0 && DlgErr == 0);
+	}
+#endif
+	*filename = ok ? _wcsdup(File) : NULL;
+
+	free(init_dir);
+	SetCurrentDirectoryW(curdir);
+	free(curdir);
+
+	return ok;
+}
+
+/**
+ *	GetOpenFileNameW() \x8C݊\xB7\x8A֐\x94
+ *	\x88قȂ\xE9\x93_
+ *		- \x83t\x83H\x83\x8B\x83_\x82\xAA\x95ύX\x82\xB3\x82\xEA\x82Ȃ\xA2
+ *		- \x8F\x89\x8A\xFA\x83t\x83H\x83\x8B\x83_\x90ݒ\xE8
+ *			- \x8F\x89\x8A\xFA\x83t\x83@\x83C\x83\x8B\x82̃t\x83\x8B\x83p\x83X\x82\xF0\x8F\x89\x8A\xFA\x83t\x83H\x83\x8B\x83_\x82ɂ\xB7\x82\xE9
+ *
+ *	@param	filename	\x91I\x91\xF0\x82\xB3\x82ꂽ\x83t\x83@\x83C\x83\x8B\x96\xBC(\x96߂\xE8\x92l\x82\xAA TRUE\x82̎\x9E)
+ *						MAX_PATH\x90\xA7\x8C\xC0\x82Ȃ\xB5\x81A\x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7free()\x82\xB7\x82邱\x82\xC6
+ *	@retval	TRUE		ok\x82\xAA\x89\x9F\x82\xB3\x82ꂽ
+ *	@retval	FALSE		cancel\x82\xAA\x89\x9F\x82\xB3\x82ꂽ
+ */
+BOOL TTGetOpenFileNameW(const TTOPENFILENAMEW *ofn, wchar_t **filename)
+{
+	return GetOpenSaveFileNameW(ofn, false, filename);
+}
+
+BOOL TTGetSaveFileNameW(const TTOPENFILENAMEW *ofn, wchar_t **filename)
+{
+	return GetOpenSaveFileNameW(ofn, true, filename);
+}

Added: trunk/teraterm/common/ttcommdlg.h
===================================================================
--- trunk/teraterm/common/ttcommdlg.h	                        (rev 0)
+++ trunk/teraterm/common/ttcommdlg.h	2022-12-11 12:08:07 UTC (rev 10403)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2020- TeraTerm Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <windows.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+   HWND         hwndOwner;
+   HINSTANCE    hInstance;
+   LPCWSTR      lpstrFilter;
+   LPWSTR       lpstrCustomFilter;
+   DWORD        nMaxCustFilter;
+   DWORD        nFilterIndex;
+   LPCWSTR lpstrFile;	// \x8F\x89\x8A\xFA\x83t\x83@\x83C\x83\x8B\x96\xBC
+   LPWSTR lpstrFileTitle;
+   DWORD        nMaxFileTitle;
+   LPCWSTR      lpstrInitialDir;	// \x8F\x89\x8A\xFA\x83t\x83H\x83\x8B\x83_
+   LPCWSTR      lpstrTitle;
+   DWORD        Flags;
+   WORD         nFileOffset;
+   WORD         nFileExtension;
+   LPCWSTR      lpstrDefExt;
+   DWORD        FlagsEx;
+} TTOPENFILENAMEW;
+
+BOOL TTGetOpenFileNameW(const TTOPENFILENAMEW *ofn, wchar_t **filename);
+BOOL TTGetSaveFileNameW(const TTOPENFILENAMEW *ofn, wchar_t **filename);
+
+typedef struct _TTbrowseinfoW {
+	HWND	hwndOwner;
+	LPCWSTR lpszTitle;
+	UINT	ulFlags;
+} TTBROWSEINFOW;
+
+BOOL TTSHBrowseForFolderW(TTBROWSEINFOW *bi, const wchar_t *def, wchar_t **folder);
+
+DllExport BOOL doSelectFolder(HWND hWnd, char *path, int pathlen, const char *def, const char *msg);
+BOOL doSelectFolderW(HWND hWnd, const wchar_t *def, const wchar_t *msg, wchar_t **folder);
+
+#ifdef __cplusplus
+}
+#endif

Modified: trunk/teraterm/common/ttlib.c
===================================================================
--- trunk/teraterm/common/ttlib.c	2022-12-11 12:07:56 UTC (rev 10402)
+++ trunk/teraterm/common/ttlib.c	2022-12-11 12:08:07 UTC (rev 10403)
@@ -43,6 +43,8 @@
 #include "tttypes.h"
 #include "compat_win.h"
 #include "codeconv.h"
+#include "ttlib.h"
+#include "ttcommdlg.h"
 
 // for isInvalidFileNameChar / replaceInvalidFileNameChar
 static char *invalidFileNameChars = "\\/:*?\"<>|";

Modified: trunk/teraterm/common/ttlib.h
===================================================================
--- trunk/teraterm/common/ttlib.h	2022-12-11 12:07:56 UTC (rev 10402)
+++ trunk/teraterm/common/ttlib.h	2022-12-11 12:08:07 UTC (rev 10403)
@@ -105,8 +105,6 @@
 void get_lang_msg(const char *key, PCHAR buf, int buf_len, const char *def, const char *iniFile);
 void get_lang_msgW(const char *key, wchar_t *buf, int buf_len, const wchar_t *def, const char *iniFile);
 int get_lang_font(const char *key, HWND dlg, PLOGFONT logfont, HFONT *font, const char *iniFile);
-DllExport BOOL doSelectFolder(HWND hWnd, char *path, int pathlen, const char *def, const char *msg);
-BOOL doSelectFolderW(HWND hWnd, const wchar_t *def, const wchar_t *msg, wchar_t **folder);
 #if defined(_MSC_VER)
 DllExport void OutputDebugPrintf(_Printf_format_string_ const char *fmt, ...);
 void OutputDebugPrintfW(_Printf_format_string_ const wchar_t *fmt, ...);
@@ -214,3 +212,5 @@
 #ifdef __cplusplus
 }
 #endif
+
+#include "ttcommdlg.h"

Modified: trunk/teraterm/common/ttlib_static_cpp.cpp
===================================================================
--- trunk/teraterm/common/ttlib_static_cpp.cpp	2022-12-11 12:07:56 UTC (rev 10402)
+++ trunk/teraterm/common/ttlib_static_cpp.cpp	2022-12-11 12:08:07 UTC (rev 10403)
@@ -52,10 +52,6 @@
 
 #include "ttlib.h"
 
-#if _WIN32_WINNT >= 0x0600 // Vista+
-#define IFILEOPENDIALOG_ENABLE 1
-#endif
-
 /**
  *	MessageBox\x82\xF0\x95\\x8E\xA6\x82\xB7\x82\xE9
  *
@@ -1073,123 +1069,6 @@
 	return download;
 }
 
-#if IFILEOPENDIALOG_ENABLE
-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) {
-	case BFFM_INITIALIZED: {
-		// \x8F\x89\x8A\x{227B39E}
-
-		const wchar_t *folder = (wchar_t *)lpData;
-		if (folder == NULL || folder[0] == 0) {
-			// \x91I\x91\xF0\x83t\x83H\x83\x8B\x83_\x82\xAA\x8Ew\x92肳\x82\xEA\x82Ă\xA2\x82Ȃ\xA2
-			break;
-		}
-		// \x83t\x83H\x83\x8B\x83_\x82\xF0\x91I\x91\xF0\x8F\xF3\x91Ԃɂ\xB7\x82\xE9
-		SendMessageW(hwnd, BFFM_SETSELECTIONW, (WPARAM)TRUE, (LPARAM)folder);
-		break;
-	}
-	default:
-		break;
-	}
-	return 0;
-}
-
-static BOOL doSelectFolderWAPI(HWND hWnd, const wchar_t *def, const wchar_t *msg, wchar_t **folder)
-{
-	wchar_t buf[MAX_PATH];
-	BROWSEINFOW bi = {};
-	bi.hwndOwner = hWnd;
-	bi.pidlRoot = 0;	// 0 = from desktop
-	bi.pszDisplayName = buf;
-	bi.lpszTitle = msg;
-	bi.ulFlags = BIF_EDITBOX | BIF_NEWDIALOGSTYLE;
-	bi.lpfn = BrowseCallback;
-	bi.lParam = (LPARAM)def;
-	LPITEMIDLIST pidlBrowse = SHBrowseForFolderW(&bi);
-	if (pidlBrowse == NULL) {
-		*folder = NULL;
-		return FALSE;
-	}
-
-	// PIDL\x8C`\x8E\xAE\x82̖߂\xE8\x92l\x82̃t\x83@\x83C\x83\x8B\x83V\x83X\x83e\x83\x80\x82̃p\x83X\x82ɕϊ\xB7
-	// TODO SHGetPathFromIDListEx() \x82֐؂\xE8\x91ւ\xA6?
-	if (!SHGetPathFromIDListW(pidlBrowse, buf)) {
-		return FALSE;
-	}
-	*folder = _wcsdup(buf);
-	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 IFILEOPENDIALOG_ENABLE
-	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)

Modified: trunk/teraterm/keycode/keycode.v8.vcproj
===================================================================
--- trunk/teraterm/keycode/keycode.v8.vcproj	2022-12-11 12:07:56 UTC (rev 10402)
+++ trunk/teraterm/keycode/keycode.v8.vcproj	2022-12-11 12:08:07 UTC (rev 10403)
@@ -68,7 +68,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="User32.lib Gdi32.lib SHELL32.lib Ole32.lib"
+				AdditionalDependencies="User32.lib Gdi32.lib SHELL32.lib Ole32.lib Advapi32.lib"
 				LinkIncremental="1"
 				SuppressStartupBanner="true"
 				SubSystem="2"
@@ -154,7 +154,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="User32.lib Gdi32.lib SHELL32.lib Ole32.lib"
+				AdditionalDependencies="User32.lib Gdi32.lib SHELL32.lib Ole32.lib Advapi32.lib"
 				LinkIncremental="1"
 				SuppressStartupBanner="true"
 				GenerateDebugInformation="true"

Modified: trunk/teraterm/ttpcmn/ttpcmn.v8.vcproj
===================================================================
--- trunk/teraterm/ttpcmn/ttpcmn.v8.vcproj	2022-12-11 12:07:56 UTC (rev 10402)
+++ trunk/teraterm/ttpcmn/ttpcmn.v8.vcproj	2022-12-11 12:08:07 UTC (rev 10403)
@@ -71,7 +71,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="layer_for_unicode.lib User32.lib gdi32.lib SHELL32.lib ADVAPI32.lib ole32.lib setupapi.lib"
+				AdditionalDependencies="layer_for_unicode.lib User32.lib gdi32.lib SHELL32.lib ADVAPI32.lib ole32.lib setupapi.lib Comctl32.lib Comdlg32.lib"
 				LinkIncremental="1"
 				SuppressStartupBanner="true"
 				AdditionalLibraryDirectories="$(OutDir)"
@@ -162,7 +162,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="layer_for_unicode.lib User32.lib gdi32.lib SHELL32.lib ADVAPI32.lib ole32.lib setupapi.lib"
+				AdditionalDependencies="layer_for_unicode.lib User32.lib gdi32.lib SHELL32.lib ADVAPI32.lib ole32.lib setupapi.lib Comctl32.lib Comdlg32.lib"
 				LinkIncremental="1"
 				SuppressStartupBanner="true"
 				AdditionalLibraryDirectories="$(OutDir)"

Modified: trunk/teraterm/ttpmacro/ttpmacro.v8.vcproj
===================================================================
--- trunk/teraterm/ttpmacro/ttpmacro.v8.vcproj	2022-12-11 12:07:56 UTC (rev 10402)
+++ trunk/teraterm/ttpmacro/ttpmacro.v8.vcproj	2022-12-11 12:08:07 UTC (rev 10403)
@@ -73,7 +73,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="common_static.lib LIBCMT.lib onig_s.lib SFMT.lib layer_for_unicode.lib iphlpapi.lib user32.lib gdi32.lib SHELL32.lib comctl32.lib comdlg32.lib ws2_32.lib ole32.lib"
+				AdditionalDependencies="common_static.lib LIBCMT.lib onig_s.lib SFMT.lib layer_for_unicode.lib iphlpapi.lib user32.lib gdi32.lib SHELL32.lib comctl32.lib comdlg32.lib ws2_32.lib ole32.lib Advapi32.lib"
 				LinkIncremental="1"
 				SuppressStartupBanner="true"
 				AdditionalLibraryDirectories="$(SolutionDir)..\libs\oniguruma\src;$(SolutionDir)..\libs\SFMT;$(OutDir)"
@@ -164,7 +164,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="common_static.lib onig_sd.lib SFMTd.lib layer_for_unicode.lib iphlpapi.lib user32.lib gdi32.lib SHELL32.lib comctl32.lib comdlg32.lib ws2_32.lib ole32.lib"
+				AdditionalDependencies="common_static.lib onig_sd.lib SFMTd.lib layer_for_unicode.lib iphlpapi.lib user32.lib gdi32.lib SHELL32.lib comctl32.lib comdlg32.lib ws2_32.lib ole32.lib Advapi32.lib"
 				LinkIncremental="1"
 				SuppressStartupBanner="true"
 				AdditionalLibraryDirectories="$(SolutionDir)..\libs\oniguruma\src;$(SolutionDir)..\libs\SFMT;$(OutDir)"

Modified: trunk/teraterm/ttptek/ttptek.v8.vcproj
===================================================================
--- trunk/teraterm/ttptek/ttptek.v8.vcproj	2022-12-11 12:07:56 UTC (rev 10402)
+++ trunk/teraterm/ttptek/ttptek.v8.vcproj	2022-12-11 12:08:07 UTC (rev 10403)
@@ -69,7 +69,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="common_static.lib User32.lib gdi32.lib SHELL32.lib ole32.lib ttpcmn.lib"
+				AdditionalDependencies="common_static.lib User32.lib gdi32.lib SHELL32.lib ole32.lib ttpcmn.lib Comdlg32.lib Advapi32.lib"
 				LinkIncremental="1"
 				SuppressStartupBanner="true"
 				AdditionalLibraryDirectories="$(OutDir)"
@@ -162,7 +162,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="common_static.lib User32.lib gdi32.lib SHELL32.lib ole32.lib ttpcmn.lib"
+				AdditionalDependencies="common_static.lib User32.lib gdi32.lib SHELL32.lib ole32.lib ttpcmn.lib Comdlg32.lib Advapi32.lib"
 				LinkIncremental="1"
 				SuppressStartupBanner="true"
 				AdditionalLibraryDirectories="$(OutDir)"


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