@-Franky- hat hier: Eigener FolderBrowserDialog - Root Folder ermitteln
einen eigenen
Dieser Dialog sieht aus wie ein "normaler"
Ich habe den mal her genommen und nach C# konvertiert und ihn im Aufruf etwas dem
Version 1
PickFolderDialog
Aufruf
Viel Vergnügen.
=====
Version 1.1:
- Öffnet als modaler Dialog
- von Component abgeleitet, lässt sich vom Designer aus auf die GUI ziehen
- merkt sich den zuletzt ausgewählten Pfad (sofern er nicht mit
Version 1.1
PickFolderDialog
einen eigenen
FolderBrowserDialog
in VB.NET vorgestellt.Dieser Dialog sieht aus wie ein "normaler"
OpenFileDialog
und verhält sich auch so, bis auf den Umstand, dass keine Dateien angezeigt werden.Ich habe den mal her genommen und nach C# konvertiert und ihn im Aufruf etwas dem
FolderBrowserDialog
angepasst, so dass ein FolderBrowserDialog
ganz easy durch den PickFolderDialog
ersetzt werden kann:C#-Quellcode
- using System;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- namespace TestPickFolderDialog
- {
- /// <summary>
- /// FolderB
- /// </summary>
- public sealed class PickFolderDialog
- : IDisposable
- {
- #region Const
- // siehe Headerfile Winerror.h
- private const int S_OK = 0;
- // siehe Headerfile shobjidl_core.h
- private const string IID_IModalWindow = "b4db1657-70d7-485e-8e3e-6fcb5a5c1802";
- private const string IID_IFileDialog = "42f85136-db7e-439c-85f1-e4075d135fc8";
- private const string IID_IShellItem = "43826d1e-e718-42ee-bc55-a1e261c37bfe";
- private const string CLSID_FileOpenDialog = "dc1c5a9c-e88a-4dde-a5a1-60f82a20aef7";
- #endregion Const
- #region Enums
- // siehe Headerfile shobjidl_core.h
- private enum FileOpenDialogOptions : int
- {
- OverwritePrompt = 0x2,
- FOS_STRICTFILETYPES = 0x4,
- FOS_NOCHANGEDIR = 0x8,
- FOS_PICKFOLDERS = 0x20,
- FOS_FORCEFILESYSTEM = 0x40,
- FOS_ALLNONSTORAGEITEMS = 0x80,
- FOS_NOVALIDATE = 0x100,
- FOS_ALLOWMULTISELECT = 0x200,
- FOS_PATHMUSTEXIST = 0x800,
- FOS_FILEMUSTEXIST = 0x1000,
- FOS_CREATEPROMPT = 0x2000,
- FOS_SHAREAWARE = 0x4000,
- FOS_NOREADONLYRETURN = 0x8000,
- FOS_NOTESTFILECREATE = 0x10000,
- FOS_HIDEMRUPLACES = 0x20000,
- FOS_HIDEPINNEDPLACES = 0x40000,
- FOS_NODEREFERENCELINKS = 0x100000,
- FOS_OKBUTTONNEEDSINTERACTION = 0x200000,
- FOS_DONTADDTORECENT = 0x2000000,
- FOS_FORCESHOWHIDDEN = 0x10000000,
- FOS_DEFAULTNOMINIMODE = 0x20000000,
- FOS_FORCEPREVIEWPANEON = 0x40000000,
- FOS_SUPPORTSTREAMABLEITEMS = int.MinValue + 0x00000000
- }
- // siehe Headerfile shobjidl_core.h
- public enum SIGDN : int
- {
- SIGDN_NORMALDISPLAYField = 0x0,
- SIGDN_PARENTRELATIVEPARSINGField = int.MinValue + 0x00018001,
- SIGDN_DESKTOPABSOLUTEPARSINGField = int.MinValue + 0x00028000,
- SIGDN_PARENTRELATIVEEDITINGField = int.MinValue + 0x00031001,
- SIGDN_DESKTOPABSOLUTEEDITINGField = int.MinValue + 0x0004C000,
- SIGDN_FILESYSPATHField = int.MinValue + 0x00058000,
- SIGDN_URLField = int.MinValue + 0x00068000,
- SIGDN_PARENTRELATIVEFORADDRESSBARField = int.MinValue + 0x0007C001,
- SIGDN_PARENTRELATIVEField = int.MinValue + 0x00080001,
- SIGDN_PARENTRELATIVEFORUIField = int.MinValue + 0x00094001
- }
- #endregion Enums
- #region Member
- private bool m_DisposedValue;
- private IFileDialog m_FileOpenDialog;
- #endregion Member
- #region API
- // siehe https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-shcreateitemfromparsingname
- // oder Headerfile shobjidl_core.h
- [DllImport("Shell32.dll", EntryPoint = "SHCreateItemFromParsingName")]
- [PreserveSig]
- private static extern int SHCreateItemFromParsingName([In][MarshalAs(UnmanagedType.LPWStr)] string pszPath, [In] IntPtr pbc, [In][MarshalAs(UnmanagedType.LPStruct)] Guid riid, out IntPtr pUnk);
- #endregion
- #region Properties
- /// <summary>
- /// Gets or sets the path selected by the user.
- /// Wird nichts angegeben: "Dieser PC"
- /// </summary>
- public string SelectedPath
- {
- get { return this.GetResult(PickFolderDialog.SIGDN.SIGDN_FILESYSPATHField); }
- set { this.SetFolder(value); }
- }
- #endregion Properties
- #region Konstruktor
- public PickFolderDialog()
- {
- FileOpenDialogOptions options;
- this.m_FileOpenDialog = (IFileDialog)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(CLSID_FileOpenDialog)));
- if (this.m_FileOpenDialog != null)
- {
- if (this.m_FileOpenDialog.GetOptions(out options) == S_OK)
- {
- options |= FileOpenDialogOptions.FOS_PICKFOLDERS;
- this.m_FileOpenDialog.SetOptions(options);
- }
- }
- }
- #endregion Konstruktor
- #region Public Functions
- public bool SetFolder(string folder = null)
- {
- // Wird bei Dialog.SetFolder nichts angegeben = Dieser PC
- // Ansonsten z.B. "C:" oder "C:\" = Laufwerk C:
- // "C:\Users" oder "C:\Users\" = Ordner Users auf Laufwerk C:
- // "::{645FF040-5081-101B-9F08-00AA002F954E}" = Papierkorb
- // "::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}" = Netzwerk
- // "::{031E4825-7B94-4DC3-B131-E946B44C8DD5}" = Bibliotheken
- // usw.
- bool retval = false;
- if (this.m_FileOpenDialog != null)
- {
- IntPtr item;
- if (folder is null)
- {
- // C-String-Ende-Kennung
- folder = "\0";
- }
- if (SHCreateItemFromParsingName(folder, IntPtr.Zero, new Guid(IID_IShellItem), out item) == S_OK)
- {
- if (this.m_FileOpenDialog.SetFolder(item) == S_OK)
- {
- retval = true;
- }
- Marshal.Release(item);
- }
- }
- return retval;
- }
- public DialogResult ShowDialog(IntPtr hwndOwner = default)
- {
- if (this.m_FileOpenDialog != null)
- {
- if (this.m_FileOpenDialog.Show(hwndOwner) == S_OK)
- {
- return DialogResult.OK;
- }
- }
- return DialogResult.Cancel;
- }
- public string GetResult(SIGDN eSIGDN = SIGDN.SIGDN_FILESYSPATHField)
- {
- string strRet = string.Empty;
- if (this.m_FileOpenDialog != null)
- {
- if (this.m_FileOpenDialog.GetResult(out IShellItem ShellItem) == S_OK)
- {
- if (ShellItem.GetDisplayName(eSIGDN, out IntPtr pszName) == S_OK)
- {
- strRet = Marshal.PtrToStringUni(pszName);
- Marshal.FreeCoTaskMem(pszName);
- }
- Marshal.ReleaseComObject(ShellItem);
- }
- }
- return strRet;
- }
- #endregion Public Functions
- #region Interface IModalWindow
- // siehe Headerfile shobjidl_core.h
- [ComImport]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [Guid(IID_IModalWindow)]
- private interface IModalWindow
- {
- // virtual /* [local] */ HRESULT STDMETHODCALLTYPE Show(
- // /* [annotation][unique][in] */
- // _In_opt_ HWND hwndOwner) = 0;
- [PreserveSig]
- int Show([In] IntPtr hwndOwner);
- }
- #endregion
- #region Interface IFileDialog
- // siehe Headerfile shobjidl_core.h
- [ComImport]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [Guid(IID_IFileDialog)]
- private interface IFileDialog : IModalWindow
- {
- [PreserveSig]
- new int Show([In] IntPtr hwndOwner);
- // virtual HRESULT STDMETHODCALLTYPE SetFileTypes(
- // /* [in] */ UINT cFileTypes,
- // /* [size_is][in] */ __RPC__in_ecount_full(cFileTypes) const COMDLG_FILTERSPEC *rgFilterSpec) = 0;
- [PreserveSig]
- int SetFileTypes();
- // virtual HRESULT STDMETHODCALLTYPE SetFileTypeIndex(
- // /* [in] */ UINT iFileType) = 0;
- [PreserveSig]
- int SetFileTypeIndex();
- // virtual HRESULT STDMETHODCALLTYPE GetFileTypeIndex(
- // /* [out] */ __RPC__out UINT *piFileType) = 0;
- [PreserveSig]
- int GetFileTypeIndex();
- // virtual HRESULT STDMETHODCALLTYPE Advise(
- // /* [in] */ __RPC__in_opt IFileDialogEvents *pfde,
- // /* [out] */ __RPC__out DWORD *pdwCookie) = 0;
- [PreserveSig]
- int Advise();
- // virtual HRESULT STDMETHODCALLTYPE Unadvise(
- // /* [in] */ DWORD dwCookie) = 0;
- [PreserveSig]
- int Unadvise();
- // virtual HRESULT STDMETHODCALLTYPE SetOptions(
- // /* [in] */ FILEOPENDIALOGOPTIONS fos) = 0;
- [PreserveSig]
- int SetOptions([In] FileOpenDialogOptions fos);
- // virtual HRESULT STDMETHODCALLTYPE GetOptions(
- // /* [out] */ __RPC__out FILEOPENDIALOGOPTIONS *pfos) = 0;
- [PreserveSig]
- int GetOptions(out FileOpenDialogOptions pfos);
- // virtual HRESULT STDMETHODCALLTYPE SetDefaultFolder(
- // /* [in] */ __RPC__in_opt IShellItem *psi) = 0;
- [PreserveSig]
- int SetDefaultFolder();
- // virtual HRESULT STDMETHODCALLTYPE SetFolder(
- // /* [in] */ __RPC__in_opt IShellItem *psi) = 0;
- [PreserveSig]
- int SetFolder([In] IntPtr psi);
- // virtual HRESULT STDMETHODCALLTYPE GetFolder(
- // /* [out] */ __RPC__deref_out_opt IShellItem **ppsi) = 0;
- [PreserveSig]
- int GetFolder();
- // virtual HRESULT STDMETHODCALLTYPE GetCurrentSelection(
- // /* [out] */ __RPC__deref_out_opt IShellItem **ppsi) = 0;
- [PreserveSig]
- int GetCurrentSelection();
- // virtual HRESULT STDMETHODCALLTYPE SetFileName(
- // /* [string][in] */ __RPC__in_string LPCWSTR pszName) = 0;
- [PreserveSig]
- int SetFileName();
- // virtual HRESULT STDMETHODCALLTYPE GetFileName(
- // /* [string][out] */ __RPC__deref_out_opt_string LPWSTR *pszName) = 0;
- [PreserveSig]
- int GetFileName();
- // virtual HRESULT STDMETHODCALLTYPE SetTitle(
- // /* [string][in] */ __RPC__in_string LPCWSTR pszTitle) = 0;
- [PreserveSig]
- int SetTitle();
- // virtual HRESULT STDMETHODCALLTYPE SetOkButtonLabel(
- // /* [string][in] */ __RPC__in_string LPCWSTR pszText) = 0;
- [PreserveSig]
- int SetOkButtonLabel();
- // virtual HRESULT STDMETHODCALLTYPE SetFileNameLabel(
- // /* [string][in] */ __RPC__in_string LPCWSTR pszLabel) = 0;
- [PreserveSig]
- int SetFileNameLabel();
- // virtual HRESULT STDMETHODCALLTYPE GetResult(
- // /* [out] */ __RPC__deref_out_opt IShellItem **ppsi) = 0;
- [PreserveSig]
- int GetResult([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);
- // virtual HRESULT STDMETHODCALLTYPE AddPlace(
- // /* [in] */ __RPC__in_opt IShellItem *psi,
- // /* [in] */ FDAP fdap) = 0;
- [PreserveSig]
- int AddPlace();
- // virtual HRESULT STDMETHODCALLTYPE SetDefaultExtension(
- // /* [string][in] */ __RPC__in_string LPCWSTR pszDefaultExtension) = 0;
- [PreserveSig]
- int SetDefaultExtension();
- // virtual HRESULT STDMETHODCALLTYPE Close(
- // /* [in] */ HRESULT hr) = 0;
- [PreserveSig]
- int Close();
- // virtual HRESULT STDMETHODCALLTYPE SetClientGuid(
- // /* [in] */ __RPC__in REFGUID guid) = 0;
- [PreserveSig]
- int SetClientGuid();
- // virtual HRESULT STDMETHODCALLTYPE ClearClientData( void) = 0;
- [PreserveSig]
- int ClearClientData();
- // virtual HRESULT STDMETHODCALLTYPE SetFilter(
- // /* [in] */ __RPC__in_opt IShellItemFilter *pFilter) = 0;
- [PreserveSig]
- int SetFilter();
- }
- #endregion
- #region Interface IShellItem
- // siehe Headerfile shobjidl_core.h
- [ComImport]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [Guid(IID_IShellItem)]
- private interface IShellItem
- {
- // virtual HRESULT STDMETHODCALLTYPE BindToHandler(
- // /* [unique][in] */ __RPC__in_opt IBindCtx *pbc,
- // /* [in] */ __RPC__in REFGUID bhid,
- // /* [in] */ __RPC__in REFIID riid,
- // /* [iid_is][out] */ __RPC__deref_out_opt void **ppv) = 0;
- [PreserveSig]
- int BindToHandler();
- // virtual HRESULT STDMETHODCALLTYPE GetParent(
- // /* [out] */ __RPC__deref_out_opt IShellItem **ppsi) = 0;
- [PreserveSig]
- int GetParent();
- // virtual HRESULT STDMETHODCALLTYPE GetDisplayName(
- // /* [in] */ SIGDN sigdnName,
- // /* [annotation][string][out] */
- // _Outptr_result_nullonfailure_ LPWSTR *ppszName) = 0;
- [PreserveSig]
- int GetDisplayName([In] SIGDN sigdnName, out IntPtr ppszName);
- // virtual HRESULT STDMETHODCALLTYPE GetAttributes(
- // /* [in] */ SFGAOF sfgaoMask,
- // /* [out] */ __RPC__out SFGAOF *psfgaoAttribs) = 0;
- [PreserveSig]
- int GetAttributes();
- // virtual HRESULT STDMETHODCALLTYPE Compare(
- // /* [in] */ __RPC__in_opt IShellItem *psi,
- // /* [in] */ SICHINTF hint,
- // /* [out] */ __RPC__out int *piOrder) = 0;
- [PreserveSig]
- int Compare();
- }
- #endregion
- #region Dispose
- public void Dispose()
- {
- if (!this.m_DisposedValue)
- {
- if (this.m_FileOpenDialog != null)
- {
- if (Marshal.ReleaseComObject(this.m_FileOpenDialog) == 0)
- {
- this.m_FileOpenDialog = null;
- }
- }
- this.m_DisposedValue = true;
- }
- GC.SuppressFinalize(this);
- }
- #endregion Dispose
- }
- }
C#-Quellcode
- using System;
- using System.Windows.Forms;
- namespace TestPickFolderDialog
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- this.InitializeComponent();
- }
- private void Button1_Click(object sender, EventArgs e)
- {
- using (PickFolderDialog dlg = new PickFolderDialog())
- {
- dlg.SelectedPath = @"C:\Users\";
- if (dlg.ShowDialog() == DialogResult.OK)
- {
- this.label1.Text = dlg.SelectedPath;
- }
- }
- }
- }
- }
=====
Version 1.1:
- Öffnet als modaler Dialog
- von Component abgeleitet, lässt sich vom Designer aus auf die GUI ziehen
- merkt sich den zuletzt ausgewählten Pfad (sofern er nicht mit
Using
aufgerufen wird)
C#-Quellcode
- using System;
- using System.ComponentModel;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- // Version 1.1 2022-01-16
- namespace TestPickFolderDialog
- {
- /// <summary>
- /// FolderBrowserDialog im Gewandt eines OpenFileDialogs
- /// </summary>
- [DesignerCategory("code")]
- public class PickFolderDialog
- : Component
- {
- #region Const
- // siehe Headerfile Winerror.h
- private const int S_OK = 0;
- // siehe Headerfile shobjidl_core.h
- private const string IID_IModalWindow = "b4db1657-70d7-485e-8e3e-6fcb5a5c1802";
- private const string IID_IFileDialog = "42f85136-db7e-439c-85f1-e4075d135fc8";
- private const string IID_IShellItem = "43826d1e-e718-42ee-bc55-a1e261c37bfe";
- private const string CLSID_FileOpenDialog = "dc1c5a9c-e88a-4dde-a5a1-60f82a20aef7";
- #endregion Const
- #region Enums
- // siehe Headerfile shobjidl_core.h
- private enum FileOpenDialogOptions : int
- {
- OverwritePrompt = 0x2,
- FOS_STRICTFILETYPES = 0x4,
- FOS_NOCHANGEDIR = 0x8,
- FOS_PICKFOLDERS = 0x20,
- FOS_FORCEFILESYSTEM = 0x40,
- FOS_ALLNONSTORAGEITEMS = 0x80,
- FOS_NOVALIDATE = 0x100,
- FOS_ALLOWMULTISELECT = 0x200,
- FOS_PATHMUSTEXIST = 0x800,
- FOS_FILEMUSTEXIST = 0x1000,
- FOS_CREATEPROMPT = 0x2000,
- FOS_SHAREAWARE = 0x4000,
- FOS_NOREADONLYRETURN = 0x8000,
- FOS_NOTESTFILECREATE = 0x10000,
- FOS_HIDEMRUPLACES = 0x20000,
- FOS_HIDEPINNEDPLACES = 0x40000,
- FOS_NODEREFERENCELINKS = 0x100000,
- FOS_OKBUTTONNEEDSINTERACTION = 0x200000,
- FOS_DONTADDTORECENT = 0x2000000,
- FOS_FORCESHOWHIDDEN = 0x10000000,
- FOS_DEFAULTNOMINIMODE = 0x20000000,
- FOS_FORCEPREVIEWPANEON = 0x40000000,
- FOS_SUPPORTSTREAMABLEITEMS = int.MinValue + 0x00000000
- }
- // siehe Headerfile shobjidl_core.h
- public enum SIGDN : int
- {
- SIGDN_NORMALDISPLAYField = 0x0,
- SIGDN_PARENTRELATIVEPARSINGField = int.MinValue + 0x00018001,
- SIGDN_DESKTOPABSOLUTEPARSINGField = int.MinValue + 0x00028000,
- SIGDN_PARENTRELATIVEEDITINGField = int.MinValue + 0x00031001,
- SIGDN_DESKTOPABSOLUTEEDITINGField = int.MinValue + 0x0004C000,
- SIGDN_FILESYSPATHField = int.MinValue + 0x00058000,
- SIGDN_URLField = int.MinValue + 0x00068000,
- SIGDN_PARENTRELATIVEFORADDRESSBARField = int.MinValue + 0x0007C001,
- SIGDN_PARENTRELATIVEField = int.MinValue + 0x00080001,
- SIGDN_PARENTRELATIVEFORUIField = int.MinValue + 0x00094001
- }
- #endregion Enums
- #region Member
- /// <summary>
- /// COM-Instanz des Dialogs
- /// </summary>
- private IFileDialog FileDialog;
- #endregion Member
- #region API
- // siehe https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-shcreateitemfromparsingname
- // oder Headerfile shobjidl_core.h
- [DllImport("Shell32.dll", EntryPoint = "SHCreateItemFromParsingName")]
- [PreserveSig]
- private static extern int SHCreateItemFromParsingName([In][MarshalAs(UnmanagedType.LPWStr)] string pszPath, [In] IntPtr pbc, [In][MarshalAs(UnmanagedType.LPStruct)] Guid riid, out IntPtr pUnk);
- #endregion
- #region Properties
- /// <summary>
- /// Gets or sets the path selected by the user.
- /// Wird nichts angegeben: "Dieser PC"
- /// </summary>
- public string SelectedPath { get; set; }
- #endregion Properties
- #region Konstruktor
- public PickFolderDialog()
- {
- FileOpenDialogOptions options;
- this.FileDialog = (IFileDialog)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(CLSID_FileOpenDialog)));
- if (this.FileDialog == null)
- {
- throw new COMException("PickFolderDialog constructor failed.");
- }
- if (this.FileDialog.GetOptions(out options) == S_OK)
- {
- options |= FileOpenDialogOptions.FOS_PICKFOLDERS;
- this.FileDialog.SetOptions(options);
- }
- }
- #endregion Konstruktor
- #region Public Functions
- public DialogResult ShowDialog(IntPtr hwndOwner)
- {
- this.SetFolder(this.SelectedPath);
- if (this.FileDialog.Show(hwndOwner) == S_OK)
- {
- this.SelectedPath = this.GetResult(PickFolderDialog.SIGDN.SIGDN_FILESYSPATHField);
- return DialogResult.OK;
- }
- return DialogResult.Cancel;
- }
- public string GetResult(SIGDN eSIGDN = SIGDN.SIGDN_FILESYSPATHField)
- {
- string strRet = string.Empty;
- if (this.FileDialog.GetResult(out IShellItem ShellItem) == S_OK)
- {
- if (ShellItem.GetDisplayName(eSIGDN, out IntPtr pszName) == S_OK)
- {
- strRet = Marshal.PtrToStringUni(pszName);
- Marshal.FreeCoTaskMem(pszName);
- }
- Marshal.ReleaseComObject(ShellItem);
- }
- return strRet;
- }
- #endregion Public Functions
- #region Private Functions
- private bool SetFolder(string folder)
- {
- // Wird bei Dialog.SetFolder nichts angegeben = Dieser PC
- // Ansonsten z.B. "C:" oder "C:\" = Laufwerk C:
- // "C:\Users" oder "C:\Users\" = Ordner Users auf Laufwerk C:
- // "::{645FF040-5081-101B-9F08-00AA002F954E}" = Papierkorb
- // "::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}" = Netzwerk
- // "::{031E4825-7B94-4DC3-B131-E946B44C8DD5}" = Bibliotheken
- // usw.
- bool retval = false;
- IntPtr item;
- if (folder is null)
- {
- // C-String-Ende-Kennung
- folder = "\0";
- }
- if (SHCreateItemFromParsingName(folder, IntPtr.Zero, new Guid(IID_IShellItem), out item) == S_OK)
- {
- if (this.FileDialog.SetFolder(item) == S_OK)
- {
- retval = true;
- }
- Marshal.Release(item);
- }
- return retval;
- }
- #endregion Private Functions
- #region Interface IModalWindow
- // siehe Headerfile shobjidl_core.h
- [ComImport]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [Guid(IID_IModalWindow)]
- private interface IModalWindow
- {
- // virtual /* [local] */ HRESULT STDMETHODCALLTYPE Show(
- // /* [annotation][unique][in] */
- // _In_opt_ HWND hwndOwner) = 0;
- [PreserveSig]
- int Show([In] IntPtr hwndOwner);
- }
- #endregion
- #region Interface IFileDialog
- // siehe Headerfile shobjidl_core.h
- [ComImport]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [Guid(IID_IFileDialog)]
- private interface IFileDialog : IModalWindow
- {
- [PreserveSig]
- new int Show([In] IntPtr hwndOwner);
- // virtual HRESULT STDMETHODCALLTYPE SetFileTypes(
- // /* [in] */ UINT cFileTypes,
- // /* [size_is][in] */ __RPC__in_ecount_full(cFileTypes) const COMDLG_FILTERSPEC *rgFilterSpec) = 0;
- [PreserveSig]
- int SetFileTypes();
- // virtual HRESULT STDMETHODCALLTYPE SetFileTypeIndex(
- // /* [in] */ UINT iFileType) = 0;
- [PreserveSig]
- int SetFileTypeIndex();
- // virtual HRESULT STDMETHODCALLTYPE GetFileTypeIndex(
- // /* [out] */ __RPC__out UINT *piFileType) = 0;
- [PreserveSig]
- int GetFileTypeIndex();
- // virtual HRESULT STDMETHODCALLTYPE Advise(
- // /* [in] */ __RPC__in_opt IFileDialogEvents *pfde,
- // /* [out] */ __RPC__out DWORD *pdwCookie) = 0;
- [PreserveSig]
- int Advise();
- // virtual HRESULT STDMETHODCALLTYPE Unadvise(
- // /* [in] */ DWORD dwCookie) = 0;
- [PreserveSig]
- int Unadvise();
- // virtual HRESULT STDMETHODCALLTYPE SetOptions(
- // /* [in] */ FILEOPENDIALOGOPTIONS fos) = 0;
- [PreserveSig]
- int SetOptions([In] FileOpenDialogOptions fos);
- // virtual HRESULT STDMETHODCALLTYPE GetOptions(
- // /* [out] */ __RPC__out FILEOPENDIALOGOPTIONS *pfos) = 0;
- [PreserveSig]
- int GetOptions(out FileOpenDialogOptions pfos);
- // virtual HRESULT STDMETHODCALLTYPE SetDefaultFolder(
- // /* [in] */ __RPC__in_opt IShellItem *psi) = 0;
- [PreserveSig]
- int SetDefaultFolder();
- // virtual HRESULT STDMETHODCALLTYPE SetFolder(
- // /* [in] */ __RPC__in_opt IShellItem *psi) = 0;
- [PreserveSig]
- int SetFolder([In] IntPtr psi);
- // virtual HRESULT STDMETHODCALLTYPE GetFolder(
- // /* [out] */ __RPC__deref_out_opt IShellItem **ppsi) = 0;
- [PreserveSig]
- int GetFolder();
- // virtual HRESULT STDMETHODCALLTYPE GetCurrentSelection(
- // /* [out] */ __RPC__deref_out_opt IShellItem **ppsi) = 0;
- [PreserveSig]
- int GetCurrentSelection();
- // virtual HRESULT STDMETHODCALLTYPE SetFileName(
- // /* [string][in] */ __RPC__in_string LPCWSTR pszName) = 0;
- [PreserveSig]
- int SetFileName();
- // virtual HRESULT STDMETHODCALLTYPE GetFileName(
- // /* [string][out] */ __RPC__deref_out_opt_string LPWSTR *pszName) = 0;
- [PreserveSig]
- int GetFileName();
- // virtual HRESULT STDMETHODCALLTYPE SetTitle(
- // /* [string][in] */ __RPC__in_string LPCWSTR pszTitle) = 0;
- [PreserveSig]
- int SetTitle();
- // virtual HRESULT STDMETHODCALLTYPE SetOkButtonLabel(
- // /* [string][in] */ __RPC__in_string LPCWSTR pszText) = 0;
- [PreserveSig]
- int SetOkButtonLabel();
- // virtual HRESULT STDMETHODCALLTYPE SetFileNameLabel(
- // /* [string][in] */ __RPC__in_string LPCWSTR pszLabel) = 0;
- [PreserveSig]
- int SetFileNameLabel();
- // virtual HRESULT STDMETHODCALLTYPE GetResult(
- // /* [out] */ __RPC__deref_out_opt IShellItem **ppsi) = 0;
- [PreserveSig]
- int GetResult([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);
- // virtual HRESULT STDMETHODCALLTYPE AddPlace(
- // /* [in] */ __RPC__in_opt IShellItem *psi,
- // /* [in] */ FDAP fdap) = 0;
- [PreserveSig]
- int AddPlace();
- // virtual HRESULT STDMETHODCALLTYPE SetDefaultExtension(
- // /* [string][in] */ __RPC__in_string LPCWSTR pszDefaultExtension) = 0;
- [PreserveSig]
- int SetDefaultExtension();
- // virtual HRESULT STDMETHODCALLTYPE Close(
- // /* [in] */ HRESULT hr) = 0;
- [PreserveSig]
- int Close();
- // virtual HRESULT STDMETHODCALLTYPE SetClientGuid(
- // /* [in] */ __RPC__in REFGUID guid) = 0;
- [PreserveSig]
- int SetClientGuid();
- // virtual HRESULT STDMETHODCALLTYPE ClearClientData( void) = 0;
- [PreserveSig]
- int ClearClientData();
- // virtual HRESULT STDMETHODCALLTYPE SetFilter(
- // /* [in] */ __RPC__in_opt IShellItemFilter *pFilter) = 0;
- [PreserveSig]
- int SetFilter();
- }
- #endregion
- #region Interface IShellItem
- // siehe Headerfile shobjidl_core.h
- [ComImport]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- [Guid(IID_IShellItem)]
- private interface IShellItem
- {
- // virtual HRESULT STDMETHODCALLTYPE BindToHandler(
- // /* [unique][in] */ __RPC__in_opt IBindCtx *pbc,
- // /* [in] */ __RPC__in REFGUID bhid,
- // /* [in] */ __RPC__in REFIID riid,
- // /* [iid_is][out] */ __RPC__deref_out_opt void **ppv) = 0;
- [PreserveSig]
- int BindToHandler();
- // virtual HRESULT STDMETHODCALLTYPE GetParent(
- // /* [out] */ __RPC__deref_out_opt IShellItem **ppsi) = 0;
- [PreserveSig]
- int GetParent();
- // virtual HRESULT STDMETHODCALLTYPE GetDisplayName(
- // /* [in] */ SIGDN sigdnName,
- // /* [annotation][string][out] */
- // _Outptr_result_nullonfailure_ LPWSTR *ppszName) = 0;
- [PreserveSig]
- int GetDisplayName([In] SIGDN sigdnName, out IntPtr ppszName);
- // virtual HRESULT STDMETHODCALLTYPE GetAttributes(
- // /* [in] */ SFGAOF sfgaoMask,
- // /* [out] */ __RPC__out SFGAOF *psfgaoAttribs) = 0;
- [PreserveSig]
- int GetAttributes();
- // virtual HRESULT STDMETHODCALLTYPE Compare(
- // /* [in] */ __RPC__in_opt IShellItem *psi,
- // /* [in] */ SICHINTF hint,
- // /* [out] */ __RPC__out int *piOrder) = 0;
- [PreserveSig]
- int Compare();
- }
- #endregion
- #region Dispose
- protected override void Dispose(bool disposing)
- {
- if (this.FileDialog != null)
- {
- Marshal.ReleaseComObject(this.FileDialog);
- this.FileDialog = null;
- }
- base.Dispose(disposing);
- }
- #endregion Dispose
- }
- }
Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch
Ein guter .NET-Snippetkonverter (der ist verfügbar).
Programmierfragen über PN / Konversation werden ignoriert!
Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch
Ein guter .NET-Snippetkonverter (der ist verfügbar).
Programmierfragen über PN / Konversation werden ignoriert!
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „RodFromGermany“ ()