Using bitmap handle with GuiControl

Get help with using AutoHotkey and its commands and hotkeys
rengg
Posts: 4
Joined: 27 Jan 2017, 22:17

Using bitmap handle with GuiControl

13 Nov 2017, 12:22

I tried running the example found at https://autohotkey.com/docs/commands/LoadPicture.htm and it works for me.

Code from above:

Code: Select all

Pics := []

Loop, Files, %A_WinDir%\Web\Wallpaper\*.jpg, R
{
    Pics.Push(LoadPicture(A_LoopFileFullPath))
}

Gui, Add, Pic, w600 h-1 vPic +Border, % "HBITMAP:*" Pics.1
Gui, Show
Loop 
{
    ; Switch pictures!
    GuiControl, , Pic, % "HBITMAP:*" Pics[Mod(A_Index, Pics.Length())+1]
    Sleep 3000
}
However I tried to implement something similar and it's not changing the picture the same way:

Code: Select all

	pics := []
	Loop, Files, pics\*.bmp,
	{
		Splitpath, A_LoopFileLongPath,,,,bmpName
		pics[bmpName] := LoadPicture(A_LoopFileFullPath)
	}
	
	defaultBmp := LoadPicture("default.bmp")
	Gui, Add, Picture, vPic x0 y0, HBITMAP:*%defaultBmp%
	Gui, Show
	
	for key, value in pics
		GuiControl, , Pic, % "HBITMAP:*" value
		Sleep 3000
It switches to only one pic (something to do with associative array? or am i using handles incorrectly?), and doesn't show any of the other pics.

If I do:

Code: Select all

	;no loop
	GuiControl, , Labels, % "HBITMAP:*" pics["nameOfBmp"]
then it changes to the correct picture.
just me
Posts: 5519
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Using bitmap handle with GuiControl

14 Nov 2017, 04:47

You might need block braces:

Code: Select all

for key, value in pics
{
	GuiControl, , Pic, % "HBITMAP:*" value
	Sleep 3000
}

Return to “Ask For Help”

Who is online

Users browsing this forum: Quadzilla and 29 guests