Help with using ButtonGadget
Posted: Thu Feb 17, 2011 8:45 pm
Hello! This is my first post. I come from Ye' Olde BASIC for the DOS days. I actually still used until a couple days ago. It's incompatibility with Windows has brought me to PureBasic.
I copied an example straight out of the help file for the ButtonGadget command:
; Shows possible flags of ButtonGadget in action...
If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 200, 20, "Standard Button")
ButtonGadget(1, 10, 40, 200, 20, "Left Button", #PB_Button_Left)
ButtonGadget(2, 10, 70, 200, 20, "Right Button", #PB_Button_Right)
ButtonGadget(3, 10,100, 200, 60, "Multiline Button (longer text gets automatically wrapped)", #PB_Button_MultiLine)
ButtonGadget(4, 10,170, 200, 20, "Toggle Button", #PB_Button_Toggle)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
It works as expected. Then I modified it by inserting some code after the window and buttons were created. It no longer worked. I simplified the program to result with:
; Shows possible flags of ButtonGadget in action...
If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 200, 20, "Standard Button")
ButtonGadget(1, 10, 40, 200, 20, "Left Button", #PB_Button_Left)
ButtonGadget(2, 10, 70, 200, 20, "Right Button", #PB_Button_Right)
ButtonGadget(3, 10,100, 200, 60, "Multiline Button (longer text gets automatically wrapped)", #PB_Button_MultiLine)
ButtonGadget(4, 10,170, 200, 20, "Toggle Button", #PB_Button_Toggle)
EndIf
; The delay is used in place of some code segments to do something else.
Delay(5000)
loophere:
If WaitWindowEvent() <> #PB_Event_CloseWindow
Goto loophere
EndIf
End
As the comment says..... I put my "Other" code where the Delay(5000) command is. The window opens, but the buttons do not display until the execution reaches the If WaitWindowEvent().......... At that point, the buttons display and are functional.
If I comment out the "Delay" (or my other code) the buttons work just fine.
What in the world is wrong??? I can't sit there and do a "If WaitWindowEvent().........." all the time or else my program wouldn't do a stinking thing except display buttons!
I copied an example straight out of the help file for the ButtonGadget command:
; Shows possible flags of ButtonGadget in action...
If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 200, 20, "Standard Button")
ButtonGadget(1, 10, 40, 200, 20, "Left Button", #PB_Button_Left)
ButtonGadget(2, 10, 70, 200, 20, "Right Button", #PB_Button_Right)
ButtonGadget(3, 10,100, 200, 60, "Multiline Button (longer text gets automatically wrapped)", #PB_Button_MultiLine)
ButtonGadget(4, 10,170, 200, 20, "Toggle Button", #PB_Button_Toggle)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
It works as expected. Then I modified it by inserting some code after the window and buttons were created. It no longer worked. I simplified the program to result with:
; Shows possible flags of ButtonGadget in action...
If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 200, 20, "Standard Button")
ButtonGadget(1, 10, 40, 200, 20, "Left Button", #PB_Button_Left)
ButtonGadget(2, 10, 70, 200, 20, "Right Button", #PB_Button_Right)
ButtonGadget(3, 10,100, 200, 60, "Multiline Button (longer text gets automatically wrapped)", #PB_Button_MultiLine)
ButtonGadget(4, 10,170, 200, 20, "Toggle Button", #PB_Button_Toggle)
EndIf
; The delay is used in place of some code segments to do something else.
Delay(5000)
loophere:
If WaitWindowEvent() <> #PB_Event_CloseWindow
Goto loophere
EndIf
End
As the comment says..... I put my "Other" code where the Delay(5000) command is. The window opens, but the buttons do not display until the execution reaches the If WaitWindowEvent().......... At that point, the buttons display and are functional.
If I comment out the "Delay" (or my other code) the buttons work just fine.
What in the world is wrong??? I can't sit there and do a "If WaitWindowEvent().........." all the time or else my program wouldn't do a stinking thing except display buttons!