using System.Security; namespace Vanara.PInvoke; public static partial class Shell32 { /// /// Specifies the values that indicate whether a control is visible and enabled. Used by members of the IFileDialogCustomize interface. /// [Flags] public enum CDCONTROLSTATEF : uint { /// The control is inactive and cannot be accessed by the user. CDCS_INACTIVE = 0x00000000, /// The control is active. CDCS_ENABLED = 0x00000001, /// The control is visible. The absence of this value indicates that the control is hidden. CDCS_VISIBLE = 0x00000002, /// Windows 7 and later. The control is visible and enabled. CDCS_ENABLEDVISIBLE = 0x00000003 } /// Specifies list placement. [PInvokeData("Shobjidl.h", MSDNShortId = "bb762502")] public enum FDAP : uint { /// The place is added to the bottom of the default list. FDAP_BOTTOM = 0, /// The place is added to the top of the default list. FDAP_TOP = 1 } /// /// Specifies the values used by the IFileDialogEvents::OnShareViolation method to indicate an application's response to a sharing /// violation that occurs when a file is opened or saved. /// [PInvokeData("Shobjidl.h", MSDNShortId = "bb762504")] public enum FDE_SHAREVIOLATION_RESPONSE { /// /// The application has not handled the event. The dialog displays a UI that indicates that the file is in use and a different /// file must be chosen. /// FDESVR_DEFAULT, /// The application has determined that the file should be returned from the dialog. FDESVR_ACCEPT, /// The application has determined that the file should not be returned from the dialog. FDESVR_REFUSE } /// Defines the set of options available to an Open or Save dialog. [PInvokeData("Shobjidl.h", MSDNShortId = "dn457282")] [Flags] public enum FILEOPENDIALOGOPTIONS : uint { /// /// When saving a file, prompt before overwriting an existing file of the same name. This is a default value for the Save dialog. /// FOS_OVERWRITEPROMPT = 0x00000002, /// /// In the Save dialog, only allow the user to choose a file that has one of the file name extensions specified through IFileDialog::SetFileTypes. /// FOS_STRICTFILETYPES = 0x00000004, /// Don't change the current working directory. FOS_NOCHANGEDIR = 0x00000008, /// Present an Open dialog that offers a choice of folders rather than files. FOS_PICKFOLDERS = 0x00000020, /// /// Ensures that returned items are file system items (SFGAO_FILESYSTEM). Note that this does not apply to items returned by IFileDialog::GetCurrentSelection. /// FOS_FORCEFILESYSTEM = 0x00000040, /// /// Enables the user to choose any item in the Shell namespace, not just those with SFGAO_STREAM or SFAGO_FILESYSTEM attributes. /// This flag cannot be combined with FOS_FORCEFILESYSTEM. /// FOS_ALLNONSTORAGEITEMS = 0x00000080, /// /// Do not check for situations that would prevent an application from opening the selected file, such as sharing violations or /// access denied errors. /// FOS_NOVALIDATE = 0x00000100, /// /// Enables the user to select multiple items in the open dialog. Note that when this flag is set, the IFileOpenDialog interface /// must be used to retrieve those items. /// FOS_ALLOWMULTISELECT = 0x00000200, /// The item returned must be in an existing folder. This is a default value. FOS_PATHMUSTEXIST = 0x00000800, /// The item returned must exist. This is a default value for the Open dialog. FOS_FILEMUSTEXIST = 0x00001000, /// /// Prompt for creation if the item returned in the save dialog does not exist. Note that this does not actually create the item. /// FOS_CREATEPROMPT = 0x00002000, /// /// In the case of a sharing violation when an application is opening a file, call the application back through OnShareViolation /// for guidance. This flag is overridden by FOS_NOVALIDATE. /// FOS_SHAREAWARE = 0x00004000, /// Do not return read-only items. This is a default value for the Save dialog. FOS_NOREADONLYRETURN = 0x00008000, /// /// Do not test whether creation of the item as specified in the Save dialog will be successful. If this flag is not set, the /// calling application must handle errors, such as denial of access, discovered when the item is created. /// FOS_NOTESTFILECREATE = 0x00010000, /// /// Hide the list of places from which the user has recently opened or saved items. This value is not supported as of Windows 7. /// FOS_HIDEMRUPLACES = 0x00020000, /// /// Hide items shown by default in the view's navigation pane. This flag is often used in conjunction with the /// IFileDialog::AddPlace method, to hide standard locations and replace them with custom locations. /// /// Windows 7 and later. Hide all of the standard namespace locations (such as Favorites, Libraries, Computer, and /// Network) shown in the navigation pane. /// /// /// Windows Vista. Hide the contents of the Favorite Links tree in the navigation pane. Note that the category itself is /// still displayed, but shown as empty. /// /// FOS_HIDEPINNEDPLACES = 0x00040000, /// /// Shortcuts should not be treated as their target items. This allows an application to open a .lnk file rather than what that /// file is a shortcut to. /// FOS_NODEREFERENCELINKS = 0x00100000, /// Do not add the item being opened or saved to the recent documents list (SHAddToRecentDocs). FOS_DONTADDTORECENT = 0x02000000, /// Include hidden and system items. FOS_FORCESHOWHIDDEN = 0x10000000, /// /// Indicates to the Save As dialog box that it should open in expanded mode. Expanded mode is the mode that is set and unset by /// clicking the button in the lower-left corner of the Save As dialog box that switches between Browse Folders and Hide Folders /// when clicked. This value is not supported as of Windows 7. /// FOS_DEFAULTNOMINIMODE = 0x20000000, /// Indicates to the Open dialog box that the preview pane should always be displayed. FOS_FORCEPREVIEWPANEON = 0x40000000, /// /// Indicates that the caller is opening a file as a stream (BHID_Stream), so there is no need to download that file. /// FOS_SUPPORTSTREAMABLEITEMS = 0x80000000 } /// Indicates status of the merge process. [PInvokeData("shobjidl_core.h", MSDNShortId = "NF:shobjidl_core.IFileSyncMergeHandler.Merge")] public enum MERGE_UPDATE_STATUS { /// Indicates that the process has completed successfully. MUS_COMPLETE = 0, /// Indicates that additional input is required by the user for the process to complete. MUS_USERINPUTNEEDED = (MUS_COMPLETE + 1), /// Indicates that the process has failed. MUS_FAILED = (MUS_USERINPUTNEEDED + 1) } /// Used by methods of the ITransferSource and ITransferDestination interfaces to control their file operations. [Flags] public enum TRANSFER_SOURCE_FLAGS { /// Fail if the destination already exists, unless TSF_OVERWRITE_EXIST is specified. This is a default behavior. TSF_NORMAL = 0, /// Fail if the destination already exists, unless TSF_OVERWRITE_EXIST is specified. This is a default behavior TSF_FAIL_EXIST = 0, /// Rename with auto-name generation if the destination already exists. TSF_RENAME_EXIST = 0x1, /// Overwrite or merge with the destination. TSF_OVERWRITE_EXIST = 0x2, /// Allow creation of a decrypted destination. TSF_ALLOW_DECRYPTION = 0x4, /// No discretionary access control list (DACL), system access control list (SACL), or owner. TSF_NO_SECURITY = 0x8, /// /// Copy the creation time as part of the copy. This can be useful for a move operation that is being used as a copy and delete /// operation (TSF_MOVE_AS_COPY_DELETE). /// TSF_COPY_CREATION_TIME = 0x10, /// Copy the last write time as part of the copy. TSF_COPY_WRITE_TIME = 0x20, /// Assign write, read, and delete permissions as share mode. TSF_USE_FULL_ACCESS = 0x40, /// Recycle on file delete, if possible. TSF_DELETE_RECYCLE_IF_POSSIBLE = 0x80, /// Hard link to the desired source (not required). This avoids a normal copy operation. TSF_COPY_HARD_LINK = 0x100, /// Copy the localized name. TSF_COPY_LOCALIZED_NAME = 0x200, /// Move as a copy and delete operation. TSF_MOVE_AS_COPY_DELETE = 0x400, /// Suspend Shell events. TSF_SUSPEND_SHELLEVENTS = 0x800 } /// Exposes methods that initialize, show, and get results from the common file dialog. /// [SuppressUnmanagedCodeSecurity] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("42f85136-db7e-439c-85f1-e4075d135fc8")] [PInvokeData("Shobjidl.h", MSDNShortId = "bb775966")] public interface IFileDialog : IModalWindow { /// Launches the modal window. /// The handle of the owner window. This value can be NULL. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code, including the following: /// HRESULT_FROM_WIN32(ERROR_CANCELLED) = The user closed the window by canceling the operation. /// [PreserveSig] new HRESULT Show([Optional] HWND parent); /// Sets the file types that the dialog can open or save. /// The number of elements in the array specified by rgFilterSpec. /// A pointer to an array of COMDLG_FILTERSPEC structures, each representing a file type. void SetFileTypes(uint cFileTypes, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] COMDLG_FILTERSPEC[] rgFilterSpec); /// Sets the file type that appears as selected in the dialog. /// /// The index of the file type in the file type array passed to IFileDialog::SetFileTypes in its cFileTypes parameter. Note that /// this is a one-based index, not zero-based. /// void SetFileTypeIndex(uint iFileType); /// Gets the currently selected file type. /// /// A UINT value that receives the index of the selected file type in the file type array passed to IFileDialog::SetFileTypes in /// its cFileTypes parameter. /// uint GetFileTypeIndex(); /// Assigns an event handler that listens for events coming from the dialog. /// A pointer to an IFileDialogEvents implementation that will receive events from the dialog. /// /// A DWORD value identifying this event handler. When the client is finished with the dialog, that client must call the /// IFileDialog::Unadvise method with this value. /// uint Advise(IFileDialogEvents pfde); /// Removes an event handler that was attached through the IFileDialog::Advise method. /// /// The DWORD value that represents the event handler. This value is obtained through the pdwCookie parameter of the /// IFileDialog::Advise method. /// void Unadvise(uint dwCookie); /// Sets flags to control the behavior of the dialog. /// One or more of the FILEOPENDIALOGOPTIONS values. void SetOptions(FILEOPENDIALOGOPTIONS fos); /// Gets the current flags that are set to control dialog behavior. /// /// When this method returns successfully, points to a value made up of one or more of the FILEOPENDIALOGOPTIONS values. /// FILEOPENDIALOGOPTIONS GetOptions(); /// Sets the folder used as a default if there is not a recently used folder value available. /// A pointer to the interface that represents the folder. void SetDefaultFolder(IShellItem psi); /// Sets a folder that is always selected when the dialog is opened, regardless of previous user action. /// A pointer to the interface that represents the folder. void SetFolder(IShellItem psi); /// /// Gets either the folder currently selected in the dialog, or, if the dialog is not currently displayed, the folder that is to /// be selected when the dialog is opened. /// /// The address of a pointer to the interface that represents the folder. IShellItem GetFolder(); /// Gets the user's current selection in the dialog. /// /// The address of a pointer to the interface that represents the item currently selected in the dialog. This item can be a file /// or folder selected in the view window, or something that the user has entered into the dialog's edit box. The latter case /// may require a parsing operation (cancelable by the user) that blocks the current thread. /// IShellItem GetCurrentSelection(); /// Sets the file name that appears in the File name edit box when that dialog box is opened. /// A pointer to the name of the file. void SetFileName([MarshalAs(UnmanagedType.LPWStr)] string pszName); /// Retrieves the text currently entered in the dialog's File name edit box. /// The address of a pointer to a buffer that, when this method returns successfully, receives the text. [return: MarshalAs(UnmanagedType.LPWStr)] string GetFileName(); /// Sets the title of the dialog. /// A pointer to a buffer that contains the title text. void SetTitle([MarshalAs(UnmanagedType.LPWStr)] string pszTitle); /// Sets the text of the Open or Save button. /// A pointer to a buffer that contains the button text. void SetOkButtonLabel([MarshalAs(UnmanagedType.LPWStr)] string pszText); /// Sets the text of the label next to the file name edit box. /// A pointer to a buffer that contains the label text. void SetFileNameLabel([MarshalAs(UnmanagedType.LPWStr)] string pszLabel); /// Gets the choice that the user made in the dialog. /// The address of a pointer to an IShellItem that represents the user's choice. IShellItem GetResult(); /// Adds a folder to the list of places available for the user to open or save items. /// /// A pointer to an IShellItem that represents the folder to be made available to the user. This can only be a folder. /// /// Specifies where the folder is placed within the list. void AddPlace(IShellItem psi, FDAP fdap); /// Sets the default extension to be added to file names. /// /// A pointer to a buffer that contains the extension text. This string should not include a leading period. For example, "jpg" /// is correct, while ".jpg" is not. /// void SetDefaultExtension([MarshalAs(UnmanagedType.LPWStr)] string pszDefaultExtension); /// Closes the dialog. /// The code that will be returned by Show to indicate that the dialog was closed before a selection was made. void Close([MarshalAs(UnmanagedType.Error)] HRESULT hr); /// Enables a calling application to associate a GUID with a dialog's persisted state. /// The GUID to associate with this dialog state. void SetClientGuid(in Guid guid); /// Instructs the dialog to clear all persisted state information. void ClearClientData(); /// Sets the filter. Deprecated. SetFilter is no longer available for use as of Windows 7. /// A pointer to the IShellItemFilter that is to be set. void SetFilter([MarshalAs(UnmanagedType.Interface)] object pFilter); } /// /// Extends the IFileDialog interface by providing methods that allow the caller to name a specific, restricted location that can be /// browsed in the common file dialog as well as to specify alternate text to display as a label on the Cancel button. /// /// [SuppressUnmanagedCodeSecurity] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("61744fc7-85b5-4791-a9b0-272276309b13")] [PInvokeData("Shobjidl.h", MinClient = PInvokeClient.Windows7)] public interface IFileDialog2 : IFileDialog { /// Launches the modal window. /// The handle of the owner window. This value can be NULL. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code, including the following: /// HRESULT_FROM_WIN32(ERROR_CANCELLED) = The user closed the window by canceling the operation. /// [PreserveSig] new HRESULT Show([Optional] HWND parent); /// Sets the file types that the dialog can open or save. /// The number of elements in the array specified by rgFilterSpec. /// A pointer to an array of COMDLG_FILTERSPEC structures, each representing a file type. new void SetFileTypes(uint cFileTypes, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] COMDLG_FILTERSPEC[] rgFilterSpec); /// Sets the file type that appears as selected in the dialog. /// /// The index of the file type in the file type array passed to IFileDialog::SetFileTypes in its cFileTypes parameter. Note that /// this is a one-based index, not zero-based. /// new void SetFileTypeIndex(uint iFileType); /// Gets the currently selected file type. /// /// A UINT value that receives the index of the selected file type in the file type array passed to IFileDialog::SetFileTypes in /// its cFileTypes parameter. /// new uint GetFileTypeIndex(); /// Assigns an event handler that listens for events coming from the dialog. /// A pointer to an IFileDialogEvents implementation that will receive events from the dialog. /// /// A DWORD value identifying this event handler. When the client is finished with the dialog, that client must call the /// IFileDialog::Unadvise method with this value. /// new uint Advise(IFileDialogEvents pfde); /// Removes an event handler that was attached through the IFileDialog::Advise method. /// /// The DWORD value that represents the event handler. This value is obtained through the pdwCookie parameter of the /// IFileDialog::Advise method. /// new void Unadvise(uint dwCookie); /// Sets flags to control the behavior of the dialog. /// One or more of the FILEOPENDIALOGOPTIONS values. new void SetOptions(FILEOPENDIALOGOPTIONS fos); /// Gets the current flags that are set to control dialog behavior. /// /// When this method returns successfully, points to a value made up of one or more of the FILEOPENDIALOGOPTIONS values. /// new FILEOPENDIALOGOPTIONS GetOptions(); /// Sets the folder used as a default if there is not a recently used folder value available. /// A pointer to the interface that represents the folder. new void SetDefaultFolder(IShellItem psi); /// Sets a folder that is always selected when the dialog is opened, regardless of previous user action. /// A pointer to the interface that represents the folder. new void SetFolder(IShellItem psi); /// /// Gets either the folder currently selected in the dialog, or, if the dialog is not currently displayed, the folder that is to /// be selected when the dialog is opened. /// /// The address of a pointer to the interface that represents the folder. new IShellItem GetFolder(); /// Gets the user's current selection in the dialog. /// /// The address of a pointer to the interface that represents the item currently selected in the dialog. This item can be a file /// or folder selected in the view window, or something that the user has entered into the dialog's edit box. The latter case /// may require a parsing operation (cancelable by the user) that blocks the current thread. /// new IShellItem GetCurrentSelection(); /// Sets the file name that appears in the File name edit box when that dialog box is opened. /// A pointer to the name of the file. new void SetFileName([MarshalAs(UnmanagedType.LPWStr)] string pszName); /// Retrieves the text currently entered in the dialog's File name edit box. /// The address of a pointer to a buffer that, when this method returns successfully, receives the text. [return: MarshalAs(UnmanagedType.LPWStr)] new string GetFileName(); /// Sets the title of the dialog. /// A pointer to a buffer that contains the title text. new void SetTitle([MarshalAs(UnmanagedType.LPWStr)] string pszTitle); /// Sets the text of the Open or Save button. /// A pointer to a buffer that contains the button text. new void SetOkButtonLabel([MarshalAs(UnmanagedType.LPWStr)] string pszText); /// Sets the text of the label next to the file name edit box. /// A pointer to a buffer that contains the label text. new void SetFileNameLabel([MarshalAs(UnmanagedType.LPWStr)] string pszLabel); /// Gets the choice that the user made in the dialog. /// The address of a pointer to an IShellItem that represents the user's choice. new IShellItem GetResult(); /// Adds a folder to the list of places available for the user to open or save items. /// /// A pointer to an IShellItem that represents the folder to be made available to the user. This can only be a folder. /// /// Specifies where the folder is placed within the list. new void AddPlace(IShellItem psi, FDAP fdap); /// Sets the default extension to be added to file names. /// /// A pointer to a buffer that contains the extension text. This string should not include a leading period. For example, "jpg" /// is correct, while ".jpg" is not. /// new void SetDefaultExtension([MarshalAs(UnmanagedType.LPWStr)] string pszDefaultExtension); /// Closes the dialog. /// The code that will be returned by Show to indicate that the dialog was closed before a selection was made. new void Close([MarshalAs(UnmanagedType.Error)] HRESULT hr); /// Enables a calling application to associate a GUID with a dialog's persisted state. /// The GUID to associate with this dialog state. new void SetClientGuid(in Guid guid); /// Instructs the dialog to clear all persisted state information. new void ClearClientData(); /// Sets the filter. Deprecated. SetFilter is no longer available for use as of Windows 7. /// A pointer to the IShellItemFilter that is to be set. new void SetFilter([MarshalAs(UnmanagedType.Interface)] object pFilter); /// Replaces the default text "Cancel" on the common file dialog's Cancel button. /// Pointer to a string that contains the new text to display on the button. void SetCancelButtonLabel([MarshalAs(UnmanagedType.LPWStr)] string pszLabel); /// /// Specifies a top-level location from which to begin browsing a namespace, for instance in the Save dialog's Browse folder /// option. Users cannot navigate above this location. /// /// Pointer to an IShellItem object that represents the navigation root. void SetNavigationRoot([MarshalAs(UnmanagedType.Interface)] IShellItem psi); } /// /// Exposes methods that allow an application to be notified of events that are related to controls that the application has added /// to a common file dialog. /// [SuppressUnmanagedCodeSecurity] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("36116642-D713-4b97-9B83-7484A9D00433")] [PInvokeData("Shobjidl.h")] public interface IFileDialogControlEvents { /// Called when [item selected]. /// The PFDC. /// The dw identifier control. /// The dw identifier item. /// [PreserveSig] HRESULT OnItemSelected(IFileDialogCustomize pfdc, uint dwIDCtl, uint dwIDItem); /// Called when [button clicked]. /// The PFDC. /// The dw identifier control. /// [PreserveSig] HRESULT OnButtonClicked(IFileDialogCustomize pfdc, uint dwIDCtl); /// Called when [check button toggled]. /// The PFDC. /// The dw identifier control. /// if set to true [b checked]. /// [PreserveSig] HRESULT OnCheckButtonToggled(IFileDialogCustomize pfdc, uint dwIDCtl, [MarshalAs(UnmanagedType.Bool)] bool bChecked); /// Called when [control activating]. /// The PFDC. /// The dw identifier control. /// [PreserveSig] HRESULT OnControlActivating(IFileDialogCustomize pfdc, uint dwIDCtl); } /// Exposes methods that allow an application to add controls to a common file dialog. [SuppressUnmanagedCodeSecurity] [ComImport, Guid("e6fdd21a-163f-4975-9c8c-a69f1ba37034"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IFileDialogCustomize { /// Enables a drop-down list on the Open or Save button in the dialog. /// The ID of the drop-down list. void EnableOpenDropDown(uint dwIDCtl); /// Adds a menu to the dialog. /// The ID of the menu to add. /// A pointer to a buffer that contains the menu name as a null-terminated Unicode string. void AddMenu(uint dwIDCtl, [MarshalAs(UnmanagedType.LPWStr)] string pszLabel); /// Adds a button to the dialog. /// The ID of the button to add. /// A pointer to a buffer that contains the button text as a null-terminated Unicode string. void AddPushButton(uint dwIDCtl, [MarshalAs(UnmanagedType.LPWStr)] string pszLabel); /// Adds a combo box to the dialog. /// The ID of the combo box to add. void AddComboBox(uint dwIDCtl); /// Adds an option button (also known as radio button) group to the dialog. /// The ID of the option button group to add. void AddRadioButtonList(uint dwIDCtl); /// Adds a check button (check box) to the dialog. /// The ID of the check button to add. /// A pointer to a buffer that contains the button text as a null-terminated Unicode string. /// A BOOL indicating the current state of the check button. TRUE if checked; FALSE otherwise. void AddCheckButton(uint dwIDCtl, [MarshalAs(UnmanagedType.LPWStr)] string pszLabel, [MarshalAs(UnmanagedType.Bool)] bool bChecked); /// Adds an edit box control to the dialog. /// The ID of the edit box to add. /// /// A pointer to a null-terminated Unicode string that provides the default text displayed in the edit box. /// void AddEditBox(uint dwIDCtl, [MarshalAs(UnmanagedType.LPWStr)] string pszText); /// Adds a separator to the dialog, allowing a visual separation of controls. /// The control ID of the separator. void AddSeparator(uint dwIDCtl); /// Adds text content to the dialog. /// The ID of the text to add. /// A pointer to a buffer that contains the text as a null-terminated Unicode string. void AddText(uint dwIDCtl, [MarshalAs(UnmanagedType.LPWStr)] string pszText); /// Sets the text associated with a control, such as button text or an edit box label. /// The ID of the control whose text is to be changed. /// A pointer to a buffer that contains the text as a null-terminated Unicode string. void SetControlLabel(uint dwIDCtl, [MarshalAs(UnmanagedType.LPWStr)] string pszLabel); /// Gets the current visibility and enabled states of a given control. /// The ID of the control in question. /// /// A variable that receives one or more values from the CDCONTROLSTATE enumeration that indicate the current state of the control. /// CDCONTROLSTATEF GetControlState(uint dwIDCtl); /// Sets the current visibility and enabled states of a given control. /// The ID of the control in question. /// One or more values from the CDCONTROLSTATE enumeration that indicate the current state of the control. void SetControlState(uint dwIDCtl, CDCONTROLSTATEF dwState); /// Gets the current text in an edit box control. /// The ID of the edit box. /// The address of a pointer to a buffer that receives the text as a null-terminated Unicode string. void GetEditBoxText(uint dwIDCtl, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(CoTaskMemStringMarshaler))] out string ppszText); /// Sets the text in an edit box control found in the dialog. /// The ID of the edit box. /// A pointer to a buffer that contains the text as a null-terminated Unicode string. void SetEditBoxText(uint dwIDCtl, [MarshalAs(UnmanagedType.LPWStr)] string pszText); /// Gets the current state of a check button (check box) in the dialog. /// The ID of the check box. /// A BOOL value that indicates whether the box is checked. TRUE means checked; FALSE, unchecked. [return: MarshalAs(UnmanagedType.Bool)] bool GetCheckButtonState(uint dwIDCtl); /// Sets the state of a check button (check box) in the dialog. /// The ID of the check box. /// A BOOL value that indicates whether the box is checked. TRUE means checked; FALSE, unchecked. void SetCheckButtonState(uint dwIDCtl, [MarshalAs(UnmanagedType.Bool)] bool bChecked); /// Adds an item to a container control in the dialog. /// The ID of the container control to which the item is to be added. /// The ID of the item. /// /// A pointer to a buffer that contains the item's text, which can be either a label or, in the case of a drop-down list, the /// item itself. This text is a null-terminated Unicode string. /// void AddControlItem(uint dwIDCtl, int dwIDItem, [MarshalAs(UnmanagedType.LPWStr)] string pszLabel); /// Removes an item from a container control in the dialog. /// The ID of the container control from which the item is to be removed. /// The ID of the item. void RemoveControlItem(uint dwIDCtl, int dwIDItem); /// Not implemented. /// void RemoveAllControlItems(uint dwIDCtl); /// Gets the current state of an item in a container control found in the dialog. /// The ID of the container control. /// The ID of the item. /// /// A pointer to a variable that receives one of more values from the CDCONTROLSTATE enumeration that indicate the current state /// of the control. /// CDCONTROLSTATEF GetControlItemState(uint dwIDCtl, int dwIDItem); /// Sets the current state of an item in a container control found in the dialog. /// The ID of the container control. /// The ID of the item. /// One or more values from the CDCONTROLSTATE enumeration that indicate the new state of the control. void SetControlItemState(uint dwIDCtl, int dwIDItem, CDCONTROLSTATEF dwState); /// Gets a particular item from specified container controls in the dialog. /// The ID of the container control. /// The ID of the item that the user selected in the control. uint GetSelectedControlItem(uint dwIDCtl); /// Sets the selected state of a particular item in an option button group or a combo box found in the dialog. /// The ID of the container control. /// The ID of the item to display as selected in the control. void SetSelectedControlItem(uint dwIDCtl, int dwIDItem); /// Declares a visual group in the dialog. Subsequent calls to any "add" method add those elements to this group. /// The ID of the visual group. /// /// A pointer to a buffer that contains text, as a null-terminated Unicode string, that appears next to the visual group. /// void StartVisualGroup(uint dwIDCtl, [MarshalAs(UnmanagedType.LPWStr)] string pszLabel); /// Stops the addition of elements to a visual group in the dialog. void EndVisualGroup(); /// Places a control in the dialog so that it stands out compared to other added controls. /// The ID of the control. void MakeProminent(uint dwIDCtl); } /// Exposes methods that allow notification of events within a common file dialog. [SuppressUnmanagedCodeSecurity] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("973510DB-7D7F-452B-8975-74A85828D354")] [PInvokeData("Shobjidl.h", MSDNShortId = "bb775876")] public interface IFileDialogEvents { /// Called just before the dialog is about to return with a result. /// A pointer to the interface that represents the dialog. /// /// Implementations should return S_OK to accept the current result in the dialog or S_FALSE to refuse it. In the case of /// S_FALSE, the dialog should remain open. /// /// /// When this method is called, the IFileDialog::GetResult and GetResults methods can be called. /// /// The application can use this callback method to perform additional validation before the dialog closes, or to prevent the /// dialog from closing. If the application prevents the dialog from closing, it should display a UI to indicate a cause. To /// obtain a parent HWND for the UI, obtain the IOleWindow interface through IFileDialog::QueryInterface and call IOleWindow::GetWindow. /// /// An application can also use this method to perform all of its work surrounding the opening or saving of files. /// [PreserveSig] HRESULT OnFileOk(IFileDialog pfd); /// /// Called before IFileDialogEvents::OnFolderChange. This allows the implementer to stop navigation to a particular location. /// /// A pointer to the interface that represents the dialog. /// A pointer to an interface that represents the folder to which the dialog is about to navigate. /// /// Returns S_OK if successful, or an error value otherwise. A return value of S_OK or E_NOTIMPL indicates that the folder /// change can proceed. /// /// /// The calling application can call IFileDialog::SetFolder during this callback to redirect navigation to an alternate folder. /// The actual navigation does not occur until IFileDialogEvents::OnFolderChanging has returned. /// /// If the calling application simply prevents navigation to a particular folder, UI should be displayed with an explanation of /// the restriction. To obtain a parent HWND for the UI, obtain the IOleWindow interface through IFileDialog and call IOleWindow::GetWindow. /// /// [PreserveSig] HRESULT OnFolderChanging(IFileDialog pfd, IShellItem psiFolder); /// Called when the user navigates to a new folder. /// A pointer to the interface that represents the dialog. /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. [PreserveSig] HRESULT OnFolderChange(IFileDialog pfd); /// Called when the user changes the selection in the dialog's view. /// A pointer to the interface that represents the dialog. /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. [PreserveSig] HRESULT OnSelectionChange(IFileDialog pfd); /// Enables an application to respond to sharing violations that arise from Open or Save operations. /// A pointer to the interface that represents the dialog. /// A pointer to the interface that represents the item that has the sharing violation. /// /// A pointer to a value from the FDE_SHAREVIOLATION_RESPONSE enumeration indicating the response to the sharing violation. /// /// /// The implementer should return E_NOTIMPL if this method is not implemented; S_OK or an appropriate error code otherwise. /// /// /// The FOS_SHAREAWARE flag must be set through IFileDialog::SetOptions before this method is called. /// /// A sharing violation could possibly arise when the application attempts to open a file, because the file could have been /// locked between the time that the dialog tested it and the application opened it. /// /// [PreserveSig] HRESULT OnShareViolation(IFileDialog pfd, IShellItem psi, out FDE_SHAREVIOLATION_RESPONSE pResponse); /// Called when the dialog is opened to notify the application of the initial chosen filetype. /// A pointer to the interface that represents the dialog. /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// This method is called when the dialog is opened to notify the application of the initially chosen filetype. If the /// application has code in IFileDialogEvents that responds to type changes, it can respond to the type. For example, it could /// hide certain controls. The application controls the initial file type and could do its own checks, so this method is /// provided as a convenience. /// [PreserveSig] HRESULT OnTypeChange(IFileDialog pfd); /// Called from the save dialog when the user chooses to overwrite a file. /// A pointer to the interface that represents the dialog. /// A pointer to the interface that represents the item that will be overwritten. /// /// A pointer to a value from the FDE_OVERWRITE_RESPONSE enumeration indicating the response to the potential overwrite action. /// /// /// The implementer should return E_NOTIMPL if this method is not implemented; S_OK or an appropriate error code otherwise. /// /// The FOS_OVERWRITEPROMPT flag must be set through IFileDialog::SetOptions before this method is called. [PreserveSig] HRESULT OnOverwrite(IFileDialog pfd, IShellItem psi, out FDE_SHAREVIOLATION_RESPONSE pResponse); } /// Extends the IFileDialog interface by adding methods specific to the open dialog. /// [SuppressUnmanagedCodeSecurity] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("d57c7288-d4ad-4768-be02-9d969532d960"), CoClass(typeof(CFileOpenDialog))] [PInvokeData("Shobjidl.h", MSDNShortId = "bb775834")] public interface IFileOpenDialog : IFileDialog { /// Launches the modal window. /// The handle of the owner window. This value can be NULL. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code, including the following: /// HRESULT_FROM_WIN32(ERROR_CANCELLED) = The user closed the window by canceling the operation. /// [PreserveSig] new HRESULT Show([Optional] HWND parent); /// Sets the file types that the dialog can open or save. /// The number of elements in the array specified by rgFilterSpec. /// A pointer to an array of COMDLG_FILTERSPEC structures, each representing a file type. new void SetFileTypes(uint cFileTypes, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] COMDLG_FILTERSPEC[] rgFilterSpec); /// Sets the file type that appears as selected in the dialog. /// /// The index of the file type in the file type array passed to IFileDialog::SetFileTypes in its cFileTypes parameter. Note that /// this is a one-based index, not zero-based. /// new void SetFileTypeIndex(uint iFileType); /// Gets the currently selected file type. /// /// A UINT value that receives the index of the selected file type in the file type array passed to IFileDialog::SetFileTypes in /// its cFileTypes parameter. /// new uint GetFileTypeIndex(); /// Assigns an event handler that listens for events coming from the dialog. /// A pointer to an IFileDialogEvents implementation that will receive events from the dialog. /// /// A DWORD value identifying this event handler. When the client is finished with the dialog, that client must call the /// IFileDialog::Unadvise method with this value. /// new uint Advise(IFileDialogEvents pfde); /// Removes an event handler that was attached through the IFileDialog::Advise method. /// /// The DWORD value that represents the event handler. This value is obtained through the pdwCookie parameter of the /// IFileDialog::Advise method. /// new void Unadvise(uint dwCookie); /// Sets flags to control the behavior of the dialog. /// One or more of the FILEOPENDIALOGOPTIONS values. new void SetOptions(FILEOPENDIALOGOPTIONS fos); /// Gets the current flags that are set to control dialog behavior. /// /// When this method returns successfully, points to a value made up of one or more of the FILEOPENDIALOGOPTIONS values. /// new FILEOPENDIALOGOPTIONS GetOptions(); /// Sets the folder used as a default if there is not a recently used folder value available. /// A pointer to the interface that represents the folder. new void SetDefaultFolder(IShellItem psi); /// Sets a folder that is always selected when the dialog is opened, regardless of previous user action. /// A pointer to the interface that represents the folder. new void SetFolder(IShellItem psi); /// /// Gets either the folder currently selected in the dialog, or, if the dialog is not currently displayed, the folder that is to /// be selected when the dialog is opened. /// /// The address of a pointer to the interface that represents the folder. new IShellItem GetFolder(); /// Gets the user's current selection in the dialog. /// /// The address of a pointer to the interface that represents the item currently selected in the dialog. This item can be a file /// or folder selected in the view window, or something that the user has entered into the dialog's edit box. The latter case /// may require a parsing operation (cancelable by the user) that blocks the current thread. /// new IShellItem GetCurrentSelection(); /// Sets the file name that appears in the File name edit box when that dialog box is opened. /// A pointer to the name of the file. new void SetFileName([MarshalAs(UnmanagedType.LPWStr)] string pszName); /// Retrieves the text currently entered in the dialog's File name edit box. /// The address of a pointer to a buffer that, when this method returns successfully, receives the text. [return: MarshalAs(UnmanagedType.LPWStr)] new string GetFileName(); /// Sets the title of the dialog. /// A pointer to a buffer that contains the title text. new void SetTitle([MarshalAs(UnmanagedType.LPWStr)] string pszTitle); /// Sets the text of the Open or Save button. /// A pointer to a buffer that contains the button text. new void SetOkButtonLabel([MarshalAs(UnmanagedType.LPWStr)] string pszText); /// Sets the text of the label next to the file name edit box. /// A pointer to a buffer that contains the label text. new void SetFileNameLabel([MarshalAs(UnmanagedType.LPWStr)] string pszLabel); /// Gets the choice that the user made in the dialog. /// The address of a pointer to an IShellItem that represents the user's choice. new IShellItem GetResult(); /// Adds a folder to the list of places available for the user to open or save items. /// /// A pointer to an IShellItem that represents the folder to be made available to the user. This can only be a folder. /// /// Specifies where the folder is placed within the list. new void AddPlace(IShellItem psi, FDAP fdap); /// Sets the default extension to be added to file names. /// /// A pointer to a buffer that contains the extension text. This string should not include a leading period. For example, "jpg" /// is correct, while ".jpg" is not. /// new void SetDefaultExtension([MarshalAs(UnmanagedType.LPWStr)] string pszDefaultExtension); /// Closes the dialog. /// The code that will be returned by Show to indicate that the dialog was closed before a selection was made. new void Close([MarshalAs(UnmanagedType.Error)] HRESULT hr); /// Enables a calling application to associate a GUID with a dialog's persisted state. /// The GUID to associate with this dialog state. new void SetClientGuid(in Guid guid); /// Instructs the dialog to clear all persisted state information. new void ClearClientData(); /// Sets the filter. Deprecated. SetFilter is no longer available for use as of Windows 7. /// A pointer to the IShellItemFilter that is to be set. new void SetFilter([MarshalAs(UnmanagedType.Interface)] object pFilter); /// Gets the user's choices in a dialog that allows multiple selection. /// The address of a pointer to an IShellItemArray through which the items selected in the dialog can be accessed. IShellItemArray GetResults(); /// /// Gets the currently selected items in the dialog. These items may be items selected in the view, or text selected in the file /// name edit box. /// /// The address of a pointer to an IShellItemArray through which the selected items can be accessed. IShellItemArray GetSelectedItems(); } /// /// Exposes methods that provide a rich notification system used by callers of IFileOperation to monitor the details of the /// operations they are performing through that interface. /// [ComImport, Guid("04b0f1a7-9490-44bc-96e1-4296a31252e2"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [PInvokeData("Shobjidl.h", MSDNShortId = "bb775722")] public interface IFileOperationProgressSink { /// Performs caller-implemented actions before any specific file operations are performed. [PreserveSig] HRESULT StartOperations(); /// Performs caller-implemented actions after the last operation performed by the call to IFileOperation is complete. /// /// The return value of the final operation. Note that this is not the HRESULT returned by one of the IFileOperation methods, /// which simply queue the operations. Instead, this is the result of the actual operation, such as copy, delete, or move. /// [PreserveSig] HRESULT FinishOperations(HRESULT hrResult); /// Performs caller-implemented actions before the rename process for each item begins. /// /// bitwise value that contains flags that control the operation. See TRANSFER_SOURCE_FLAGS for flag descriptions. /// /// Pointer to an IShellItem that specifies the item to be renamed. /// Pointer to the new display name of the item. This is a null-terminated, Unicode string. [PreserveSig] HRESULT PreRenameItem(TRANSFER_SOURCE_FLAGS dwFlags, IShellItem psiItem, [MarshalAs(UnmanagedType.LPWStr)] string pszNewName); /// Performs caller-implemented actions after the rename process for each item is complete. /// /// bitwise value that contains flags that were used during the rename operation. Some values can be set or changed during the /// rename operation. See TRANSFER_SOURCE_FLAGS for flag descriptions. /// /// Pointer to an IShellItem that specifies the item before it was renamed. /// /// Pointer to the new display name of the item. This is a null-terminated, Unicode string. Note that this might not be the name /// that you asked for, given collisions and other naming rules. /// /// /// The return value of the rename operation. Note that this is not the HRESULT returned by RenameItem, which simply queues the /// rename operation. Instead, this is the result of the actual rename operation. /// /// Pointer to an IShellItem that represents the item with its new name. [PreserveSig] HRESULT PostRenameItem(TRANSFER_SOURCE_FLAGS dwFlags, IShellItem psiItem, [MarshalAs(UnmanagedType.LPWStr)] string pszNewName, HRESULT hrRename, IShellItem psiNewlyCreated); /// Performs caller-implemented actions before the move process for each item begins. /// /// bitwise value that contains flags that control the operation. See TRANSFER_SOURCE_FLAGS for flag descriptions. /// /// Pointer to an IShellItem that specifies the item to be moved. /// /// Pointer to an IShellItem that specifies the destination folder to contain the moved item. /// /// /// Pointer to a new name for the item in its new location. This is a null-terminated Unicode string and can be NULL. If NULL, /// the name of the destination item is the same as the source. /// [PreserveSig] HRESULT PreMoveItem(TRANSFER_SOURCE_FLAGS dwFlags, IShellItem psiItem, IShellItem psiDestinationFolder, [MarshalAs(UnmanagedType.LPWStr)] string? pszNewName); /// Performs caller-implemented actions after the move process for each item is complete. /// /// bitwise value that contains flags that were used during the move operation. Some values can be set or changed during the /// move operation. See TRANSFER_SOURCE_FLAGS for flag descriptions. /// /// Pointer to an IShellItem that specifies the source item. /// /// Pointer to an IShellItem that specifies the destination folder that contains the moved item. /// /// /// Pointer to the name that was given to the item after it was moved. This is a null-terminated Unicode string. Note that this /// might not be the name that you asked for, given collisions and other naming rules. /// /// /// The return value of the move operation. Note that this is not the HRESULT returned by MoveItem, which simply queues the move /// operation. Instead, this is the result of the actual move. /// /// Pointer to an IShellItem that represents the moved item in its new location. [PreserveSig] HRESULT PostMoveItem(TRANSFER_SOURCE_FLAGS dwFlags, IShellItem psiItem, IShellItem psiDestinationFolder, [MarshalAs(UnmanagedType.LPWStr)] string pszNewName, HRESULT hrMove, IShellItem psiNewlyCreated); /// Performs caller-implemented actions before the copy process for each item begins. /// /// bitwise value that contains flags that control the operation. See TRANSFER_SOURCE_FLAGS for flag descriptions. /// /// Pointer to an IShellItem that specifies the source item. /// /// Pointer to an IShellItem that specifies the destination folder to contain the copy of the item. /// /// /// Pointer to a new name for the item after it has been copied. This is a null-terminated Unicode string and can be NULL. If /// NULL, the name of the destination item is the same as the source. /// [PreserveSig] HRESULT PreCopyItem(TRANSFER_SOURCE_FLAGS dwFlags, IShellItem psiItem, IShellItem psiDestinationFolder, [MarshalAs(UnmanagedType.LPWStr)] string? pszNewName); /// Performs caller-implemented actions after the copy process for each item is complete. /// /// bitwise value that contains flags that were used during the copy operation. Some values can be set or changed during the /// copy operation. See TRANSFER_SOURCE_FLAGS for flag descriptions. /// /// Pointer to an IShellItem that specifies the source item. /// /// Pointer to an IShellItem that specifies the destination folder to which the item was copied. /// /// /// Pointer to the new name that was given to the item after it was copied. This is a null-terminated Unicode string. Note that /// this might not be the name that you asked for, given collisions and other naming rules. /// /// /// The return value of the copy operation. Note that this is not the HRESULT returned by CopyItem, which simply queues the copy /// operation. Instead, this is the result of the actual copy. /// /// Pointer to an IShellItem that represents the new copy of the item. [PreserveSig] HRESULT PostCopyItem(TRANSFER_SOURCE_FLAGS dwFlags, IShellItem psiItem, IShellItem psiDestinationFolder, [MarshalAs(UnmanagedType.LPWStr)] string pszNewName, HRESULT hrCopy, IShellItem psiNewlyCreated); /// Performs caller-implemented actions before the delete process for each item begins. /// /// bitwise value that contains flags that control the operation. See TRANSFER_SOURCE_FLAGS for flag descriptions. /// /// Pointer to an IShellItem that specifies the item to be deleted. [PreserveSig] HRESULT PreDeleteItem(TRANSFER_SOURCE_FLAGS dwFlags, IShellItem psiItem); /// Performs caller-implemented actions after the delete process for each item is complete. /// /// bitwise value that contains flags that were used during the delete operation. Some values can be set or changed during the /// delete operation. See TRANSFER_SOURCE_FLAGS for flag descriptions. /// /// Pointer to an IShellItem that specifies the item that was deleted. /// /// The return value of the delete operation. Note that this is not the HRESULT returned by DeleteItem, which simply queues the /// delete operation. Instead, this is the result of the actual deletion. /// /// /// A pointer to an IShellItem that specifies the deleted item, now in the Recycle Bin. If the item was fully deleted, this /// value is NULL. /// [PreserveSig] HRESULT PostDeleteItem(TRANSFER_SOURCE_FLAGS dwFlags, IShellItem psiItem, HRESULT hrDelete, IShellItem? psiNewlyCreated); /// Performs caller-implemented actions before the process to create a new item begins. /// /// bitwise value that contains flags that control the operation. See TRANSFER_SOURCE_FLAGS for flag descriptions. /// /// /// Pointer to an IShellItem that specifies the destination folder that will contain the new item. /// /// /// Pointer to the file name of the new item, for instance Newfile.txt. This is a null-terminated, Unicode string. /// [PreserveSig] HRESULT PreNewItem(TRANSFER_SOURCE_FLAGS dwFlags, IShellItem psiDestinationFolder, [MarshalAs(UnmanagedType.LPWStr)] string pszNewName); /// Performs caller-implemented actions after the new item is created. /// /// bitwise value that contains flags that were used during the creation operation. Some values can be set or changed during the /// creation operation. See TRANSFER_SOURCE_FLAGS for flag descriptions. /// /// /// Pointer to an IShellItem that specifies the destination folder to which the new item was added. /// /// /// Pointer to the file name of the new item, for instance Newfile.txt. This is a null-terminated, Unicode string. /// /// /// Pointer to the name of the template file (for example Excel9.xls) that the new item is based on, stored in one of the /// following locations: /// /// /// CSIDL_COMMON_TEMPLATES. The default path for this folder is %ALLUSERSPROFILE%\Templates. /// /// /// CSIDL_TEMPLATES. The default path for this folder is %USERPROFILE%\Templates. /// /// /// %SystemRoot%\shellnew /// /// /// /// This is a null-terminated, Unicode string used to specify an existing file of the same type as the new file, containing the /// minimal content that an application wants to include in any new file. /// /// This parameter is normally NULL to specify a new, blank file. /// /// The file attributes applied to the new item. One or more of the values found at GetFileAttributes. /// /// The return value of the creation operation. Note that this is not the HRESULT returned by NewItem, which simply queues the /// creation operation. Instead, this is the result of the actual creation. /// /// Pointer to an IShellItem that represents the new item. [PreserveSig] HRESULT PostNewItem(TRANSFER_SOURCE_FLAGS dwFlags, IShellItem psiDestinationFolder, [MarshalAs(UnmanagedType.LPWStr)] string pszNewName, [MarshalAs(UnmanagedType.LPWStr), Optional] string? pszTemplateName, uint dwFileAttributes, HRESULT hrNew, IShellItem psiNewItem); /// Updates the progress. /// The i work total. /// The i work so far. [PreserveSig] HRESULT UpdateProgress(uint iWorkTotal, uint iWorkSoFar); /// Resets the timer. [Obsolete("This method is not supported.")] [PreserveSig] HRESULT ResetTimer(); /// Pauses the timer. [Obsolete("This method is not supported.")] [PreserveSig] HRESULT PauseTimer(); /// Resumes the timer. [Obsolete("This method is not supported.")] [PreserveSig] HRESULT ResumeTimer(); } /// /// Extends the IFileDialog interface by adding methods specific to the save dialog, which include those that provide support for /// the collection of metadata to be persisted with the file. /// /// [SuppressUnmanagedCodeSecurity] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("84bccd23-5fde-4cdb-aea4-af64b83d78ab"), CoClass(typeof(CFileSaveDialog))] [PInvokeData("Shobjidl.h", MSDNShortId = "bb775688")] public interface IFileSaveDialog : IFileDialog { /// Launches the modal window. /// The handle of the owner window. This value can be NULL. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code, including the following: /// HRESULT_FROM_WIN32(ERROR_CANCELLED) = The user closed the window by canceling the operation. /// [PreserveSig] new HRESULT Show([Optional] HWND parent); /// Sets the file types that the dialog can open or save. /// The number of elements in the array specified by rgFilterSpec. /// A pointer to an array of COMDLG_FILTERSPEC structures, each representing a file type. new void SetFileTypes(uint cFileTypes, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] COMDLG_FILTERSPEC[] rgFilterSpec); /// Sets the file type that appears as selected in the dialog. /// /// The index of the file type in the file type array passed to IFileDialog::SetFileTypes in its cFileTypes parameter. Note that /// this is a one-based index, not zero-based. /// new void SetFileTypeIndex(uint iFileType); /// Gets the currently selected file type. /// /// A UINT value that receives the index of the selected file type in the file type array passed to IFileDialog::SetFileTypes in /// its cFileTypes parameter. /// new uint GetFileTypeIndex(); /// Assigns an event handler that listens for events coming from the dialog. /// A pointer to an IFileDialogEvents implementation that will receive events from the dialog. /// /// A DWORD value identiying this event handler. When the client is finished with the dialog, that client must call the /// IFileDialog::Unadvise method with this value. /// new uint Advise(IFileDialogEvents pfde); /// Removes an event handler that was attached through the IFileDialog::Advise method. /// /// The DWORD value that represents the event handler. This value is obtained through the pdwCookie parameter of the /// IFileDialog::Advise method. /// new void Unadvise(uint dwCookie); /// Sets flags to control the behavior of the dialog. /// One or more of the FILEOPENDIALOGOPTIONS values. new void SetOptions(FILEOPENDIALOGOPTIONS fos); /// Gets the current flags that are set to control dialog behavior. /// /// When this method returns successfully, points to a value made up of one or more of the FILEOPENDIALOGOPTIONS values. /// new FILEOPENDIALOGOPTIONS GetOptions(); /// Sets the folder used as a default if there is not a recently used folder value available. /// A pointer to the interface that represents the folder. new void SetDefaultFolder(IShellItem psi); /// Sets a folder that is always selected when the dialog is opened, regardless of previous user action. /// A pointer to the interface that represents the folder. new void SetFolder(IShellItem psi); /// /// Gets either the folder currently selected in the dialog, or, if the dialog is not currently displayed, the folder that is to /// be selected when the dialog is opened. /// /// The address of a pointer to the interface that represents the folder. new IShellItem GetFolder(); /// Gets the user's current selection in the dialog. /// /// The address of a pointer to the interface that represents the item currently selected in the dialog. This item can be a file /// or folder selected in the view window, or something that the user has entered into the dialog's edit box. The latter case /// may require a parsing operation (cancelable by the user) that blocks the current thread. /// new IShellItem GetCurrentSelection(); /// Sets the file name that appears in the File name edit box when that dialog box is opened. /// A pointer to the name of the file. new void SetFileName([MarshalAs(UnmanagedType.LPWStr)] string pszName); /// Retrieves the text currently entered in the dialog's File name edit box. /// The address of a pointer to a buffer that, when this method returns successfully, receives the text. [return: MarshalAs(UnmanagedType.LPWStr)] new string GetFileName(); /// Sets the title of the dialog. /// A pointer to a buffer that contains the title text. new void SetTitle([MarshalAs(UnmanagedType.LPWStr)] string pszTitle); /// Sets the text of the Open or Save button. /// A pointer to a buffer that contains the button text. new void SetOkButtonLabel([MarshalAs(UnmanagedType.LPWStr)] string pszText); /// Sets the text of the label next to the file name edit box. /// A pointer to a buffer that contains the label text. new void SetFileNameLabel([MarshalAs(UnmanagedType.LPWStr)] string pszLabel); /// Gets the choice that the user made in the dialog. /// The address of a pointer to an IShellItem that represents the user's choice. new IShellItem GetResult(); /// Adds a folder to the list of places available for the user to open or save items. /// /// A pointer to an IShellItem that represents the folder to be made available to the user. This can only be a folder. /// /// Specifies where the folder is placed within the list. new void AddPlace(IShellItem psi, FDAP fdap); /// Sets the default extension to be added to file names. /// /// A pointer to a buffer that contains the extension text. This string should not include a leading period. For example, "jpg" /// is correct, while ".jpg" is not. /// new void SetDefaultExtension([MarshalAs(UnmanagedType.LPWStr)] string pszDefaultExtension); /// Closes the dialog. /// The code that will be returned by Show to indicate that the dialog was closed before a selection was made. new void Close([MarshalAs(UnmanagedType.Error)] HRESULT hr); /// Enables a calling application to associate a GUID with a dialog's persisted state. /// The GUID to associate with this dialog state. new void SetClientGuid(in Guid guid); /// Instructs the dialog to clear all persisted state information. new void ClearClientData(); /// Sets the filter. Deprecated. SetFilter is no longer available for use as of Windows 7. /// A pointer to the IShellItemFilter that is to be set. new void SetFilter([MarshalAs(UnmanagedType.Interface)] object pFilter); /// Sets an item to be used as the initial entry in a Save As dialog. /// Pointer to an IShellItem that represents the item. void SetSaveAsItem(IShellItem psi); /// Provides a property store that defines the default values to be used for the item being saved. /// Pointer to the interface that represents the property store that contains the associated metadata. void SetProperties(PropSys.IPropertyStore pStore); /// Specifies which properties will be collected in the save dialog. /// Pointer to the interface that represents the list of properties to collect. This parameter can be NULL. /// /// TRUE to show default properties for the currently selected filetype in addition to the properties specified by pList. FALSE /// to show only properties specified by pList. /// void SetCollectedProperties(PropSys.IPropertyDescriptionList? pList, [MarshalAs(UnmanagedType.Bool)] bool fAppendDefault); /// Retrieves the set of property values for a saved item or an item in the process of being saved. /// Address of a pointer to an IPropertyStore that receives the property values. PropSys.IPropertyStore GetProperties(); /// Applies a set of properties to an item using the Shell's copy engine. /// /// Pointer to the IShellItem that represents the file being saved. This is usually the item retrieved by GetResult. /// /// /// Pointer to the IPropertyStore that represents the property values to be applied to the file. This can be the property store /// returned by IFileSaveDialog::GetProperties. /// /// The handle of the application window. /// /// Pointer to an optional IFileOperationProgressSink that the calling application can use if they want to be notified of the /// progress of the property stamping. This value may be NULL. /// void ApplyProperties(IShellItem psi, PropSys.IPropertyStore pStore, HWND hwnd, IFileOperationProgressSink? pSink); } /// Exposed methods to handle file sync operations between a local copy and a server copy of a file. // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ifilesyncmergehandler [ComImport, Guid("d97b5aac-c792-433c-975d-35c4eadc7a9d"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IFileSyncMergeHandler { /// Merges changes between the local copy and server copy of a file. /// /// Type: LPCWSTR /// A pointer to a string containing the path to the local copy of the file. /// /// /// Type: LPCWSTR /// A pointer to a string containing the network path to the server copy of the file. /// /// /// Type: MERGE_UPDATE_STATUS* /// When this method returns, contains a pointer to one of the following values indicating status of the merge process. /// MUS_COMPLETE /// Indicates that the process has completed successfully. /// MUS_USERINPUTNEEDED /// Indicates that additional input is required by the user for the process to complete. /// MUS_FAILED /// Indicates that the process has failed. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ifilesyncmergehandler-merge HRESULT Merge( // LPCWSTR localFilePath, LPCWSTR serverFilePath, MERGE_UPDATE_STATUS *updateStatus ); void Merge([MarshalAs(UnmanagedType.LPWStr)] string localFilePath, [MarshalAs(UnmanagedType.LPWStr)] string serverFilePath, out MERGE_UPDATE_STATUS updateStatus); /// Displays a UI to resolve conflicts between the local copy and server copy of a file. /// /// Type: LPCWSTR /// The path of the file with the merge conflict. /// /// /// Type: HMONITOR /// Indicates the monitor on which to display the UI. /// // https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ifilesyncmergehandler-showresolveconflictuiasync // HRESULT ShowResolveConflictUIAsync( LPCWSTR localFilePath, HMONITOR monitorToDisplayOn ); void ShowResolveConflictUIAsync([MarshalAs(UnmanagedType.LPWStr)] string localFilePath, HMONITOR monitorToDisplayOn); } /// Exposes a method that represents a modal window. This interface is used in the Windows XP Passport Wizard. [SuppressUnmanagedCodeSecurity] [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("b4db1657-70d7-485e-8e3e-6fcb5a5c1802")] [PInvokeData("Shobjidl.h", MSDNShortId = "bb761686")] public interface IModalWindow { /// Launches the modal window. /// The handle of the owner window. This value can be NULL. /// /// If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code, including the following: /// HRESULT_FROM_WIN32(ERROR_CANCELLED) = The user closed the window by cancelling the operation. /// [PreserveSig] HRESULT Show([Optional] HWND parent); } /// Used generically to filter elements. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] [PInvokeData("Shtypes.h", MSDNShortId = "bb773221")] public struct COMDLG_FILTERSPEC { /// A pointer to a buffer that contains the friendly name of the filter. public string pszName; /// A pointer to a buffer that contains the filter pattern. public string pszSpec; } /// Class interface for ITaskbarList and derivatives. [ComImport, Guid("DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7"), ClassInterface(ClassInterfaceType.None)] public class CFileOpenDialog { } /// Class interface for ITaskbarList and derivatives. [ComImport, Guid("C0B4E2F3-BA21-4773-8DBA-335EC946EB8B"), ClassInterface(ClassInterfaceType.None)] public class CFileSaveDialog { } }