Page 1 of 1
A better solution for While WindowEvent(): Wend
Posted: Mon Nov 21, 2005 4:08 am
by cbailey
I've been having problem after problem with my window freezing, and just acting odd. After scratching my head for way too long, I found out it was related to this statement: While WindowEvent(): Wend. I've moved the statement around, and finally got my program to behave. However, I have this suspicion that if I change anything, I'll have more problems. Looking around on the forum, I found this thread:
viewtopic.php?t=16449&highlight=while+windowevent+wend
Freak mentions enhancing the While Wend loop to check for events that should not be lost (That sounds like all events to me

Maybe I'm having a mental block, but I'm not figuring out how to do this. What I did do is this:
Start:
winevent=WindowEvent()
if winevent = 0 goto End
; Here I process the events
goto start
End:
It doesn't work for me. I still have to use a While WindowEvent(): Wend.
I've got to say that I know next to nothing about Windows programming. I came from PowerBasic, and I'm pretty good in DOS.
I feel that there's got to be a better solution. Any ideas?
Posted: Mon Nov 21, 2005 4:29 am
by Joakim Christiansen
I usually does it like this:
Code: Select all
Repeat
WindowEvent = WaitWindowEvent()
Select WindowEvent
Case #PB_Event_Menu
Select EventMenuID()
Case #New: ;do something
EndSelect
Case #PB_Event_Gadget
Select EventGadgetID()
Case #Button1: ;do something
EndSelect
EndSelect
Until WindowEvent = #PB_Event_CloseWindow
You should read and study the help file

Posted: Mon Nov 21, 2005 4:39 am
by cbailey
There's a Help file?
Seriously, I hate online docs. My PowerBasic manuals are well worn.
I'm having problems understanding the example. In my program, looking for events is part of a bigger loop, so the Repeat Until probably won't work for me. For the rest, I'm looking for the magic, the thing that keeps the window, and some routines, from freezing. Is it simply the Select Case?
Posted: Mon Nov 21, 2005 4:45 am
by Joakim Christiansen
Here is a working example:
Code: Select all
Enumeration ;Windows
#wnd_Main
EndEnumeration
Enumeration ;Menues
#Main_Menu
EndEnumeration
Enumeration ;Menu items
#Main_Menu_Hello
#Main_Menu_Exit
EndEnumeration
Enumeration ;Gadgets
#Main_Button1
#Main_Button2
EndEnumeration
OpenWindow(#wnd_Main,0,0,200,100,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered,"Test")
CreateMenu(#Main_Menu,WindowID())
MenuTitle("File")
MenuItem(#Main_Menu_Hello,"Hello World")
MenuItem(#Main_Menu_Exit,"Exit")
CreateGadgetList(WindowID())
ButtonGadget(#Main_Button1,10,10,50,20,"Button 1")
ButtonGadget(#Main_Button2,10,40,50,20,"Button 2")
Repeat
WindowEvent = WaitWindowEvent()
Select WindowEvent
Case #PB_Event_Menu
Select EventMenuID()
Case #Main_Menu_Hello: MessageRequester("Message","Hello World")
Case #Main_Menu_Exit: CloseWindow(#wnd_Main)
EndSelect
Case #PB_Event_Gadget
Select EventGadgetID()
Case #Main_Button1
MessageRequester("Message","You clicked button 1")
Case #Main_Button2
MessageRequester("Message","You clicked button 2")
EndSelect
EndSelect
Until WindowEvent = #PB_Event_CloseWindow
The help file is included with PureBasic.
Just press F1 to open it while you're running the PureBasic IDE.
Posted: Mon Nov 21, 2005 4:53 am
by Joakim Christiansen
This might be what you want?
Code: Select all
Repeat ;Main loop
WindowEvent = WindowEvent() ;This wont freeze the loop and wait for window events
Select WindowEvent
Case #PB_Event_Menu
Select EventMenuID()
Case #Main_Menu_Hello: MessageRequester("Message","Hello World")
Case #Main_Menu_Exit: CloseWindow(#wnd_Main)
EndSelect
Case #PB_Event_Gadget
Select EventGadgetID()
Case #Main_Button1
MessageRequester("Message","You clicked button 1")
Case #Main_Button2
MessageRequester("Message","You clicked button 2")
EndSelect
Default: Delay(2) ;If no window event; let other apps use some CPU too
EndSelect
;do other stuff here
Until WindowEvent = #PB_Event_CloseWindow
Posted: Mon Nov 21, 2005 5:01 am
by cbailey
I'm still confused
I double checked, and I do use a Repeat Until winevent=#PB_Event_CloseWindow. Basically, the rest of my code is similiar, except I'm using If-Then instead of Select Case.
Posted: Mon Nov 21, 2005 1:43 pm
by Kale

This is all in the Purebasic help file and all is explained clearly!!!
Posted: Mon Nov 21, 2005 9:27 pm
by blueznl
Posted: Mon Nov 21, 2005 9:38 pm
by Num3
The F1 Key is your friend

Posted: Mon Nov 21, 2005 9:56 pm
by cbailey
The help file is not quite linear, and searching for "My program doesn't work right" obviously didn't turn up any results. I believe I found the section you were referring to, but it's not understandable. Hence, I'm asking for help..
Posted: Mon Nov 21, 2005 10:00 pm
by blueznl
np
did you try the link i posted above?
Posted: Mon Nov 21, 2005 10:01 pm
by Kale
cbailey wrote:The help file is not quite linear, and searching for "My program doesn't work right" obviously didn't turn up any results.
Im not surprised! Try looking under 'WindowEvent()' and 'WaitWindowEvent()'! :roll:
Posted: Mon Nov 21, 2005 10:03 pm
by cbailey
BTW, thanks blueznl! Now if only I can get that in printable format

Posted: Mon Nov 21, 2005 10:05 pm
by Trond
cbailey wrote:BTW, thanks blueznl! Now if only I can get that in printable format

The big button which has a picture of a printer and is labelled "Print" doesn't work?
Posted: Mon Nov 21, 2005 10:26 pm
by cbailey
Instead of printing as webpages, with all the HTML and unneeded graphics, it would be nice for a DOC-Type format that's print freindly. But thanks so much for the immense help.