Restored from previous forum. Originally posted by Franco.
Hi Folks,
don't know why, but when I draw an Image on a window and after that,
comes a delay or timer command the image appears after the delay time.
Basic is a procedural language so (I thought...) the delay or timer command has to start AFTER the image is drawn!
Do we need a ShowImage() command... or is this a bug?
Have a nice day...
Franco
Edited by - franco on 11 October 2001 22:39:15
Delay [Sleep_] and Timer problem
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
Strange, and similar to a VB problem. In VB, you'd have to issue an "Image.Refresh" or "DoEvents" command BEFORE the delay started, or the same thing would happen as happened to you. Thus, my guess is that you'd need some sort of "yield to the CPU" command in PB to fix it.
UPDATE: Although this may not work, try using "sleep_(0)" before your delay command, to see if it helps, because I just saw this in the Win32 API: "A thread can relinquish the remainder of its time slice by calling this function with a sleep time of zero milliseconds."
Let me know if it was successful...
Edited by - PB on 12 October 2001 12:16:44
Strange, and similar to a VB problem. In VB, you'd have to issue an "Image.Refresh" or "DoEvents" command BEFORE the delay started, or the same thing would happen as happened to you. Thus, my guess is that you'd need some sort of "yield to the CPU" command in PB to fix it.
UPDATE: Although this may not work, try using "sleep_(0)" before your delay command, to see if it helps, because I just saw this in the Win32 API: "A thread can relinquish the remainder of its time slice by calling this function with a sleep time of zero milliseconds."
Let me know if it was successful...
Edited by - PB on 12 October 2001 12:16:44
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Franco.
Thanks PB but sleep_(0) didn't work.
Following code is my test code so you can see what's going on...
; (c) 2001 - Franco
; Create Intro Window
InitGadget(0)
LoadImage(0, "Data\PureBasic.bmp"); you have to set your path\file.bmp
If OpenWindow(0, 100, 120, 250, 200, #WS_POPUP|#WS_THICKFRAME, "Test Intro")
If CreateGadgetList(WindowID())
ImageGadget(0, 40, 65, 0, 0, UseImage(0))
EndIf
EndIf
;not working ----------------- not working
; if one of the following functions is added
; the image appears after the waiting time is over
;sleep_(0) ; tryed this
Delay(2000) ; tryed this
;Timer1.l=settimer_(windowid(),0,2000,0) ; tryed this with killtimer
;KillTimer_(windowid(),Timer1)
; normally the window #0 is closed before window 1 comes (after a delay time...)
;CloseWindow(0)
;not working ----------------- not working
; put both windows on different locations for testing
If OpenWindow(1, 300, 420, 320, 240, #PB_Window_SystemMenu, "Test Intro")
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_EventCloseWindow
EndIf
End
You can see that the image on window 0 appears after window 1 comes.
Is this a bug or a feature?
Have a nice day...
Franco
Thanks PB but sleep_(0) didn't work.
Following code is my test code so you can see what's going on...
; (c) 2001 - Franco
; Create Intro Window
InitGadget(0)
LoadImage(0, "Data\PureBasic.bmp"); you have to set your path\file.bmp
If OpenWindow(0, 100, 120, 250, 200, #WS_POPUP|#WS_THICKFRAME, "Test Intro")
If CreateGadgetList(WindowID())
ImageGadget(0, 40, 65, 0, 0, UseImage(0))
EndIf
EndIf
;not working ----------------- not working
; if one of the following functions is added
; the image appears after the waiting time is over
;sleep_(0) ; tryed this
Delay(2000) ; tryed this
;Timer1.l=settimer_(windowid(),0,2000,0) ; tryed this with killtimer
;KillTimer_(windowid(),Timer1)
; normally the window #0 is closed before window 1 comes (after a delay time...)
;CloseWindow(0)
;not working ----------------- not working
; put both windows on different locations for testing
If OpenWindow(1, 300, 420, 320, 240, #PB_Window_SystemMenu, "Test Intro")
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_EventCloseWindow
EndIf
End
You can see that the image on window 0 appears after window 1 comes.
Is this a bug or a feature?
Have a nice day...
Franco
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
I don't get it... on my PC, your example shows the PB graphic on window 0, then pauses for 2 seconds, then shows window 1. Are you saying this doesn't happen for you? You said 'the image on window 0 appears after window 1 comes', but on my PC it appears before the delay and window 1 opening. I'm using the latest version of PB and Windows 2000, if that helps...?
Edited by - PB on 18 October 2001 04:38:57
I don't get it... on my PC, your example shows the PB graphic on window 0, then pauses for 2 seconds, then shows window 1. Are you saying this doesn't happen for you? You said 'the image on window 0 appears after window 1 comes', but on my PC it appears before the delay and window 1 opening. I'm using the latest version of PB and Windows 2000, if that helps...?
Edited by - PB on 18 October 2001 04:38:57
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Mr.Skunk.
Hi Franco
This problem happens to me with the latest PB and win98
To solve it, simply add 2 windowevent() just before your delay()
>Windowevent()
>Windowevent()
>Delay(2000)
Don't know why, perhaps PB Uses some windows messages to know when it has to draw a gadget on a window (the problem is the same with the other gadgets i tried (buttongadgets, stringgadgets...), or it is just a "feature" of win98, That's a good question...
Hope it helps...
Mr Skunk
Mr Skunk's PureBasic Web Page
http://www.skunknet.fr.st
Hi Franco
This problem happens to me with the latest PB and win98
To solve it, simply add 2 windowevent() just before your delay()
>Windowevent()
>Windowevent()
>Delay(2000)
Don't know why, perhaps PB Uses some windows messages to know when it has to draw a gadget on a window (the problem is the same with the other gadgets i tried (buttongadgets, stringgadgets...), or it is just a "feature" of win98, That's a good question...
Hope it helps...
Mr Skunk
Mr Skunk's PureBasic Web Page
http://www.skunknet.fr.st
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm