Creating gadgets in a thread procedure
Posted: Wed Mar 29, 2006 9:59 am
Hi,
I have strange behaviour when I create image gadgets in a threaded procedure. Images are loaded and progressively shown on screen but after the end of the procedure they disappear ! Outside a thread it works but I need to use threads for this...
Try this code (compile with PB4.0 beta8):
I have strange behaviour when I create image gadgets in a threaded procedure. Images are loaded and progressively shown on screen but after the end of the procedure they disappear ! Outside a thread it works but I need to use threads for this...
Try this code (compile with PB4.0 beta8):
Code: Select all
EnableExplicit
Structure strImg
fimg.l
gimg.l
EndStructure
Global NewList Imgs.StrImg()
Global win, scr, thr
Procedure MyLoadImage(param)
Protected i
OpenGadgetList(param)
For i = 1 To 10
AddElement(Imgs())
Imgs()\fimg = LoadImage(#PB_Any,"D:\My Documents\My Pictures\screen_108.jpg") ;Change the path to a valid jpeg image of your own
ResizeImage(Imgs()\fimg, 60, 40)
Imgs()\gimg = ImageGadget(#PB_Any,0,(i-1)*40,60,40,ImageID(Imgs()\fimg))
Next
CloseGadgetList()
EndProcedure
UseJPEGImageDecoder()
win = OpenWindow(#PB_Any,100,100,150,450,"Test")
CreateGadgetList(WindowID(win))
scr = ScrollAreaGadget(#PB_Any,10,10,100,400,60,400,40)
thr = CreateThread(@MyLoadImage(), scr)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
End