Loop files doesn't properly handle filters

Issue #5 closed
Matt Feemster repo owner created an issue
pattern := A_ScriptDir "\*"
n := 15

; Create a menu.
Fmenu := Menu()

; Allocate memory for a SHFILEINFOW struct.
fisize := A_PtrSize + 688
fileinfo := Buffer(fisize)

Loop Files, pattern, "FD"
{
    ; Add a menu item for each file.
    Fmenu.Add(A_LoopFileName, "") ; Do nothing.

    ; Get the file's icon.
    if DllCall("shell32\SHGetFileInfoW", "Str", A_LoopFileFullPath
        , "UInt", 0, "Ptr", fileinfo, "UInt", fisize, "UInt", 0x100)
    {
        hicon := NumGet(fileinfo, 0, "Ptr")
        ; Set the menu item's icon.
        Fmenu.SetIcon(A_Index "&", "HICON:" hicon)
        ; Because we used ":" and not ":*", the icon will be automatically
        ; freed when the program exits or if the menu or item is deleted.
    }
}
until A_Index = n
Fmenu.Show()

Comments (5)

  1. Matt Feemster reporter

    I believe this is working properly. The problem is that you look through only 16 items, and there are 15 folders in my ouput folder of “bin\debug\net6.0-windows”.

    Do

    n := 25
    

    and you’ll see file entries on the menu with their proper icons displayed.

    Please confirm and we’ll close this.

  2. Winter Laite

    I tried the code above with both “n := 15” and “n := 25” and got the following error:

    Uncaught exception:
    
    Message: Object reference not set to an instance of an object.
    
    Stack:    at Keysharp.Scripting.Script.Invoke(Object del, Object[] parameters) in C:\Users\HP6300\Documents\repos\keysharp\Keysharp.Core\Scripting\Script\Call.cs:line 38
    
       at Keysharp.CompiledMain.Program.Main(String[] args)
    

  3. Log in to comment