FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list Topic is solved
-
- Posts: 77
- Joined: 18 Apr 2018, 08:49
FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list
Hello to you all, I have researched all around the autohotkey forum about workaround on "FileSelectFile" to support this type of cases:
at dialog's "files of type" drop-down list, there will be multiple filters like this : text(*.txt)|Document(*.doc)|Music(*.mp3)|Video(*.mp4)
So at the FileSelectFile dialog's "files of type" drop-down list, when left clicking it, it will show something like this:
text(*.txt)
Document(*.doc)
Music(*.mp3)
Video(*.mp4)
But the Problem is FileSelectFile only supports "One Line" of Filter, so I can't do the thing above and it only show this:
text(*.txt)
All Files(*.*)
I can't have the freedom to choose my own filters with this limitation can someone create a function for me the works ""EXACTLY" like FileSelectFile but supports "Multiple-Filters" for 64 bit architecture
I have seen derRaphael's CmnDlg Function, but it does not work on 64 bit computer, Also majkinetor's Dlg 5.01 function does not support 64-bit computer.
I Hope you call can help me, it will be helpful to all people that uses 64-bit. Thanks!
at dialog's "files of type" drop-down list, there will be multiple filters like this : text(*.txt)|Document(*.doc)|Music(*.mp3)|Video(*.mp4)
So at the FileSelectFile dialog's "files of type" drop-down list, when left clicking it, it will show something like this:
text(*.txt)
Document(*.doc)
Music(*.mp3)
Video(*.mp4)
But the Problem is FileSelectFile only supports "One Line" of Filter, so I can't do the thing above and it only show this:
text(*.txt)
All Files(*.*)
I can't have the freedom to choose my own filters with this limitation can someone create a function for me the works ""EXACTLY" like FileSelectFile but supports "Multiple-Filters" for 64 bit architecture
I have seen derRaphael's CmnDlg Function, but it does not work on 64 bit computer, Also majkinetor's Dlg 5.01 function does not support 64-bit computer.
I Hope you call can help me, it will be helpful to all people that uses 64-bit. Thanks!
Developer of AJOM's DOTA2 MOD Master, Easiest way to MOD your DOTA2 without the use of internet . I created this program using Autohotkey thats why I love Autohotkey and the community!
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
Re: FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list
Those functions are old and deprecated by Microsoft. I recommend using the IFileOpenDialog interface.
Related: https://autohotkey.com/boards/viewtopic ... 6&p=231331.
Related: https://autohotkey.com/boards/viewtopic ... 6&p=231331.
-
- Posts: 77
- Joined: 18 Apr 2018, 08:49
Re: FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list
Can you translate this code into the function you are talking about:Flipeador wrote:Those functions are old and deprecated by Microsoft. I recommend using the IFileOpenDialog interface.
Related: https://autohotkey.com/boards/viewtopic ... 6&p=231331.
FileSelectFile,invfile,S24,,save the file with your chosen extension,text(*.txt)|Document(*.doc)|Music(*.mp3)|Video(*.mp4)
I currently have problems:
1) I don't use ahk v2. I am currently at ahk v1
2)I don't know how to use your function to manipulate my desire, a basic demonstration that is exactly look like fileselectfile feature will do it I guess?
Developer of AJOM's DOTA2 MOD Master, Easiest way to MOD your DOTA2 without the use of internet . I created this program using Autohotkey thats why I love Autohotkey and the community!
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
Re: FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list
I'm not at home so I can not right now. My function does not have the same parameters order as FileSelectFile does. It also has two parameters that FileSelectFile does not have.
In the description of each function there is a clear example of use. If you use v1, maybe someone else can rewrite it. If nobody does, I'll try to make it v1 when I can, over the weekend.
In the description of each function there is a clear example of use. If you use v1, maybe someone else can rewrite it. If nobody does, I'll try to make it v1 when I can, over the weekend.
-
- Posts: 77
- Joined: 18 Apr 2018, 08:49
Re: FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list
I will be waiting my friend Cheers!Flipeador wrote:I'm not at home so I can not right now. My function does not have the same parameters order as FileSelectFile does. It also has two parameters that FileSelectFile does not have.
In the description of each function there is a clear example of use. If you use v1, maybe someone else can rewrite it. If nobody does, I'll try to make it v1 when I can, over the weekend.
Developer of AJOM's DOTA2 MOD Master, Easiest way to MOD your DOTA2 without the use of internet . I created this program using Autohotkey thats why I love Autohotkey and the community!
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
Re: FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list
Minimum requirements: AutoHotkey 1.1.29.01, Windows Vista.
Required functions:
ChooseFolder
ChooseFile
SaveFile
Required functions:
Code: Select all
DirExist(DirName)
{
loop Files, % DirName, D
return A_LoopFileAttrib
}
StrPutVar(string, ByRef var, encoding)
{
; Ensure capacity.
VarSetCapacity( var, StrPut(string, encoding)
; StrPut returns char count, but VarSetCapacity needs bytes.
* ((encoding="utf-16"||encoding="cp1200") ? 2 : 1) )
; Copy or convert the string.
return StrPut(string, &var, encoding)
} ; https://www.autohotkey.com/docs/commands/StrPut.htm#Examples
ChooseFolder
Code: Select all
/*
Displays a standard dialog that allows the user to select folder(s).
Parameters:
Owner / Title:
The identifier of the window that owns this dialog. This value can be zero.
An Array with the identifier of the owner window and the title. If the title is an empty string, it is set to the default.
StartingFolder:
The path to the directory selected by default. If the directory does not exist, it searches in higher directories.
CustomPlaces:
Specify an Array with the custom directories that will be displayed in the left pane. Missing directories will be omitted.
To specify the location in the list, specify an Array with the directory and its location (0 = Lower, 1 = Upper).
Options:
Determines the behavior of the dialog. This parameter must be one or more of the following values.
0x00000200 (FOS_ALLOWMULTISELECT) = Enables the user to select multiple items in the open dialog.
0x00040000 (FOS_HIDEPINNEDPLACES) = Hide items shown by default in the view's navigation pane.
0x02000000 (FOS_DONTADDTORECENT) = Do not add the item being opened or saved to the recent documents list (SHAddToRecentDocs).
0x10000000 (FOS_FORCESHOWHIDDEN) = Include hidden and system items.
You can check all available values at https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx.
Return:
Returns zero if the user canceled the dialog, otherwise returns the path of the selected directory. The directory never ends with "\".
*/
ChooseFolder(Owner, StartingFolder := "", CustomPlaces := "", Options := 0)
{
; IFileOpenDialog interface
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775834(v=vs.85).aspx
local IFileOpenDialog := ComObjCreate("{DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7}", "{D57C7288-D4AD-4768-BE02-9D969532D960}")
, Title := IsObject(Owner) ? Owner[2] . "" : ""
, Flags := 0x20 | Options ; FILEOPENDIALOGOPTIONS enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx)
, IShellItem := PIDL := 0 ; PIDL recibe la dirección de memoria a la estructura ITEMIDLIST que debe ser liberada con la función CoTaskMemFree
, Obj := {}, foo := bar := ""
Owner := IsObject(Owner) ? Owner[1] : (WinExist("ahk_id" . Owner) ? Owner : 0)
CustomPlaces := IsObject(CustomPlaces) || CustomPlaces == "" ? CustomPlaces : [CustomPlaces]
while (InStr(StartingFolder, "\") && !DirExist(StartingFolder))
StartingFolder := SubStr(StartingFolder, 1, InStr(StartingFolder, "\",, -1) - 1)
if ( DirExist(StartingFolder) )
{
StrPutVar(StartingFolder, StartingFolderW, "UTF-16")
DllCall("Shell32.dll\SHParseDisplayName", "UPtr", &StartingFolderW, "Ptr", 0, "UPtrP", PIDL, "UInt", 0, "UInt", 0)
DllCall("Shell32.dll\SHCreateShellItem", "Ptr", 0, "Ptr", 0, "UPtr", PIDL, "UPtrP", IShellItem)
ObjRawSet(Obj, IShellItem, PIDL)
; IFileDialog::SetFolder method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761828(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileOpenDialog+0)+12*A_PtrSize), "Ptr", IFileOpenDialog, "UPtr", IShellItem)
}
if ( IsObject(CustomPlaces) )
{
local Directory := ""
For foo, Directory in CustomPlaces ; foo = index
{
foo := IsObject(Directory) ? Directory[2] : 0 ; FDAP enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/bb762502(v=vs.85).aspx)
if ( DirExist(Directory := IsObject(Directory) ? Directory[1] : Directory) )
{
StrPutVar(Directory, DirectoryW, "UTF-16")
DllCall("Shell32.dll\SHParseDisplayName", "UPtr", &DirectoryW, "Ptr", 0, "UPtrP", PIDL, "UInt", 0, "UInt", 0)
DllCall("Shell32.dll\SHCreateShellItem", "Ptr", 0, "Ptr", 0, "UPtr", PIDL, "UPtrP", IShellItem)
ObjRawSet(Obj, IShellItem, PIDL)
; IFileDialog::AddPlace method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775946(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileOpenDialog+0)+21*A_PtrSize), "UPtr", IFileOpenDialog, "UPtr", IShellItem, "UInt", foo)
}
}
}
; IFileDialog::SetTitle method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761834(v=vs.85).aspx
StrPutVar(Title, TitleW, "UTF-16")
DllCall(NumGet(NumGet(IFileOpenDialog+0)+17*A_PtrSize), "UPtr", IFileOpenDialog, "UPtr", Title == "" ? 0 : &TitleW)
; IFileDialog::SetOptions method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761832(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileOpenDialog+0)+9*A_PtrSize), "UPtr", IFileOpenDialog, "UInt", Flags)
; IModalWindow::Show method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761688(v=vs.85).aspx
local Result := []
if ( !DllCall(NumGet(NumGet(IFileOpenDialog+0)+3*A_PtrSize), "UPtr", IFileOpenDialog, "Ptr", Owner, "UInt") )
{
; IFileOpenDialog::GetResults method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775831(v=vs.85).aspx
local IShellItemArray := 0 ; IShellItemArray interface (https://msdn.microsoft.com/en-us/library/windows/desktop/bb761106(v=vs.85).aspx)
DllCall(NumGet(NumGet(IFileOpenDialog+0)+27*A_PtrSize), "UPtr", IFileOpenDialog, "UPtrP", IShellItemArray)
; IShellItemArray::GetCount method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761098(v=vs.85).aspx
local Count := 0 ; pdwNumItems
DllCall(NumGet(NumGet(IShellItemArray+0)+7*A_PtrSize), "UPtr", IShellItemArray, "UIntP", Count)
local Buffer := ""
VarSetCapacity(Buffer, 32767 * 2)
loop % Count
{
; IShellItemArray::GetItemAt method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761100(v=vs.85).aspx
DllCall(NumGet(NumGet(IShellItemArray+0)+8*A_PtrSize), "UPtr", IShellItemArray, "UInt", A_Index-1, "UPtrP", IShellItem)
; IShellItem::GetDisplayName method
; https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellitem-getdisplayname
DllCall(NumGet(NumGet(IShellItem+0)+5*A_PtrSize), "Ptr", IShellItem, "Int", 0x80028000, "PtrP", ptr:=0)
ObjRawSet(Obj, IShellItem, ptr), ObjPush(Result, RTrim(StrGet(ptr,"UTF-16"), "\"))
if (Result[A_Index] ~= "^::") ; handle "::{00000000-0000-0000-0000-000000000000}\Documents.library-ms" (library)
{
; SHLoadLibraryFromParsingName
; https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-shloadlibraryfromparsingname
VarSetCapacity(IID_IShellItem, 16)
DllCall("Ole32\CLSIDFromString", "Str", "{43826d1e-e718-42ee-bc55-a1e261c37bfe}", "Ptr", &IID_IShellItem)
DllCall("Shell32\SHCreateItemFromParsingName", "WStr", Result[A_Index], "Ptr", 0, "Ptr", &IID_IShellItem, "PtrP", IShellItem:=0)
IShellLibrary := ComObjCreate("{d9b3211d-e57f-4426-aaef-30a806add397}", "{11A66EFA-382E-451A-9234-1E0E12EF3085}")
; IShellLibrary::LoadLibraryFromItem
; https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ishelllibrary
DllCall(NumGet(NumGet(IShellLibrary+0)+3*A_PtrSize), "UPtr", IShellLibrary, "Ptr", IShellItem, "Int", 0)
IShellLibrary2 := ComObjQuery(IShellLibrary, "{11A66EFA-382E-451A-9234-1E0E12EF3085}")
ObjRelease(IShellLibrary)
ObjRelease(IShellItem)
VarSetCapacity(IID_IShellItemArray, 16)
DllCall("Ole32\CLSIDFromString", "Str", "{b63ea76d-1f85-456f-a19c-48159efa858b}", "Ptr", &IID_IShellItemArray)
; IShellLibrary::GetFolders method
; https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishelllibrary-getfolders
DllCall(NumGet(NumGet(IShellLibrary2+0)+7*A_PtrSize), "UPtr", IShellLibrary2, "Int", 1, "Ptr", &IID_IShellItemArray, "PtrP", IShellItemArray:=0)
DllCall(NumGet(NumGet(IShellItemArray+0)+8*A_PtrSize), "UPtr", IShellItemArray, "Int", 0, "PtrP", IShellItem0:=0)
DllCall(NumGet(NumGet(IShellItem0+0)+5*A_PtrSize), "Ptr", IShellItem0, "Int", 0x80028000, "PtrP", ptr:=0)
Result[A_Index] := StrGet(ptr, "UTF-16")
DllCall("Ole32\CoTaskMemFree", "Ptr", ptr)
ObjRelease(IShellItem0)
ObjRelease(IShellItemArray)
ObjRelease(IShellLibrary2)
}
}
ObjRelease(IShellItemArray)
}
for foo, bar in Obj ; foo = IShellItem interface (ptr) | bar = PIDL structure (ptr)
ObjRelease(foo), DllCall("Ole32.dll\CoTaskMemFree", "Ptr", bar)
ObjRelease(IFileOpenDialog)
return ObjLength(Result) ? ( Options & 0x200 ? Result : Result[1] ) : FALSE
}
Code: Select all
Result := ChooseFolder( [0, "Dialog title - ChooseFolder.."]
, A_WinDir . "\System32\Non-existent folder\"
, [A_WinDir,A_Desktop,A_Temp,A_Startup,A_ProgramFiles]
, 0x10000000 | 0x02000000 | 0x00000200 )
List := ""
For Each, Directory in Result
List .= Directory . "`n"
MsgBox % List
ChooseFile
Code: Select all
/*
Displays a standard dialog that allows the user to open file(s).
Parameters:
Owner / Title:
The identifier of the window that owns this dialog. This value can be zero.
An Array with the identifier of the owner window and the title. If the title is an empty string, it is set to the default.
FileName:
The path to the file or directory selected by default. If you specify a directory, it must end with a backslash.
Filter:
Specify a file filter. You must specify an object, each key represents the description and the value the file types.
To specify the filter selected by default, add the "`n" character to the value.
CustomPlaces:
Specify an Array with the custom directories that will be displayed in the left pane. Missing directories will be omitted.
To specify the location in the list, specify an Array with the directory and its location (0 = Lower, 1 = Upper).
Options:
Determines the behavior of the dialog. This parameter must be one or more of the following values.
0x00000200 (FOS_ALLOWMULTISELECT) = Enables the user to select multiple items in the open dialog.
0x00001000 (FOS_FILEMUSTEXIST) = The item returned must exist.
0x00040000 (FOS_HIDEPINNEDPLACES) = Hide items shown by default in the view's navigation pane.
0x02000000 (FOS_DONTADDTORECENT) = Do not add the item being opened or saved to the recent documents list (SHAddToRecentDocs).
0x10000000 (FOS_FORCESHOWHIDDEN) = Include hidden and system items.
You can check all available values at https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx.
Return:
Returns 0 if the user canceled the dialog, otherwise returns the path of the selected file.
If you specified the FOS_ALLOWMULTISELECT option and the function succeeded, it returns an Array with the path of the selected files.
*/
ChooseFile(Owner, FileName := "", Filter := "", CustomPlaces := "", Options := 0x1000)
{
; IFileOpenDialog interface
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775834(v=vs.85).aspx
local IFileOpenDialog := ComObjCreate("{DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7}", "{D57C7288-D4AD-4768-BE02-9D969532D960}")
, Title := IsObject(Owner) ? Owner[2] . "" : ""
, Flags := Options ; FILEOPENDIALOGOPTIONS enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx)
, IShellItem := PIDL := 0 ; PIDL recibe la dirección de memoria a la estructura ITEMIDLIST que debe ser liberada con la función CoTaskMemFree
, Obj := {COMDLG_FILTERSPEC: ""}, foo := bar := ""
, Directory := FileName
Owner := IsObject(Owner) ? Owner[1] : (WinExist("ahk_id" . Owner) ? Owner : 0)
Filter := IsObject(Filter) ? Filter : {"All files": "*.*"}
if ( FileName != "" )
{
if ( InStr(FileName, "\") )
{
if !( FileName ~= "\\$" ) ; si «FileName» termina con "\" se trata de una carpeta
{
local File := ""
SplitPath FileName, File, Directory
; IFileDialog::SetFileName
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775974(v=vs.85).aspx
StrPutVar(File, FileW, "UTF-16")
DllCall(NumGet(NumGet(IFileOpenDialog+0)+15*A_PtrSize), "UPtr", IFileOpenDialog, "UPtr", &FileW)
}
while ( InStr(Directory,"\") && !DirExist(Directory) ) ; si el directorio no existe buscamos directorios superiores
Directory := SubStr(Directory, 1, InStr(Directory, "\",, -1) - 1) ; recupera el directorio superior
if ( DirExist(Directory) )
{
StrPutVar(Directory, DirectoryW, "UTF-16")
DllCall("Shell32.dll\SHParseDisplayName", "UPtr", &DirectoryW, "Ptr", 0, "UPtrP", PIDL, "UInt", 0, "UInt", 0)
DllCall("Shell32.dll\SHCreateShellItem", "Ptr", 0, "Ptr", 0, "UPtr", PIDL, "UPtrP", IShellItem)
ObjRawSet(Obj, IShellItem, PIDL)
; IFileDialog::SetFolder method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761828(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileOpenDialog+0)+12*A_PtrSize), "Ptr", IFileOpenDialog, "UPtr", IShellItem)
}
}
else
{
StrPutVar(FileName, FileNameW, "UTF-16")
DllCall(NumGet(NumGet(IFileOpenDialog+0)+15*A_PtrSize), "UPtr", IFileOpenDialog, "UPtr", &FileNameW)
}
}
; COMDLG_FILTERSPEC structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb773221(v=vs.85).aspx
local Description := "", FileTypes := "", FileTypeIndex := 1
ObjSetCapacity(Obj, "COMDLG_FILTERSPEC", 2*Filter.Count() * A_PtrSize)
for Description, FileTypes in Filter
{
FileTypeIndex := InStr(FileTypes,"`n") ? A_Index : FileTypeIndex
StrPutVar(Trim(Description), desc_%A_Index%, "UTF-16")
StrPutVar(Trim(StrReplace(FileTypes,"`n")), ft_%A_Index%, "UTF-16")
NumPut(&desc_%A_Index%, ObjGetAddress(Obj,"COMDLG_FILTERSPEC") + A_PtrSize * 2*(A_Index-1)) ; COMDLG_FILTERSPEC.pszName
NumPut(&ft_%A_Index%, ObjGetAddress(Obj,"COMDLG_FILTERSPEC") + A_PtrSize * (2*(A_Index-1)+1)) ; COMDLG_FILTERSPEC.pszSpec
}
; IFileDialog::SetFileTypes method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775980(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileOpenDialog+0)+4*A_PtrSize), "UPtr", IFileOpenDialog, "UInt", Filter.Count(), "UPtr", ObjGetAddress(Obj,"COMDLG_FILTERSPEC"))
; IFileDialog::SetFileTypeIndex method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775978(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileOpenDialog+0)+5*A_PtrSize), "UPtr", IFileOpenDialog, "UInt", FileTypeIndex)
if ( IsObject(CustomPlaces := IsObject(CustomPlaces) || CustomPlaces == "" ? CustomPlaces : [CustomPlaces]) )
{
for foo, Directory in CustomPlaces ; foo = index
{
foo := IsObject(Directory) ? Directory[2] : 0 ; FDAP enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/bb762502(v=vs.85).aspx)
if ( DirExist(Directory := IsObject(Directory) ? Directory[1] : Directory) )
{
StrPutVar(Directory, DirectoryW, "UTF-16")
DllCall("Shell32.dll\SHParseDisplayName", "UPtr", &DirectoryW, "Ptr", 0, "UPtrP", PIDL, "UInt", 0, "UInt", 0)
DllCall("Shell32.dll\SHCreateShellItem", "Ptr", 0, "Ptr", 0, "UPtr", PIDL, "UPtrP", IShellItem)
ObjRawSet(Obj, IShellItem, PIDL)
; IFileDialog::AddPlace method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775946(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileOpenDialog+0)+21*A_PtrSize), "UPtr", IFileOpenDialog, "UPtr", IShellItem, "UInt", foo)
}
}
}
; IFileDialog::SetTitle method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761834(v=vs.85).aspx
StrPutVar(Title, TitleW, "UTF-16")
DllCall(NumGet(NumGet(IFileOpenDialog+0)+17*A_PtrSize), "UPtr", IFileOpenDialog, "UPtr", Title == "" ? 0 : &TitleW)
; IFileDialog::SetOptions method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761832(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileOpenDialog+0)+9*A_PtrSize), "UPtr", IFileOpenDialog, "UInt", Flags)
; IModalWindow::Show method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761688(v=vs.85).aspx
local Result := []
if ( !DllCall(NumGet(NumGet(IFileOpenDialog+0)+3*A_PtrSize), "UPtr", IFileOpenDialog, "Ptr", Owner, "UInt") )
{
; IFileOpenDialog::GetResults method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775831(v=vs.85).aspx
local IShellItemArray := 0 ; IShellItemArray interface (https://msdn.microsoft.com/en-us/library/windows/desktop/bb761106(v=vs.85).aspx)
DllCall(NumGet(NumGet(IFileOpenDialog+0)+27*A_PtrSize), "UPtr", IFileOpenDialog, "UPtrP", IShellItemArray)
; IShellItemArray::GetCount method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761098(v=vs.85).aspx
local Count := 0 ; pdwNumItems
DllCall(NumGet(NumGet(IShellItemArray+0)+7*A_PtrSize), "UPtr", IShellItemArray, "UIntP", Count, "UInt")
local Buffer := ""
loop % 0*VarSetCapacity(Buffer,32767 * 2) + Count
{
; IShellItemArray::GetItemAt method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761100(v=vs.85).aspx
DllCall(NumGet(NumGet(IShellItemArray+0)+8*A_PtrSize), "UPtr", IShellItemArray, "UInt", A_Index-1, "UPtrP", IShellItem)
DllCall("Shell32.dll\SHGetIDListFromObject", "UPtr", IShellItem, "UPtrP", PIDL)
DllCall("Shell32.dll\SHGetPathFromIDListEx", "UPtr", PIDL, "Str", Buffer, "UInt", 32767, "UInt", 0)
ObjRawSet(Obj, IShellItem, PIDL), ObjPush(Result, StrGet(&Buffer, "UTF-16"))
}
ObjRelease(IShellItemArray)
}
for foo, bar in Obj ; foo = IShellItem interface (ptr) | bar = PIDL structure (ptr)
if foo is integer ; IShellItem?
ObjRelease(foo), DllCall("Ole32.dll\CoTaskMemFree", "UPtr", bar)
ObjRelease(IFileOpenDialog)
return ObjLength(Result) ? (Options & 0x200 ? Result : Result[1]) : FALSE
}
Code: Select all
Result := ChooseFile( [0, "Dialog title - ChooseFile.."]
, A_ComSpec
, {All: "`n*.*", Music: "*.mp3", Images: "*.jpg;*.png", Videos: "*.avi;*.mp4;*.mkv;*.wmp", Documents: "*.txt"}
, [A_WinDir,A_Desktop,A_Temp,A_Startup,A_ProgramFiles]
, 0x10000000 | 0x02000000 | 0x00000200 | 0x00001000 )
If ((List := "") == "" && Result != FALSE)
For Each, File in Result
List .= File . "`n"
MsgBox % List
SaveFile
Code: Select all
/*
Displays a standard dialog that allows the user to save a file.
Parameters:
Owner / Title:
The identifier of the window that owns this dialog. This value can be zero.
An Array with the identifier of the owner window and the title. If the title is an empty string, it is set to the default.
FileName:
The path to the file or directory selected by default. If you specify a directory, it must end with a backslash.
Filter:
Specify a file filter. You must specify an object, each key represents the description and the value the file types.
To specify the filter selected by default, add the "`n" character to the value.
CustomPlaces:
Specify an Array with the custom directories that will be displayed in the left pane. Missing directories will be omitted.
To specify the location in the list, specify an Array with the directory and its location (0 = Lower, 1 = Upper).
Options:
Determines the behavior of the dialog. This parameter must be one or more of the following values.
0x00000002 (FOS_OVERWRITEPROMPT) = When saving a file, prompt before overwriting an existing file of the same name.
0x00000004 (FOS_STRICTFILETYPES) = Only allow the user to choose a file that has one of the file name extensions specified through Filter.
0x00040000 (FOS_HIDEPINNEDPLACES) = Hide items shown by default in the view's navigation pane.
0x10000000 (FOS_FORCESHOWHIDDEN) = Include hidden and system items.
0x02000000 (FOS_DONTADDTORECENT) = Do not add the item being opened or saved to the recent documents list (SHAddToRecentDocs).
You can check all available values at https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx.
Return:
Returns 0 if the user canceled the dialog, otherwise returns the path of the selected file.
*/
SaveFile(Owner, FileName := "", Filter := "", CustomPlaces := "", Options := 0x6)
{
; IFileSaveDialog interface
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775688(v=vs.85).aspx
local IFileSaveDialog := ComObjCreate("{C0B4E2F3-BA21-4773-8DBA-335EC946EB8B}", "{84BCCD23-5FDE-4CDB-AEA4-AF64B83D78AB}")
, Title := IsObject(Owner) ? Owner[2] . "" : ""
, Flags := Options ; FILEOPENDIALOGOPTIONS enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx)
, IShellItem := PIDL := 0 ; PIDL recibe la dirección de memoria a la estructura ITEMIDLIST que debe ser liberada con la función CoTaskMemFree
, Obj := {}, foo := bar := ""
, Directory := FileName
Owner := IsObject(Owner) ? Owner[1] : (WinExist("ahk_id" . Owner) ? Owner : 0)
Filter := IsObject(Filter) ? Filter : {"All files": "*.*"}
if ( FileName != "" )
{
if ( InStr(FileName, "\") )
{
if !( FileName ~= "\\$" ) ; si «FileName» termina con "\" se trata de una carpeta
{
local File := ""
SplitPath FileName, File, Directory
; IFileDialog::SetFileName
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775974(v=vs.85).aspx
StrPutVar(File, FileW, "UTF-16")
DllCall(NumGet(NumGet(IFileSaveDialog+0)+15*A_PtrSize), "UPtr", IFileSaveDialog, "UPtr", &FileW)
}
while ( InStr(Directory,"\") && !DirExist(Directory) ) ; si el directorio no existe buscamos directorios superiores
Directory := SubStr(Directory, 1, InStr(Directory, "\",, -1) - 1) ; recupera el directorio superior
if ( DirExist(Directory) )
{
StrPutVar(Directory, DirectoryW, "UTF-16")
DllCall("Shell32.dll\SHParseDisplayName", "UPtr", &DirectoryW, "Ptr", 0, "UPtrP", PIDL, "UInt", 0, "UInt", 0)
DllCall("Shell32.dll\SHCreateShellItem", "Ptr", 0, "Ptr", 0, "UPtr", PIDL, "UPtrP", IShellItem)
ObjRawSet(Obj, IShellItem, PIDL)
; IFileDialog::SetFolder method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761828(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileSaveDialog+0)+12*A_PtrSize), "Ptr", IFileSaveDialog, "UPtr", IShellItem)
}
}
else
{
StrPutVar(FileName, FileNameW, "UTF-16")
DllCall(NumGet(NumGet(IFileSaveDialog+0)+15*A_PtrSize), "UPtr", IFileSaveDialog, "UPtr", &FileNameW)
}
}
; COMDLG_FILTERSPEC structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb773221(v=vs.85).aspx
local Description := "", FileTypes := "", FileTypeIndex := 1
ObjSetCapacity(Obj, "COMDLG_FILTERSPEC", 2*Filter.Count() * A_PtrSize)
for Description, FileTypes in Filter
{
FileTypeIndex := InStr(FileTypes,"`n") ? A_Index : FileTypeIndex
StrPutVar(Trim(Description), desc_%A_Index%, "UTF-16")
StrPutVar(Trim(StrReplace(FileTypes,"`n")), ft_%A_Index%, "UTF-16")
NumPut(&desc_%A_Index%, ObjGetAddress(Obj,"COMDLG_FILTERSPEC") + A_PtrSize * 2*(A_Index-1)) ; COMDLG_FILTERSPEC.pszName
NumPut(&ft_%A_Index%, ObjGetAddress(Obj,"COMDLG_FILTERSPEC") + A_PtrSize * (2*(A_Index-1)+1)) ; COMDLG_FILTERSPEC.pszSpec
}
; IFileDialog::SetFileTypes method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775980(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileSaveDialog+0)+4*A_PtrSize), "UPtr", IFileSaveDialog, "UInt", Filter.Count(), "UPtr", ObjGetAddress(Obj,"COMDLG_FILTERSPEC"))
; IFileDialog::SetFileTypeIndex method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775978(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileSaveDialog+0)+5*A_PtrSize), "UPtr", IFileSaveDialog, "UInt", FileTypeIndex)
if ( IsObject(CustomPlaces := IsObject(CustomPlaces) || CustomPlaces == "" ? CustomPlaces : [CustomPlaces]) )
{
for foo, Directory in CustomPlaces ; foo = index
{
foo := IsObject(Directory) ? Directory[2] : 0 ; FDAP enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/bb762502(v=vs.85).aspx)
if ( DirExist(Directory := IsObject(Directory) ? Directory[1] : Directory) )
{
StrPutVar(Directory, DirectoryW, "UTF-16")
DllCall("Shell32.dll\SHParseDisplayName", "UPtr", &DirectoryW, "Ptr", 0, "UPtrP", PIDL, "UInt", 0, "UInt", 0)
DllCall("Shell32.dll\SHCreateShellItem", "Ptr", 0, "Ptr", 0, "UPtr", PIDL, "UPtrP", IShellItem)
ObjRawSet(Obj, IShellItem, PIDL)
; IFileDialog::AddPlace method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775946(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileSaveDialog+0)+21*A_PtrSize), "UPtr", IFileSaveDialog, "UPtr", IShellItem, "UInt", foo)
}
}
}
; IFileDialog::SetTitle method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761834(v=vs.85).aspx
StrPutVar(Title, TitleW, "UTF-16")
DllCall(NumGet(NumGet(IFileSaveDialog+0)+17*A_PtrSize), "UPtr", IFileSaveDialog, "UPtr", Title == "" ? 0 : &TitleW)
; IFileDialog::SetOptions method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761832(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileSaveDialog+0)+9*A_PtrSize), "UPtr", IFileSaveDialog, "UInt", Flags)
; IModalWindow::Show method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761688(v=vs.85).aspx
local Result := FALSE
if ( !DllCall(NumGet(NumGet(IFileSaveDialog+0)+3*A_PtrSize), "UPtr", IFileSaveDialog, "Ptr", Owner, "UInt") )
{
; IFileDialog::GetResult method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775964(v=vs.85).aspx
if ( !DllCall(NumGet(NumGet(IFileSaveDialog+0)+20*A_PtrSize), "UPtr", IFileSaveDialog, "UPtrP", IShellItem) )
{
VarSetCapacity(Result, 32767 * 2, 0)
DllCall("Shell32.dll\SHGetIDListFromObject", "UPtr", IShellItem, "UPtrP", PIDL)
DllCall("Shell32.dll\SHGetPathFromIDListEx", "UPtr", PIDL, "Str", Result, "UInt", 2000, "UInt", 0)
Result := StrGet(&Result, "UTF-16")
ObjRawSet(Obj, IShellItem, PIDL)
}
}
for foo, bar in Obj ; foo = IShellItem interface (ptr) | bar = PIDL structure (ptr)
if foo is integer ; IShellItem?
ObjRelease(foo), DllCall("Ole32.dll\CoTaskMemFree", "UPtr", bar)
ObjRelease(IFileSaveDialog)
return Result
}
Code: Select all
MsgBox % SaveFile( [0, "Dialog title - SaveFile.."]
, A_ComSpec
, {Music: "*.mp3", Images: "`n*.jpg;*.png", Videos: "*.avi;*.mp4;*.mkv;*.wmp", Documents: "*.txt"}
, [A_WinDir,A_Desktop,A_Temp,A_Startup,A_ProgramFiles]
, 0x00000002 | 0x00000004 | 0x10000000 | 0x02000000 )
aldrinjohnom⠀ wrote:Can you translate this code into the function you are talking about:
FileSelectFile invfile, S24,, save the file with your chosen extension, text(*.txt)|Document(*.doc)|Music(*.mp3)|Video(*.mp4)
Code: Select all
R := SaveFile( [0, "save the file with your chosen extension"] ; [owner, title/prompt]
, "" ; RootDir\Filename
, {Text: "*.txt", Decument: "*.doc", Music: "*.mp3", Video: "*.mp4"} ; Filter
, "" ; CustomPlaces
, 2) ; Options ( 2 = FOS_OVERWRITEPROMPT )
MsgBox % R
-
- Posts: 77
- Joined: 18 Apr 2018, 08:49
Re: FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list
WOW! That is One way to go! this function creates the gui I wanted to generate. Now just one problem:
How can I Return the selected filter of the gui on this code?
eg. I selected music... it will return either the "filter row number" or the "filter name"... Its your choice I guess?
My Case is nearly being solved, Thank you very much Flipeador, You are awesome!
How can I Return the selected filter of the gui on this code?
Code: Select all
R := SaveFile( [0, "save the file with your chosen extension"] ; [owner, title/prompt]
, "" ; RootDir\Filename
, {Text: "*.txt", Decument: "*.doc", Music: "*.mp3", Video: "*.mp4"} ; Filter
, "" ; CustomPlaces
, 2) ; Options ( 2 = FOS_OVERWRITEPROMPT )
MsgBox filename was : %R%`n`nand the chosen filter was %filter%
My Case is nearly being solved, Thank you very much Flipeador, You are awesome!
Last edited by Flipeador on 04 Aug 2018, 07:18, edited 1 time in total.
Reason: shorten message
Reason: shorten message
Developer of AJOM's DOTA2 MOD Master, Easiest way to MOD your DOTA2 without the use of internet . I created this program using Autohotkey thats why I love Autohotkey and the community!
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
Re: FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list
@Flipeador, thank you
just another FileSelectFile DropDownList example I used
just another FileSelectFile DropDownList example I used
Code: Select all
#Warn
#NoEnv
SendMode, Input
SetWorkingDir, %A_ScriptDir%
extensions:="ahk,bat,bak,ini,csv,bas" ;- open these with notepad
mediafolder=D:\M_MEDIA ;- <<< here are files video/music/foto
Gui,2: Color, ControlColor,Black ;- background from edit
Gui,2: Color, Black ;- Gui color
Gui,2: Font,s12 cWhite ,Lucida Console ;- font , font-size and color
e:=""
ftext=Fileselectfolder_DDL
transform,s,chr,32
e5x=
(Ltrim join|
MusicVideo ;mp3,mp4,flv,aac,mpg,vob,flac,aif,m3a
Music ;mp3,aac,flac,aif,m3a
Video ;mp4,flv,vob,mpg
Foto ;jpg,png,bmp,tif
Text ;txt,bat,bak,ini,csv,ahk,bas
eBook ;epub,txt,pdf
%s%
)
Gui,2: Show, NA x100 y5 w320 h50, %ftext%
Gui,2: Add, DDL , x10 y10 w150 vddlC gAA,%e5x%
GuiControl,2:Choose,ddlC,3
return
2Guiclose:
exitapp
aa:
Gui,2:submit,nohide
ddlC=%ddlC%
if ddlC=
return
StringSplit,h, ddlC, `;
h1=%h1%
Loop, Parse,h2, `,
e .= "*." . a_loopfield . ";"
stringtrimright,e,e,1
e := "(" . e . ")"
if (h1="Music" or h1="Video" or h1="Foto" or h1="MusicVideo")
preselect=%mediafolder%
else
preselect=%a_desktop%
FileSelectFile, FL1, 3,%preselect%, Choose file:, %e%
If FL1 =
ExitApp
SplitPath,fl1, name, dir, ext, name_no_ext, drive
If Ext In %extensions%
run,notepad %fl1%
else
run,%fl1%
return
;========================================================
Re: FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list
You can use the GetFileTypeIndex method of the IFileDialog interface.aldrinjohnom wrote:How can I Return the selected filter of the gui on this code?
Put this code inside the if block of IModalWindow::Show method. For the ChooseFile and ChooseFolder functions you must replace IFileSaveDialog with IFileOpenDialog.
Code: Select all
; IFileDialog::GetFileTypeIndex method
; https://msdn.microsoft.com/es-es/bb775958
DllCall(NumGet(NumGet(IFileSaveDialog+0)+6*A_PtrSize), "UPtr", IFileSaveDialog, "UIntP", FileTypeIndex)
MsgBox % FileTypeIndex
Code: Select all
; IModalWindow::Show method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761688(v=vs.85).aspx
local Result := FALSE
if ( !DllCall(NumGet(NumGet(IFileSaveDialog+0)+3*A_PtrSize), "UPtr", IFileSaveDialog, "Ptr", Owner, "UInt") )
{
; IFileDialog::GetFileTypeIndex method
; https://msdn.microsoft.com/es-es/bb775958
DllCall(NumGet(NumGet(IFileSaveDialog+0)+6*A_PtrSize), "UPtr", IFileSaveDialog, "UIntP", FileTypeIndex)
MsgBox % FileTypeIndex
; IFileDialog::GetResult method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775964(v=vs.85).aspx
if ( !DllCall(NumGet(NumGet(IFileSaveDialog+0)+20*A_PtrSize), "UPtr", IFileSaveDialog, "UPtrP", IShellItem) )
{
VarSetCapacity(Result, 32767 * 2, 0)
DllCall("Shell32.dll\SHGetIDListFromObject", "UPtr", IShellItem, "UPtrP", PIDL)
DllCall("Shell32.dll\SHGetPathFromIDListEx", "UPtr", PIDL, "Str", Result, "UInt", 32767, "UInt", 0)
ObjRawSet(Obj, IShellItem, PIDL)
}
}
Edit* I've added it to the v2 script using ErrorLevel (because DllCall does not modify it in v2). I've also added the ability to specify the default extension (using the `r character along with the extension in the filter).
@garry
-
- Posts: 77
- Joined: 18 Apr 2018, 08:49
Re: FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list Topic is solved
I Finally created the Code that I was dreaming of, this will be the best alternative for FileSelectFile. Thank you So Much for your Effort Flipeador, You are the Master of GUI!Flipeador wrote:You can use the GetFileTypeIndex method of the IFileDialog interface.aldrinjohnom wrote:How can I Return the selected filter of the gui on this code?
Put this code inside the if block of IModalWindow::Show method. For the ChooseFile and ChooseFolder functions you must replace IFileSaveDialog with IFileOpenDialog.For example, in the SaveFile function, that part would look like this:Code: Select all
; IFileDialog::GetFileTypeIndex method ; https://msdn.microsoft.com/es-es/bb775958 DllCall(NumGet(NumGet(IFileSaveDialog+0)+6*A_PtrSize), "UPtr", IFileSaveDialog, "UIntP", FileTypeIndex) MsgBox % FileTypeIndex
If you want, you can return an object with the selected file and the filter index (FileTypeIndex). just change return Result --> return Result ? {File: Result, FileTypeIndex: FileTypeIndex} : FALSE. Then you can use MsgBox % "Filename:`n" . R.File . "`n`nFilter:`n" . R.FileTypeIndex.Code: Select all
; IModalWindow::Show method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761688(v=vs.85).aspx local Result := FALSE if ( !DllCall(NumGet(NumGet(IFileSaveDialog+0)+3*A_PtrSize), "UPtr", IFileSaveDialog, "Ptr", Owner, "UInt") ) { ; IFileDialog::GetFileTypeIndex method ; https://msdn.microsoft.com/es-es/bb775958 DllCall(NumGet(NumGet(IFileSaveDialog+0)+6*A_PtrSize), "UPtr", IFileSaveDialog, "UIntP", FileTypeIndex) MsgBox % FileTypeIndex ; IFileDialog::GetResult method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775964(v=vs.85).aspx if ( !DllCall(NumGet(NumGet(IFileSaveDialog+0)+20*A_PtrSize), "UPtr", IFileSaveDialog, "UPtrP", IShellItem) ) { VarSetCapacity(Result, 32767 * 2, 0) DllCall("Shell32.dll\SHGetIDListFromObject", "UPtr", IShellItem, "UPtrP", PIDL) DllCall("Shell32.dll\SHGetPathFromIDListEx", "UPtr", PIDL, "Str", Result, "UInt", 32767, "UInt", 0) ObjRawSet(Obj, IShellItem, PIDL) } }
Edit* I've added it to the v2 script using ErrorLevel (because DllCall does not modify it in v2). I've also added the ability to specify the default extension (using the `r character along with the extension in the filter).
@garry
FileSelectFile(Save):
Code: Select all
Result := SaveFile( [0, "save the file with your chosen extension"] ; [owner, title/prompt]
, "" ; RootDir\Filename
, {Text: "*.txt", Document: "`n*.doc", Music: "*.mp3", Video: "*.mp4"} ; Filter
, "" ; CustomPlaces
, 2) ; Options ( 2 = FOS_OVERWRITEPROMPT )
MsgBox % "You Chose Filter: " Result.FilterIndex "`n" Result.FileFullPath
ExitApp
; FUNCTIONS
DirExist(DirName)
{
loop Files, % DirName, D
return A_LoopFileAttrib
}
StrPutVar(string, ByRef var, encoding)
{
; Ensure capacity.
VarSetCapacity( var, StrPut(string, encoding)
; StrPut returns char count, but VarSetCapacity needs bytes.
* ((encoding="utf-16"||encoding="cp1200") ? 2 : 1) )
; Copy or convert the string.
return StrPut(string, &var, encoding)
} ; https://www.autohotkey.com/docs/commands/StrPut.htm#Examples
/*
Displays a standard dialog that allows the user to save a file.
Parameters:
Owner / Title:
The identifier of the window that owns this dialog. This value can be zero.
An Array with the identifier of the owner window and the title. If the title is an empty string, it is set to the default.
FileName:
The path to the file or directory selected by default. If you specify a directory, it must end with a backslash.
Filter:
Specify a file filter. You must specify an object, each key represents the description and the value the file types.
To specify the filter selected by default, add the "`n" character to the value.
CustomPlaces:
Specify an Array with the custom directories that will be displayed in the left pane. Missing directories will be omitted.
To specify the location in the list, specify an Array with the directory and its location (0 = Lower, 1 = Upper).
Options:
Determines the behavior of the dialog. This parameter must be one or more of the following values.
0x00000002 (FOS_OVERWRITEPROMPT) = When saving a file, prompt before overwriting an existing file of the same name.
0x00000004 (FOS_STRICTFILETYPES) = Only allow the user to choose a file that has one of the file name extensions specified through Filter.
0x00040000 (FOS_HIDEPINNEDPLACES) = Hide items shown by default in the view's navigation pane.
0x10000000 (FOS_FORCESHOWHIDDEN) = Include hidden and system items.
0x02000000 (FOS_DONTADDTORECENT) = Do not add the item being opened or saved to the recent documents list (SHAddToRecentDocs).
You can check all available values at https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx.
Return:
Returns 0 if the user canceled the dialog, otherwise:
callervariable.File = Chosen File Full Path
callervariable.FileTypeIndex = index of chosen filter
*/
SaveFile(Owner, FileName := "", Filter := "", CustomPlaces := "", Options := 0x6)
{
; IFileSaveDialog interface
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775688(v=vs.85).aspx
local IFileSaveDialog := ComObjCreate("{C0B4E2F3-BA21-4773-8DBA-335EC946EB8B}", "{84BCCD23-5FDE-4CDB-AEA4-AF64B83D78AB}")
, Title := IsObject(Owner) ? Owner[2] . "" : ""
, Flags := Options ; FILEOPENDIALOGOPTIONS enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx)
, IShellItem := PIDL := 0 ; PIDL recibe la dirección de memoria a la estructura ITEMIDLIST que debe ser liberada con la función CoTaskMemFree
, Obj := {}, foo := bar := ""
, Directory := FileName
Owner := IsObject(Owner) ? Owner[1] : (WinExist("ahk_id" . Owner) ? Owner : 0)
Filter := IsObject(Filter) ? Filter : {"All files": "*.*"}
if ( FileName != "" )
{
if ( InStr(FileName, "\") )
{
if !( FileName ~= "\\$" ) ; si «FileName» termina con "\" se trata de una carpeta
{
local File := ""
SplitPath FileName, File, Directory
; IFileDialog::SetFileName
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775974(v=vs.85).aspx
StrPutVar(File, FileW, "UTF-16")
DllCall(NumGet(NumGet(IFileSaveDialog+0)+15*A_PtrSize), "UPtr", IFileSaveDialog, "UPtr", &FileW)
}
while ( InStr(Directory,"\") && !DirExist(Directory) ) ; si el directorio no existe buscamos directorios superiores
Directory := SubStr(Directory, 1, InStr(Directory, "\",, -1) - 1) ; recupera el directorio superior
if ( DirExist(Directory) )
{
StrPutVar(Directory, DirectoryW, "UTF-16")
DllCall("Shell32.dll\SHParseDisplayName", "UPtr", &DirectoryW, "Ptr", 0, "UPtrP", PIDL, "UInt", 0, "UInt", 0)
DllCall("Shell32.dll\SHCreateShellItem", "Ptr", 0, "Ptr", 0, "UPtr", PIDL, "UPtrP", IShellItem)
ObjRawSet(Obj, IShellItem, PIDL)
; IFileDialog::SetFolder method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761828(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileSaveDialog+0)+12*A_PtrSize), "Ptr", IFileSaveDialog, "UPtr", IShellItem)
}
}
else
{
StrPutVar(FileName, FileNameW, "UTF-16")
DllCall(NumGet(NumGet(IFileSaveDialog+0)+15*A_PtrSize), "UPtr", IFileSaveDialog, "UPtr", &FileNameW)
}
}
; COMDLG_FILTERSPEC structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb773221(v=vs.85).aspx
local Description := "", FileTypes := "", FileTypeIndex := 1
ObjSetCapacity(Obj, "COMDLG_FILTERSPEC", 2*Filter.Count() * A_PtrSize)
for Description, FileTypes in Filter
{
FileTypeIndex := InStr(FileTypes,"`n") ? A_Index : FileTypeIndex
StrPutVar(Trim(Description), desc_%A_Index%, "UTF-16")
StrPutVar(Trim(StrReplace(FileTypes,"`n")), ft_%A_Index%, "UTF-16")
NumPut(&desc_%A_Index%, ObjGetAddress(Obj,"COMDLG_FILTERSPEC") + A_PtrSize * 2*(A_Index-1)) ; COMDLG_FILTERSPEC.pszName
NumPut(&ft_%A_Index%, ObjGetAddress(Obj,"COMDLG_FILTERSPEC") + A_PtrSize * (2*(A_Index-1)+1)) ; COMDLG_FILTERSPEC.pszSpec
}
; IFileDialog::SetFileTypes method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775980(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileSaveDialog+0)+4*A_PtrSize), "UPtr", IFileSaveDialog, "UInt", Filter.Count(), "UPtr", ObjGetAddress(Obj,"COMDLG_FILTERSPEC"))
; IFileDialog::SetFileTypeIndex method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775978(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileSaveDialog+0)+5*A_PtrSize), "UPtr", IFileSaveDialog, "UInt", FileTypeIndex)
if ( IsObject(CustomPlaces := IsObject(CustomPlaces) || CustomPlaces == "" ? CustomPlaces : [CustomPlaces]) )
{
for foo, Directory in CustomPlaces ; foo = index
{
foo := IsObject(Directory) ? Directory[2] : 0 ; FDAP enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/bb762502(v=vs.85).aspx)
if ( DirExist(Directory := IsObject(Directory) ? Directory[1] : Directory) )
{
StrPutVar(Directory, DirectoryW, "UTF-16")
DllCall("Shell32.dll\SHParseDisplayName", "UPtr", &DirectoryW, "Ptr", 0, "UPtrP", PIDL, "UInt", 0, "UInt", 0)
DllCall("Shell32.dll\SHCreateShellItem", "Ptr", 0, "Ptr", 0, "UPtr", PIDL, "UPtrP", IShellItem)
ObjRawSet(Obj, IShellItem, PIDL)
; IFileDialog::AddPlace method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775946(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileSaveDialog+0)+21*A_PtrSize), "UPtr", IFileSaveDialog, "UPtr", IShellItem, "UInt", foo)
}
}
}
; IFileDialog::SetTitle method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761834(v=vs.85).aspx
StrPutVar(Title, TitleW, "UTF-16")
DllCall(NumGet(NumGet(IFileSaveDialog+0)+17*A_PtrSize), "UPtr", IFileSaveDialog, "UPtr", Title == "" ? 0 : &TitleW)
; IFileDialog::SetOptions method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761832(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileSaveDialog+0)+9*A_PtrSize), "UPtr", IFileSaveDialog, "UInt", Flags)
; IModalWindow::Show method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761688(v=vs.85).aspx
local Result := FALSE
if ( !DllCall(NumGet(NumGet(IFileSaveDialog+0)+3*A_PtrSize), "UPtr", IFileSaveDialog, "Ptr", Owner, "UInt") )
{
; IFileDialog::GetFileTypeIndex method
; https://msdn.microsoft.com/es-es/bb775958
DllCall(NumGet(NumGet(IFileSaveDialog+0)+6*A_PtrSize), "UPtr", IFileSaveDialog, "UIntP", FileTypeIndex)
; IFileDialog::GetResult method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775964(v=vs.85).aspx
if ( !DllCall(NumGet(NumGet(IFileSaveDialog+0)+20*A_PtrSize), "UPtr", IFileSaveDialog, "UPtrP", IShellItem) )
{
VarSetCapacity(Result, 32767 * 2, 0)
DllCall("Shell32.dll\SHGetIDListFromObject", "UPtr", IShellItem, "UPtrP", PIDL)
DllCall("Shell32.dll\SHGetPathFromIDListEx", "UPtr", PIDL, "Str", Result, "UInt", 2000, "UInt", 0)
Result := StrGet(&Result, "UTF-16")
ObjRawSet(Obj, IShellItem, PIDL)
}
}
for foo, bar in Obj ; foo = IShellItem interface (ptr) | bar = PIDL structure (ptr)
if foo is integer ; IShellItem?
ObjRelease(foo), DllCall("Ole32.dll\CoTaskMemFree", "UPtr", bar)
ObjRelease(IFileSaveDialog)
return (Result!=FALSE) ? {FileFullPath:Result,FilterIndex:FileTypeIndex} : FALSE
}
FileSelectFile(Open File) Demonstration:
Code: Select all
Result := ChooseFile( [0, "Dialog title - ChooseFile.."]
, A_ComSpec
, {All: "`n*.*", Music: "*.mp3", Images: "`n*.jpg;*.png", Videos: "*.avi;*.mp4;*.mkv;*.wmp", Documents: "*.txt"}
, [A_WinDir,A_Desktop,A_Temp,A_Startup,A_ProgramFiles]
, 0x10000000 | 0x02000000 | 0x00000200 | 0x00001000 )
If ((List := "") == "" && Result != FALSE)
For Each, File in Result.FileFullPath
List .= File . "`n"
MsgBox % "You Chose Filter: " Result.FilterIndex "`n" List
ExitApp
; FUNCTIONS
DirExist(DirName)
{
loop Files, % DirName, D
return A_LoopFileAttrib
}
StrPutVar(string, ByRef var, encoding)
{
; Ensure capacity.
VarSetCapacity( var, StrPut(string, encoding)
; StrPut returns char count, but VarSetCapacity needs bytes.
* ((encoding="utf-16"||encoding="cp1200") ? 2 : 1) )
; Copy or convert the string.
return StrPut(string, &var, encoding)
} ; https://www.autohotkey.com/docs/commands/StrPut.htm#Examples
/*
Displays a standard dialog that allows the user to open file(s).
Parameters:
Owner / Title:
The identifier of the window that owns this dialog. This value can be zero.
An Array with the identifier of the owner window and the title. If the title is an empty string, it is set to the default.
FileName:
The path to the file or directory selected by default. If you specify a directory, it must end with a backslash.
Filter:
Specify a file filter. You must specify an object, each key represents the description and the value the file types.
To specify the filter selected by default, add the "`n" character to the value.
CustomPlaces:
Specify an Array with the custom directories that will be displayed in the left pane. Missing directories will be omitted.
To specify the location in the list, specify an Array with the directory and its location (0 = Lower, 1 = Upper).
Options:
Determines the behavior of the dialog. This parameter must be one or more of the following values.
0x00000200 (FOS_ALLOWMULTISELECT) = Enables the user to select multiple items in the open dialog.
0x00001000 (FOS_FILEMUSTEXIST) = The item returned must exist.
0x00040000 (FOS_HIDEPINNEDPLACES) = Hide items shown by default in the view's navigation pane.
0x02000000 (FOS_DONTADDTORECENT) = Do not add the item being opened or saved to the recent documents list (SHAddToRecentDocs).
0x10000000 (FOS_FORCESHOWHIDDEN) = Include hidden and system items.
You can check all available values at https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx.
Return:
Returns 0 if the user canceled the dialog, otherwise returns the path of the selected file.
If you specified the FOS_ALLOWMULTISELECT option and the function succeeded, it returns an Array with the path of the selected files.
*/
ChooseFile(Owner, FileName := "", Filter := "", CustomPlaces := "", Options := 0x1000)
{
; IFileOpenDialog interface
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775834(v=vs.85).aspx
local IFileOpenDialog := ComObjCreate("{DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7}", "{D57C7288-D4AD-4768-BE02-9D969532D960}")
, Title := IsObject(Owner) ? Owner[2] . "" : ""
, Flags := Options ; FILEOPENDIALOGOPTIONS enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx)
, IShellItem := PIDL := 0 ; PIDL recibe la dirección de memoria a la estructura ITEMIDLIST que debe ser liberada con la función CoTaskMemFree
, Obj := {COMDLG_FILTERSPEC: ""}, foo := bar := ""
, Directory := FileName
Owner := IsObject(Owner) ? Owner[1] : (WinExist("ahk_id" . Owner) ? Owner : 0)
Filter := IsObject(Filter) ? Filter : {"All files": "*.*"}
if ( FileName != "" )
{
if ( InStr(FileName, "\") )
{
if !( FileName ~= "\\$" ) ; si «FileName» termina con "\" se trata de una carpeta
{
local File := ""
SplitPath FileName, File, Directory
; IFileDialog::SetFileName
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775974(v=vs.85).aspx
StrPutVar(File, FileW, "UTF-16")
DllCall(NumGet(NumGet(IFileOpenDialog+0)+15*A_PtrSize), "UPtr", IFileOpenDialog, "UPtr", &FileW)
}
while ( InStr(Directory,"\") && !DirExist(Directory) ) ; si el directorio no existe buscamos directorios superiores
Directory := SubStr(Directory, 1, InStr(Directory, "\",, -1) - 1) ; recupera el directorio superior
if ( DirExist(Directory) )
{
StrPutVar(Directory, DirectoryW, "UTF-16")
DllCall("Shell32.dll\SHParseDisplayName", "UPtr", &DirectoryW, "Ptr", 0, "UPtrP", PIDL, "UInt", 0, "UInt", 0)
DllCall("Shell32.dll\SHCreateShellItem", "Ptr", 0, "Ptr", 0, "UPtr", PIDL, "UPtrP", IShellItem)
ObjRawSet(Obj, IShellItem, PIDL)
; IFileDialog::SetFolder method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761828(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileOpenDialog+0)+12*A_PtrSize), "Ptr", IFileOpenDialog, "UPtr", IShellItem)
}
}
else
{
StrPutVar(FileName, FileNameW, "UTF-16")
DllCall(NumGet(NumGet(IFileOpenDialog+0)+15*A_PtrSize), "UPtr", IFileOpenDialog, "UPtr", &FileNameW)
}
}
; COMDLG_FILTERSPEC structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb773221(v=vs.85).aspx
local Description := "", FileTypes := "", FileTypeIndex := 1
ObjSetCapacity(Obj, "COMDLG_FILTERSPEC", 2*Filter.Count() * A_PtrSize)
for Description, FileTypes in Filter
{
FileTypeIndex := InStr(FileTypes,"`n") ? A_Index : FileTypeIndex
StrPutVar(Trim(Description), desc_%A_Index%, "UTF-16")
StrPutVar(Trim(StrReplace(FileTypes,"`n")), ft_%A_Index%, "UTF-16")
NumPut(&desc_%A_Index%, ObjGetAddress(Obj,"COMDLG_FILTERSPEC") + A_PtrSize * 2*(A_Index-1)) ; COMDLG_FILTERSPEC.pszName
NumPut(&ft_%A_Index%, ObjGetAddress(Obj,"COMDLG_FILTERSPEC") + A_PtrSize * (2*(A_Index-1)+1)) ; COMDLG_FILTERSPEC.pszSpec
}
; IFileDialog::SetFileTypes method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775980(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileOpenDialog+0)+4*A_PtrSize), "UPtr", IFileOpenDialog, "UInt", Filter.Count(), "UPtr", ObjGetAddress(Obj,"COMDLG_FILTERSPEC"))
; IFileDialog::SetFileTypeIndex method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775978(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileOpenDialog+0)+5*A_PtrSize), "UPtr", IFileOpenDialog, "UInt", FileTypeIndex)
if ( IsObject(CustomPlaces := IsObject(CustomPlaces) || CustomPlaces == "" ? CustomPlaces : [CustomPlaces]) )
{
for foo, Directory in CustomPlaces ; foo = index
{
foo := IsObject(Directory) ? Directory[2] : 0 ; FDAP enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/bb762502(v=vs.85).aspx)
if ( DirExist(Directory := IsObject(Directory) ? Directory[1] : Directory) )
{
StrPutVar(Directory, DirectoryW, "UTF-16")
DllCall("Shell32.dll\SHParseDisplayName", "UPtr", &DirectoryW, "Ptr", 0, "UPtrP", PIDL, "UInt", 0, "UInt", 0)
DllCall("Shell32.dll\SHCreateShellItem", "Ptr", 0, "Ptr", 0, "UPtr", PIDL, "UPtrP", IShellItem)
ObjRawSet(Obj, IShellItem, PIDL)
; IFileDialog::AddPlace method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775946(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileOpenDialog+0)+21*A_PtrSize), "UPtr", IFileOpenDialog, "UPtr", IShellItem, "UInt", foo)
}
}
}
; IFileDialog::SetTitle method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761834(v=vs.85).aspx
StrPutVar(Title, TitleW, "UTF-16")
DllCall(NumGet(NumGet(IFileOpenDialog+0)+17*A_PtrSize), "UPtr", IFileOpenDialog, "UPtr", Title == "" ? 0 : &TitleW)
; IFileDialog::SetOptions method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761832(v=vs.85).aspx
DllCall(NumGet(NumGet(IFileOpenDialog+0)+9*A_PtrSize), "UPtr", IFileOpenDialog, "UInt", Flags)
; IModalWindow::Show method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761688(v=vs.85).aspx
local Result := []
if ( !DllCall(NumGet(NumGet(IFileOpenDialog+0)+3*A_PtrSize), "UPtr", IFileOpenDialog, "Ptr", Owner, "UInt") )
{
; IFileOpenDialog::GetResults method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775831(v=vs.85).aspx
local IShellItemArray := 0 ; IShellItemArray interface (https://msdn.microsoft.com/en-us/library/windows/desktop/bb761106(v=vs.85).aspx)
DllCall(NumGet(NumGet(IFileOpenDialog+0)+27*A_PtrSize), "UPtr", IFileOpenDialog, "UPtrP", IShellItemArray)
; IShellItemArray::GetCount method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761098(v=vs.85).aspx
local Count := 0 ; pdwNumItems
DllCall(NumGet(NumGet(IShellItemArray+0)+7*A_PtrSize), "UPtr", IShellItemArray, "UIntP", Count, "UInt")
local Buffer := ""
loop % 0*VarSetCapacity(Buffer,32767 * 2) + Count
{
; IShellItemArray::GetItemAt method
; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761100(v=vs.85).aspx
DllCall(NumGet(NumGet(IShellItemArray+0)+8*A_PtrSize), "UPtr", IShellItemArray, "UInt", A_Index-1, "UPtrP", IShellItem)
DllCall("Shell32.dll\SHGetIDListFromObject", "UPtr", IShellItem, "UPtrP", PIDL)
DllCall("Shell32.dll\SHGetPathFromIDListEx", "UPtr", PIDL, "Str", Buffer, "UInt", 32767, "UInt", 0)
ObjRawSet(Obj, IShellItem, PIDL), ObjPush(Result, StrGet(&Buffer, "UTF-16"))
}
ObjRelease(IShellItemArray)
}
; IFileDialog::GetFileTypeIndex method
; https://msdn.microsoft.com/es-es/bb775958
DllCall(NumGet(NumGet(IFileOpenDialog+0)+6*A_PtrSize), "UPtr", IFileOpenDialog, "UIntP", FileTypeIndex)
msgbox %FileTypeIndex%
for foo, bar in Obj ; foo = IShellItem interface (ptr) | bar = PIDL structure (ptr)
if foo is integer ; IShellItem?
ObjRelease(foo), DllCall("Ole32.dll\CoTaskMemFree", "UPtr", bar)
ObjRelease(IFileOpenDialog)
return ObjLength(Result) ? {FileFullPath:(Options & 0x200 ? Result : Result[1]),FilterIndex:FileTypeIndex} : FALSE
}
Problem Solved!
Last edited by aldrinjohnom on 17 Oct 2020, 04:33, edited 1 time in total.
Developer of AJOM's DOTA2 MOD Master, Easiest way to MOD your DOTA2 without the use of internet . I created this program using Autohotkey thats why I love Autohotkey and the community!
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
-
- Posts: 77
- Joined: 18 Apr 2018, 08:49
Re: FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list
OK, So I have been using @Flipeador's function for almost a year now. Now I am facing a problem with "Read-Only" FIles. I cannot select this files, Can you help me with this?
Developer of AJOM's DOTA2 MOD Master, Easiest way to MOD your DOTA2 without the use of internet . I created this program using Autohotkey thats why I love Autohotkey and the community!
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
-
- Posts: 77
- Joined: 18 Apr 2018, 08:49
Re: FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list
@Flipeador I am having a problem with all these function at ANSI Build. I tried it on Unicode and it is working great, but when I Tried compiling a code in ANSI, I get this weird look: Can you help me fix it? I am not that good on manipulating dll calls and how it works but I wish you to bear with me. Thank you!Flipeador wrote: ↑03 Aug 2018, 20:29Minimum requirements: AutoHotkey 1.1.29.01, Windows Vista.
Required functions:Code: Select all
DirExist(DirName) { loop Files, % DirName, D return A_LoopFileAttrib }
ChooseFolder
Code: Select all
/* Displays a standard dialog that allows the user to select folder(s). Parameters: Owner / Title: The identifier of the window that owns this dialog. This value can be zero. An Array with the identifier of the owner window and the title. If the title is an empty string, it is set to the default. StartingFolder: The path to the directory selected by default. If the directory does not exist, it searches in higher directories. CustomPlaces: Specify an Array with the custom directories that will be displayed in the left pane. Missing directories will be omitted. To specify the location in the list, specify an Array with the directory and its location (0 = Lower, 1 = Upper). Options: Determines the behavior of the dialog. This parameter must be one or more of the following values. 0x00000200 (FOS_ALLOWMULTISELECT) = Enables the user to select multiple items in the open dialog. 0x00040000 (FOS_HIDEPINNEDPLACES) = Hide items shown by default in the view's navigation pane. 0x02000000 (FOS_DONTADDTORECENT) = Do not add the item being opened or saved to the recent documents list (SHAddToRecentDocs). 0x10000000 (FOS_FORCESHOWHIDDEN) = Include hidden and system items. You can check all available values at https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx. Return: Returns zero if the user canceled the dialog, otherwise returns the path of the selected directory. The directory never ends with "\". */ ChooseFolder(Owner, StartingFolder := "", CustomPlaces := "", Options := 0) { ; IFileOpenDialog interface ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775834(v=vs.85).aspx local IFileOpenDialog := ComObjCreate("{DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7}", "{D57C7288-D4AD-4768-BE02-9D969532D960}") , Title := IsObject(Owner) ? Owner[2] . "" : "" , Flags := 0x20 | Options ; FILEOPENDIALOGOPTIONS enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx) , IShellItem := PIDL := 0 ; PIDL recibe la dirección de memoria a la estructura ITEMIDLIST que debe ser liberada con la función CoTaskMemFree , Obj := {}, foo := bar := "" Owner := IsObject(Owner) ? Owner[1] : (WinExist("ahk_id" . Owner) ? Owner : 0) CustomPlaces := IsObject(CustomPlaces) || CustomPlaces == "" ? CustomPlaces : [CustomPlaces] while (InStr(StartingFolder, "\") && !DirExist(StartingFolder)) ; si el directorio no existe buscamos directorios superiores StartingFolder := SubStr(StartingFolder, 1, InStr(StartingFolder, "\",, -1) - 1) if ( DirExist(StartingFolder) ) { DllCall("Shell32.dll\SHParseDisplayName", "UPtr", &StartingFolder, "Ptr", 0, "UPtrP", PIDL, "UInt", 0, "UInt", 0) DllCall("Shell32.dll\SHCreateShellItem", "Ptr", 0, "Ptr", 0, "UPtr", PIDL, "UPtrP", IShellItem) ObjRawSet(Obj, IShellItem, PIDL) ; guardamos la interfaz «IShellItem» y la estructura «PIDL» para liberarlas al final ; IFileDialog::SetFolder method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761828(v=vs.85).aspx DllCall(NumGet(NumGet(IFileOpenDialog+0)+12*A_PtrSize), "Ptr", IFileOpenDialog, "UPtr", IShellItem) } if ( IsObject(CustomPlaces) ) { local Directory := "" For foo, Directory in CustomPlaces ; foo = index { foo := IsObject(Directory) ? Directory[2] : 0 ; FDAP enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/bb762502(v=vs.85).aspx) if ( DirExist(Directory := IsObject(Directory) ? Directory[1] : Directory) ) { DllCall("Shell32.dll\SHParseDisplayName", "UPtr", &Directory, "Ptr", 0, "UPtrP", PIDL, "UInt", 0, "UInt", 0) DllCall("Shell32.dll\SHCreateShellItem", "Ptr", 0, "Ptr", 0, "UPtr", PIDL, "UPtrP", IShellItem) ObjRawSet(Obj, IShellItem, PIDL) ; IFileDialog::AddPlace method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775946(v=vs.85).aspx DllCall(NumGet(NumGet(IFileOpenDialog+0)+21*A_PtrSize), "UPtr", IFileOpenDialog, "UPtr", IShellItem, "UInt", foo) } } } ; IFileDialog::SetTitle method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761834(v=vs.85).aspx DllCall(NumGet(NumGet(IFileOpenDialog+0)+17*A_PtrSize), "UPtr", IFileOpenDialog, "UPtr", Title == "" ? 0 : &Title) ; IFileDialog::SetOptions method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761832(v=vs.85).aspx DllCall(NumGet(NumGet(IFileOpenDialog+0)+9*A_PtrSize), "UPtr", IFileOpenDialog, "UInt", Flags) ; IModalWindow::Show method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761688(v=vs.85).aspx local Result := [] if ( !DllCall(NumGet(NumGet(IFileOpenDialog+0)+3*A_PtrSize), "UPtr", IFileOpenDialog, "Ptr", Owner, "UInt") ) { ; IFileOpenDialog::GetResults method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775831(v=vs.85).aspx local IShellItemArray := 0 ; IShellItemArray interface (https://msdn.microsoft.com/en-us/library/windows/desktop/bb761106(v=vs.85).aspx) DllCall(NumGet(NumGet(IFileOpenDialog+0)+27*A_PtrSize), "UPtr", IFileOpenDialog, "UPtrP", IShellItemArray) ; IShellItemArray::GetCount method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761098(v=vs.85).aspx local Count := 0 ; pdwNumItems DllCall(NumGet(NumGet(IShellItemArray+0)+7*A_PtrSize), "UPtr", IShellItemArray, "UIntP", Count) local Buffer := "" VarSetCapacity(Buffer, 32767 * 2) loop % Count { ; IShellItemArray::GetItemAt method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761100(v=vs.85).aspx DllCall(NumGet(NumGet(IShellItemArray+0)+8*A_PtrSize), "UPtr", IShellItemArray, "UInt", A_Index-1, "UPtrP", IShellItem) DllCall("Shell32.dll\SHGetIDListFromObject", "UPtr", IShellItem, "UPtrP", PIDL) DllCall("Shell32.dll\SHGetPathFromIDListEx", "UPtr", PIDL, "Str", Buffer, "UInt", 32767, "UInt", 0) ObjRawSet(Obj, IShellItem, PIDL), ObjPush(Result, RTrim(Buffer, "\")) } ObjRelease(IShellItemArray) } for foo, bar in Obj ; foo = IShellItem interface (ptr) | bar = PIDL structure (ptr) ObjRelease(foo), DllCall("Ole32.dll\CoTaskMemFree", "UPtr", bar) ObjRelease(IFileOpenDialog) return ObjLength(Result) ? ( Options & 0x200 ? Result : Result[1] ) : FALSE }
ChooseFile
Code: Select all
/* Displays a standard dialog that allows the user to open file(s). Parameters: Owner / Title: The identifier of the window that owns this dialog. This value can be zero. An Array with the identifier of the owner window and the title. If the title is an empty string, it is set to the default. FileName: The path to the file or directory selected by default. If you specify a directory, it must end with a backslash. Filter: Specify a file filter. You must specify an object, each key represents the description and the value the file types. To specify the filter selected by default, add the "`n" character to the value. CustomPlaces: Specify an Array with the custom directories that will be displayed in the left pane. Missing directories will be omitted. To specify the location in the list, specify an Array with the directory and its location (0 = Lower, 1 = Upper). Options: Determines the behavior of the dialog. This parameter must be one or more of the following values. 0x00000200 (FOS_ALLOWMULTISELECT) = Enables the user to select multiple items in the open dialog. 0x00001000 (FOS_FILEMUSTEXIST) = The item returned must exist. 0x00040000 (FOS_HIDEPINNEDPLACES) = Hide items shown by default in the view's navigation pane. 0x02000000 (FOS_DONTADDTORECENT) = Do not add the item being opened or saved to the recent documents list (SHAddToRecentDocs). 0x10000000 (FOS_FORCESHOWHIDDEN) = Include hidden and system items. You can check all available values at https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx. Return: Returns 0 if the user canceled the dialog, otherwise returns the path of the selected file. If you specified the FOS_ALLOWMULTISELECT option and the function succeeded, it returns an Array with the path of the selected files. */ ChooseFile(Owner, FileName := "", Filter := "", CustomPlaces := "", Options := 0x1000) { ; IFileOpenDialog interface ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775834(v=vs.85).aspx local IFileOpenDialog := ComObjCreate("{DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7}", "{D57C7288-D4AD-4768-BE02-9D969532D960}") , Title := IsObject(Owner) ? Owner[2] . "" : "" , Flags := Options ; FILEOPENDIALOGOPTIONS enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx) , IShellItem := PIDL := 0 ; PIDL recibe la dirección de memoria a la estructura ITEMIDLIST que debe ser liberada con la función CoTaskMemFree , Obj := {COMDLG_FILTERSPEC: ""}, foo := bar := "" , Directory := FileName Owner := IsObject(Owner) ? Owner[1] : (WinExist("ahk_id" . Owner) ? Owner : 0) Filter := IsObject(Filter) ? Filter : {"All files": "*.*"} if ( FileName != "" ) { if ( InStr(FileName, "\") ) { if !( FileName ~= "\\$" ) ; si «FileName» termina con "\" se trata de una carpeta { local File := "" SplitPath FileName, File, Directory ; IFileDialog::SetFileName ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775974(v=vs.85).aspx DllCall(NumGet(NumGet(IFileOpenDialog+0)+15*A_PtrSize), "UPtr", IFileOpenDialog, "UPtr", &File) } while ( InStr(Directory,"\") && !DirExist(Directory) ) ; si el directorio no existe buscamos directorios superiores Directory := SubStr(Directory, 1, InStr(Directory, "\",, -1) - 1) ; recupera el directorio superior if ( DirExist(Directory) ) { DllCall("Shell32.dll\SHParseDisplayName", "UPtr", &Directory, "Ptr", 0, "UPtrP", PIDL, "UInt", 0, "UInt", 0) DllCall("Shell32.dll\SHCreateShellItem", "Ptr", 0, "Ptr", 0, "UPtr", PIDL, "UPtrP", IShellItem) ObjRawSet(Obj, IShellItem, PIDL) ; IFileDialog::SetFolder method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761828(v=vs.85).aspx DllCall(NumGet(NumGet(IFileOpenDialog+0)+12*A_PtrSize), "Ptr", IFileOpenDialog, "UPtr", IShellItem) } } else ; si «FileName» es únicamente el nombre de un archivo DllCall(NumGet(NumGet(IFileOpenDialog+0)+15*A_PtrSize), "UPtr", IFileOpenDialog, "UPtr", &FileName) } ; COMDLG_FILTERSPEC structure ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb773221(v=vs.85).aspx local Description := "", FileTypes := "", FileTypeIndex := 1 ObjSetCapacity(Obj, "COMDLG_FILTERSPEC", 2*Filter.Count() * A_PtrSize) for Description, FileTypes in Filter { FileTypeIndex := InStr(FileTypes,"`n") ? A_Index : FileTypeIndex ObjRawSet(Obj, "#" . A_Index, Trim(Description)), ObjRawSet(Obj, "@" . A_Index, Trim(StrReplace(FileTypes,"`n"))) NumPut(ObjGetAddress(Obj,"#" . A_Index), ObjGetAddress(Obj,"COMDLG_FILTERSPEC") + A_PtrSize * 2*(A_Index-1)) ; COMDLG_FILTERSPEC.pszName NumPut(ObjGetAddress(Obj,"@" . A_Index), ObjGetAddress(Obj,"COMDLG_FILTERSPEC") + A_PtrSize * (2*(A_Index-1)+1)) ; COMDLG_FILTERSPEC.pszSpec } ; IFileDialog::SetFileTypes method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775980(v=vs.85).aspx DllCall(NumGet(NumGet(IFileOpenDialog+0)+4*A_PtrSize), "UPtr", IFileOpenDialog, "UInt", Filter.Count(), "UPtr", ObjGetAddress(Obj,"COMDLG_FILTERSPEC")) ; IFileDialog::SetFileTypeIndex method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775978(v=vs.85).aspx DllCall(NumGet(NumGet(IFileOpenDialog+0)+5*A_PtrSize), "UPtr", IFileOpenDialog, "UInt", FileTypeIndex) if ( IsObject(CustomPlaces := IsObject(CustomPlaces) || CustomPlaces == "" ? CustomPlaces : [CustomPlaces]) ) { local Directory := "" for foo, Directory in CustomPlaces ; foo = index { foo := IsObject(Directory) ? Directory[2] : 0 ; FDAP enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/bb762502(v=vs.85).aspx) if ( DirExist(Directory := IsObject(Directory) ? Directory[1] : Directory) ) { DllCall("Shell32.dll\SHParseDisplayName", "UPtr", &Directory, "Ptr", 0, "UPtrP", PIDL, "UInt", 0, "UInt", 0) DllCall("Shell32.dll\SHCreateShellItem", "Ptr", 0, "Ptr", 0, "UPtr", PIDL, "UPtrP", IShellItem) ObjRawSet(Obj, IShellItem, PIDL) ; IFileDialog::AddPlace method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775946(v=vs.85).aspx DllCall(NumGet(NumGet(IFileOpenDialog+0)+21*A_PtrSize), "UPtr", IFileOpenDialog, "UPtr", IShellItem, "UInt", foo) } } } ; IFileDialog::SetTitle method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761834(v=vs.85).aspx DllCall(NumGet(NumGet(IFileOpenDialog+0)+17*A_PtrSize), "UPtr", IFileOpenDialog, "UPtr", Title == "" ? 0 : &Title) ; IFileDialog::SetOptions method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761832(v=vs.85).aspx DllCall(NumGet(NumGet(IFileOpenDialog+0)+9*A_PtrSize), "UPtr", IFileOpenDialog, "UInt", Flags) ; IModalWindow::Show method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761688(v=vs.85).aspx local Result := [] if ( !DllCall(NumGet(NumGet(IFileOpenDialog+0)+3*A_PtrSize), "UPtr", IFileOpenDialog, "Ptr", Owner, "UInt") ) { ; IFileOpenDialog::GetResults method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775831(v=vs.85).aspx local IShellItemArray := 0 ; IShellItemArray interface (https://msdn.microsoft.com/en-us/library/windows/desktop/bb761106(v=vs.85).aspx) DllCall(NumGet(NumGet(IFileOpenDialog+0)+27*A_PtrSize), "UPtr", IFileOpenDialog, "UPtrP", IShellItemArray) ; IShellItemArray::GetCount method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761098(v=vs.85).aspx local Count := 0 ; pdwNumItems DllCall(NumGet(NumGet(IShellItemArray+0)+7*A_PtrSize), "UPtr", IShellItemArray, "UIntP", Count, "UInt") local Buffer := "" loop % 0*VarSetCapacity(Buffer,32767 * 2) + Count { ; IShellItemArray::GetItemAt method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761100(v=vs.85).aspx DllCall(NumGet(NumGet(IShellItemArray+0)+8*A_PtrSize), "UPtr", IShellItemArray, "UInt", A_Index-1, "UPtrP", IShellItem) DllCall("Shell32.dll\SHGetIDListFromObject", "UPtr", IShellItem, "UPtrP", PIDL) DllCall("Shell32.dll\SHGetPathFromIDListEx", "UPtr", PIDL, "Str", Buffer, "UInt", 32767, "UInt", 0) ObjRawSet(Obj, IShellItem, PIDL), ObjPush(Result, Buffer) } ObjRelease(IShellItemArray) } for foo, bar in Obj ; foo = IShellItem interface (ptr) | bar = PIDL structure (ptr) if foo is integer ; IShellItem? ObjRelease(foo), DllCall("Ole32.dll\CoTaskMemFree", "UPtr", bar) ObjRelease(IFileOpenDialog) return ObjLength(Result) ? (Options & 0x200 ? Result : Result[1]) : FALSE }
SaveFile
Code: Select all
/* Displays a standard dialog that allows the user to save a file. Parameters: Owner / Title: The identifier of the window that owns this dialog. This value can be zero. An Array with the identifier of the owner window and the title. If the title is an empty string, it is set to the default. FileName: The path to the file or directory selected by default. If you specify a directory, it must end with a backslash. Filter: Specify a file filter. You must specify an object, each key represents the description and the value the file types. To specify the filter selected by default, add the "`n" character to the value. CustomPlaces: Specify an Array with the custom directories that will be displayed in the left pane. Missing directories will be omitted. To specify the location in the list, specify an Array with the directory and its location (0 = Lower, 1 = Upper). Options: Determines the behavior of the dialog. This parameter must be one or more of the following values. 0x00000002 (FOS_OVERWRITEPROMPT) = When saving a file, prompt before overwriting an existing file of the same name. 0x00000004 (FOS_STRICTFILETYPES) = Only allow the user to choose a file that has one of the file name extensions specified through Filter. 0x00040000 (FOS_HIDEPINNEDPLACES) = Hide items shown by default in the view's navigation pane. 0x10000000 (FOS_FORCESHOWHIDDEN) = Include hidden and system items. 0x02000000 (FOS_DONTADDTORECENT) = Do not add the item being opened or saved to the recent documents list (SHAddToRecentDocs). You can check all available values at https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx. Return: Returns 0 if the user canceled the dialog, otherwise returns the path of the selected file. */ SaveFile(Owner, FileName := "", Filter := "", CustomPlaces := "", Options := 0x6) { ; IFileSaveDialog interface ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775688(v=vs.85).aspx local IFileSaveDialog := ComObjCreate("{C0B4E2F3-BA21-4773-8DBA-335EC946EB8B}", "{84BCCD23-5FDE-4CDB-AEA4-AF64B83D78AB}") , Title := IsObject(Owner) ? Owner[2] . "" : "" , Flags := Options ; FILEOPENDIALOGOPTIONS enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/dn457282(v=vs.85).aspx) , IShellItem := PIDL := 0 ; PIDL recibe la dirección de memoria a la estructura ITEMIDLIST que debe ser liberada con la función CoTaskMemFree , Obj := {}, foo := bar := "" , Directory := FileName Owner := IsObject(Owner) ? Owner[1] : (WinExist("ahk_id" . Owner) ? Owner : 0) Filter := IsObject(Filter) ? Filter : {"All files": "*.*"} if ( FileName != "" ) { if ( InStr(FileName, "\") ) { if !( FileName ~= "\\$" ) ; si «FileName» termina con "\" se trata de una carpeta { local File := "" SplitPath FileName, File, Directory ; IFileDialog::SetFileName ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775974(v=vs.85).aspx DllCall(NumGet(NumGet(IFileSaveDialog+0)+15*A_PtrSize), "UPtr", IFileSaveDialog, "UPtr", &File) } while ( InStr(Directory,"\") && !DirExist(Directory) ) ; si el directorio no existe buscamos directorios superiores Directory := SubStr(Directory, 1, InStr(Directory, "\",, -1) - 1) ; recupera el directorio superior if ( DirExist(Directory) ) { DllCall("Shell32.dll\SHParseDisplayName", "UPtr", &Directory, "Ptr", 0, "UPtrP", PIDL, "UInt", 0, "UInt", 0) DllCall("Shell32.dll\SHCreateShellItem", "Ptr", 0, "Ptr", 0, "UPtr", PIDL, "UPtrP", IShellItem) ObjRawSet(Obj, IShellItem, PIDL) ; IFileDialog::SetFolder method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761828(v=vs.85).aspx DllCall(NumGet(NumGet(IFileSaveDialog+0)+12*A_PtrSize), "Ptr", IFileSaveDialog, "UPtr", IShellItem) } } else ; si «FileName» es únicamente el nombre de un archivo DllCall(NumGet(NumGet(IFileSaveDialog+0)+15*A_PtrSize), "UPtr", IFileSaveDialog, "UPtr", &FileName) } ; COMDLG_FILTERSPEC structure ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb773221(v=vs.85).aspx local Description := "", FileTypes := "", FileTypeIndex := 1 ObjSetCapacity(Obj, "COMDLG_FILTERSPEC", 2*Filter.Count() * A_PtrSize) for Description, FileTypes in Filter { FileTypeIndex := InStr(FileTypes,"`n") ? A_Index : FileTypeIndex ObjRawSet(Obj, "#" . A_Index, Trim(Description)), ObjRawSet(Obj, "@" . A_Index, Trim(StrReplace(FileTypes,"`n"))) NumPut(ObjGetAddress(Obj,"#" . A_Index), ObjGetAddress(Obj,"COMDLG_FILTERSPEC") + A_PtrSize * 2*(A_Index-1)) ; COMDLG_FILTERSPEC.pszName NumPut(ObjGetAddress(Obj,"@" . A_Index), ObjGetAddress(Obj,"COMDLG_FILTERSPEC") + A_PtrSize * (2*(A_Index-1)+1)) ; COMDLG_FILTERSPEC.pszSpec } ; IFileDialog::SetFileTypes method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775980(v=vs.85).aspx DllCall(NumGet(NumGet(IFileSaveDialog+0)+4*A_PtrSize), "UPtr", IFileSaveDialog, "UInt", Filter.Count(), "UPtr", ObjGetAddress(Obj,"COMDLG_FILTERSPEC")) ; IFileDialog::SetFileTypeIndex method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775978(v=vs.85).aspx DllCall(NumGet(NumGet(IFileSaveDialog+0)+5*A_PtrSize), "UPtr", IFileSaveDialog, "UInt", FileTypeIndex) if ( IsObject(CustomPlaces := IsObject(CustomPlaces) || CustomPlaces == "" ? CustomPlaces : [CustomPlaces]) ) { local Directory := "" for foo, Directory in CustomPlaces ; foo = index { foo := IsObject(Directory) ? Directory[2] : 0 ; FDAP enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/bb762502(v=vs.85).aspx) if ( DirExist(Directory := IsObject(Directory) ? Directory[1] : Directory) ) { DllCall("Shell32.dll\SHParseDisplayName", "UPtr", &Directory, "Ptr", 0, "UPtrP", PIDL, "UInt", 0, "UInt", 0) DllCall("Shell32.dll\SHCreateShellItem", "Ptr", 0, "Ptr", 0, "UPtr", PIDL, "UPtrP", IShellItem) ObjRawSet(Obj, IShellItem, PIDL) ; IFileDialog::AddPlace method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775946(v=vs.85).aspx DllCall(NumGet(NumGet(IFileSaveDialog+0)+21*A_PtrSize), "UPtr", IFileSaveDialog, "UPtr", IShellItem, "UInt", foo) } } } ; IFileDialog::SetTitle method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761834(v=vs.85).aspx DllCall(NumGet(NumGet(IFileSaveDialog+0)+17*A_PtrSize), "UPtr", IFileSaveDialog, "UPtr", Title == "" ? 0 : &Title) ; IFileDialog::SetOptions method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761832(v=vs.85).aspx DllCall(NumGet(NumGet(IFileSaveDialog+0)+9*A_PtrSize), "UPtr", IFileSaveDialog, "UInt", Flags) ; IModalWindow::Show method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb761688(v=vs.85).aspx local Result := FALSE if ( !DllCall(NumGet(NumGet(IFileSaveDialog+0)+3*A_PtrSize), "UPtr", IFileSaveDialog, "Ptr", Owner, "UInt") ) { ; IFileDialog::GetResult method ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775964(v=vs.85).aspx if ( !DllCall(NumGet(NumGet(IFileSaveDialog+0)+20*A_PtrSize), "UPtr", IFileSaveDialog, "UPtrP", IShellItem) ) { VarSetCapacity(Result, 32767 * 2, 0) DllCall("Shell32.dll\SHGetIDListFromObject", "UPtr", IShellItem, "UPtrP", PIDL) DllCall("Shell32.dll\SHGetPathFromIDListEx", "UPtr", PIDL, "Str", Result, "UInt", 2000, "UInt", 0) ObjRawSet(Obj, IShellItem, PIDL) } } for foo, bar in Obj ; foo = IShellItem interface (ptr) | bar = PIDL structure (ptr) if foo is integer ; IShellItem? ObjRelease(foo), DllCall("Ole32.dll\CoTaskMemFree", "UPtr", bar) ObjRelease(IFileSaveDialog) return Result }
Developer of AJOM's DOTA2 MOD Master, Easiest way to MOD your DOTA2 without the use of internet . I created this program using Autohotkey thats why I love Autohotkey and the community!
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
-
- Posts: 77
- Joined: 18 Apr 2018, 08:49
Re: FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list
Thank you for responding to my request,This are the result: Only one problem remains identical to all of them, the title shows weird looking characters. You are super great my friend, I hope you can fix it,all credits are yours.Flipeador wrote: ↑16 Oct 2020, 06:22Hello @aldrinjohnom,
Try again: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=53136&p=231879#p231879.
Developer of AJOM's DOTA2 MOD Master, Easiest way to MOD your DOTA2 without the use of internet . I created this program using Autohotkey thats why I love Autohotkey and the community!
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
-
- Posts: 77
- Joined: 18 Apr 2018, 08:49
Re: FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list
You are an AHK god, thank you very much! Problem about SaveFile() and ChooseFile() are fixed.
Now there is one issue regarding ChooseFolder(): When I select a "short" folder(mostly found at the left side of the "explorer") the function fails to get the directory. Im Sorry if I find so many problems, I can see a potential on this function to absolutely replace FileSelectFile and FileSelectFolder. I wish you can fix it for the last time my friend , when this problem is fixed, more people will be benefited as I see.
Developer of AJOM's DOTA2 MOD Master, Easiest way to MOD your DOTA2 without the use of internet . I created this program using Autohotkey thats why I love Autohotkey and the community!
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
GitHub:
https://github.com/Aldrin-John-Olaer-Manalansan
-
- Posts: 46
- Joined: 07 May 2020, 07:02
Re: FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list
It seems to crash after selecting multiple folders (Using your provided example). No matter what version of AHK I run, 32 or 64. Any suggestions?
Re: FileSelectFile still not support multiple Filter at dialog's "files of type" drop-down list
@kairushinjuu I think I found the problem. Try again.
Who is online
Users browsing this forum: Bing [Bot] and 117 guests