GuiControl changing previously posted picture Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zippes
Posts: 4
Joined: 29 Apr 2022, 15:07

GuiControl changing previously posted picture

Post by zippes » 23 May 2022, 14:55

Hi folks... need a fresh set of eyes.

I'm quite 'early' on the road to learning AHK but I'm trying to understand Gui a bit.

I've been playing with a GUI when the background picture is refreshed.
The images are in a folder off of Desktop called “countdown”

This code works when I do a “GuiControl” directly on the image. The Gui.Show pops the Gui with the picture in the background.
When the process gets to three pictures underneath, they replace the original picture one at a time.

Code: Select all

cntd:="countdown"
Gui,Add,Picture,w300 h-1 vMyPicture, %A_Desktop%\%cntd%\image-006.png
Gui,Add,Button,x60 w80 h30, Start
Gui,Show
GuiControl, , MyPicture, %A_Desktop%\%cntd%\image-007.png
sleep 2000
GuiControl, , MyPicture, %A_Desktop%\%cntd%\image-008.png
sleep 2000
GuiControl, , MyPicture, %A_Desktop%\%cntd%\image-009.png 
sleep 2000
return

ButtonStart:
MsgBox button
return
Now for the puzzle, I want to accomplish the same thing only with a “loop”
When I run it program the Gui.Show will pop the first picture, but subsequent calls to GuiControl will blank the original picture. Puzzling because the address which is passed to GuiControl points to the correct image.

Code: Select all

imaglist:= "image-006.png, image-007.png, image-008.png, image-009.png”
cntd:="countdown"
Gui,Add,Picture,w300 h-1 vMyPicture, %A_Desktop%\%cntd%\image-006.png
Gui,Add,Button,x60 w80 h30, Start
Gui,Show

loop, Parse, imaglist, `,
{
    adrr=  %A_Desktop%\%dirsub%\%A_LoopField%
    ;~ MsgBox %adrr%
    GuiControl, , MyPicture, %adrr% 
    sleep 2000
}
return

ButtonStart:
MsgBox button
return
[Mod edit: [code][/code] tags added.]

… any thought where I drifted into the weeds?

zippes
Posts: 4
Joined: 29 Apr 2022, 15:07

Re: GuiControl changing previously posted picture

Post by zippes » 23 May 2022, 15:07

Typo: that "adrr" line should read...

adrr= %A_Desktop%\%cntd%\%A_LoopField%

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: GuiControl changing previously posted picture  Topic is solved

Post by BoBo » 23 May 2022, 15:11

Code: Select all


imaglist:=["image-006.png","image-007.png","image-008.png","image-009.png”]
cntd:="countdown"
Gui,Add,Picture,w300 h-1 vMyPicture,% A_Desktop "\" cntd "\" imaglist[1]
Gui,Add,Button,x60 w80 h30 gButton, Start
Gui,Show
Return

Button:
loop % imaglist.Count()-1 {
   adrr :=  A_Desktop "\" cntd "\" imaglist[A_Index+1]
;  MsgBox %adrr%
   GuiControl,, MyPicture, % adrr
   Sleep 2000
   }
return
Not tested.

zippes
Posts: 4
Joined: 29 Apr 2022, 15:07

Re: GuiControl changing previously posted picture

Post by zippes » 23 May 2022, 15:16

Bobo... thanks for the quick reply.

I don't have a problem with the initial Gui post of the first picture, it's the subsequent posts driven by GuiControl that give me issues... but ONLY if I'm inside the loop.

Do you feel that changing the initial coding to:

Gui,Add,Picture,w300 h-1 vMyPicture,% A_Desktop "\" cntd "\" imaglist[1]

... would affect the subsequent GuiControl opertain?

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: GuiControl changing previously posted picture

Post by BoBo » 23 May 2022, 15:31

a) I've changed a few lines from AHK 'legacy'-style to 'expression'-style, the syntax style you should get used to perspectively. But that won't change the final outcome.
b) the first image is directly taken from the imaglist-array.
c) the following images are shown with pressing the Start-button, using a Loop that is selecting the image names from the imaglist-array.
d) the array has some benefits over a string, first of all you can directly access all items via its key/name (assoc. array) or position (simple array).

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: GuiControl changing previously posted picture

Post by Xtra » 23 May 2022, 17:20

Code: Select all

imaglist:= "image-006.png, image-007.png, image-008.png, image-009.png”
Should be:

Code: Select all

imaglist:= "image-006.png, image-007.png, image-008.png, image-009.png"
and then you have vars cntd vs dirsub is that a folder missmatch?

zippes
Posts: 4
Joined: 29 Apr 2022, 15:07

Re: GuiControl changing previously posted picture

Post by zippes » 23 May 2022, 18:36

Bobo,

Many thanks for the assistance. I was able to get the functionality that I was shooting for and now I have something 'working' that I can focus on to wrap my head around the syntax and preferred structure.

Be safe...

Post Reply

Return to “Ask for Help (v1)”