Shows a list of programs to choose to open associated file types in.
Just compile it and associate the file types you want to control with the compiled exe.
The first time it is run, it creates an ini-file with a list of the programs to choose from. Just edit this file to suit your needs.
It's just an early draft, just test it and see if you can use it.
; Shows a list of programs to choose to open associated file types in
;Skrommel @ 2009
; Create the ListView and its columns:
Gui,+ToolWindow +AutoSize +Resize
Gui, Add, ListView, x0 y0 vlistview GLISTVIEW AltSubmit, Name|Program|WorkFolder|Parameters
LV_ModifyCol(3, "Integer") ; For sorting, indicate that the Size column is an integer.
; Create an ImageList so that the ListView can display some icons:
ImageListID1 := IL_Create(10)
ImageListID2 := IL_Create(10, 10, true) ; A list of large icons to go with the small ones.
; Attach the ImageLists to the ListView so that it can later display the icons:
; Ensure the variable has enough capacity to hold the longest file path. This is done
; because ExtractAssociatedIconA() needs to be able to store a new filename in it.
sfi_size = 352
; Gather a list of file names from the selected folder and append them to the ListView:
GuiControl, -Redraw, listview ; Improve performance by disabling redrawing during load.
If (exepath="" Or exepath="ERROR")
GuiControl, +Icon, listview ; Switch to icon view.
GuiControl, +Redraw, listview ; Improve performance by disabling redrawing during load.
If (name="" Or name="ERROR")
If (iconpath="" Or iconpath="ERROR")
FileName:=iconpath ; Must save it to a writable variable for use below.
; Build a unique extension ID to avoid characters that are illegal in variable names,
; such as dashes. This unique ID method also performs better because finding an item
; in the array does not require search-loop.
SplitPath, FileName,,, FileExt ; Get the file's extension.
If FileExt in EXE,ICO,ANI,CUR
ExtID := FileExt ; Special ID as a placeholder.
IconNumber = 0 ; Flag it as not found so that these types can each have a unique icon.
Else ; Some other extension/file-type, so calculate its unique ID.
ExtID = 0 ; Initialize to handle extensions that are shorter than others.
Loop 7 ; Limit the extension to 7 characters so that it fits in a 64-bit value.
StringMid, ExtChar, FileExt, A_Index, 1
If not ExtChar ; No more characters.
; Derive a Unique ID by assigning a different bit position to each character:
ExtID := ExtID | (Asc(ExtChar) << (8 * (A_Index - 1)))
; Check if this file extension already has an icon in the ImageLists. If it does,
; several calls can be avoided and loading performance is greatly improved,
; especially for a folder containing hundreds of files:
IconNumber := IconArray%ExtID%
If Not IconNumber ; There is not yet any icon for this extension, so load it.
; Get the high-quality small-icon associated with this file extension:
If Not DllCall("Shell32\SHGetFileInfoA", "str", FileName, "uint", 0, "str", sfi, "uint", sfi_size, "uint", 0x101) ; 0x101 is SHGFI_ICON+SHGFI_SMALLICON
IconNumber = 9999999 ; Set it out of bounds to display a blank icon.
Else ; Icon successfully loaded.
; Extract the hIcon member from the structure:
hIcon = 0
hIcon += *(&sfi + A_Index-1) << 8*(A_Index-1)
; Add the HICON directly to the small-icon and large-icon lists.
; Below uses +1 to convert the returned index from zero-based to one-based:
IconNumber := DllCall("ImageList_ReplaceIcon", "uint", ImageListID1, "int", -1, "uint", hIcon) + 1
DllCall("ImageList_ReplaceIcon", "uint", ImageListID2, "int", -1, "uint", hIcon)
; Now that it's been copied into the ImageLists, the original should be destroyed:
DllCall("DestroyIcon", "uint", hIcon)
; Cache the icon to save memory and improve loading performance:
IconArray%ExtID% := IconNumber
; Create the new row in the ListView and assign it the icon number determined above:
LV_Add("Icon" . IconNumber, name, exepath, workfolder, parameters)
GuiControl, +Redraw, listview ; Re-enable redrawing (it was disabled above).
LV_ModifyCol() ; Auto-size each column to fit its contents.
LV_ModifyCol(3, 60) ; Make the Size column at little wider to reveal its header.
If A_GuiEvent = Normal ; There are many other possible values the script can check.
LV_GetText(name, A_EventInfo, 1) ; Get the text of the first field.
LV_GetText(exepath, A_EventInfo, 2) ; Get the text of the second field.
LV_GetText(workfolder, A_EventInfo, 3)
LV_GetText(parameters, A_EventInfo, 4)
Run,%exepath% "%1%" %parameters%,%workfolder%, UseErrorLevel
MsgBox,Could not open "%exepath%.
GuiSize: ; Expand or shrink the ListView in response to the user's resizing of the window.
If A_EventInfo = 1 ; The window has been minimized. No action needed.
; Otherwise, the window has been resized or maximized. Resize the ListView to match.
GuiControl, Move, listview, % "W" . (A_GuiWidth) . " H" . (A_GuiHeight)