HBITMAP - HICON for Image Handles - help needed.

Issue #54 closed
Winter Laite created an issue

Image Handles doc page is here.

Affects

“HBITMAP” and “HICON” are giving me trouble. Code is below.

Comments (10)

  1. Matt Feemster repo owner

    These are present in Keysharp.Core.Common.ImageHelper.LoadImage(), which all of those functions eventually call.

    Are you filing this just because you didn’t find it in the code, or because you ran a test and it failed?

    If it’s the former, please close this ticket. If it’s the latter, please provide a test script to reproduce the problem.

    Thanks.

  2. Matt Feemster repo owner

    Passing the * suffix was not being properly processed, but this included many bugs and I’ve attempted to fix them all.

    Properly scaling with h-1 was also not working.

    Please give it another try and see if it’s fixed.

  3. Winter Laite reporter

    Test code (not working):

    Pics := []
    ; Find some pictures to display.
    Loop Files, A_WinDir "\Web\Wallpaper\*.jpg", "R"
    {
        ; Load each picture and add it to the array.
        Pics.Push(LoadPicture(A_LoopFileFullPath))
    }
    if (!Pics.Length)
    {
        ; If this happens, edit the path on the Loop line above.
        MsgBox("No pictures found! Try a different directory.")
        ExitApp
    }
    ; Add the picture control, preserving the aspect ratio of the first picture.
    MyGui := Gui()
    Pic := MyGui.Add("Picture", "w600 h-1 +Border", "HBITMAP:*" Pics[1])
    
    MyGui.Show()
    Loop 
    {
        ; Switch pictures!
        Pic.Value := "HBITMAP:*" Pics[Mod(A_Index, Pics.Length)+1]
        Sleep 3000
    }
    

  4. Winter Laite reporter

    Error:

    Uncaught Keysharp exception: 
    Message: C:\Users\HP6300\Documents\repos\keysharp_debug\keysharp\bin\debug\net6.0-windows\HBITMAP:*{"Handle":"Keysharp.Core.Common.GdiHandleHolder","ImageType":"0"} 
    What: Keysharp.Core.Common.ImageHelper.LoadImage() 
    Extra: 
    File: C:\Users\HP6300\Documents\repos\keysharp_debug\keysharp\Keysharp.Core\Common\Images\ImageHelper.cs 
    Line: 197 
    Stack:    at Keysharp.Core.Common.ImageHelper.LoadImage(String filename, Int32 w, Int32 h, Object iconindex) in C:\Users\HP6300\Documents\repos\keysharp_debug\keysharp\Keysharp.Core\Common\Images\ImageHelper.cs:line 197 
    

  5. Matt Feemster repo owner

    There were some bugs, which I fixed.

    But also, this test code needs one small change. The AHK version of LoadPicture() takes a reference argument, which we are not supporting. So like our other functions which take reference arguments, we are instead returning a map which has an entry of the same name as the reference parameter. In this case, it’s “Handle”.

    So replace LoadPicture(A_LoopFileFullPath) with LoadPicture(A_LoopFileFullPath)[”Handle”]

    That should work with my latest commit.

  6. Log in to comment