A better solution for While WindowEvent(): Wend

Just starting out? Need help? Post your questions and find answers here.
cbailey
User
User
Posts: 65
Joined: Sat Jun 04, 2005 4:05 am

A better solution for While WindowEvent(): Wend

Post 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?
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post 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 :wink:
I like logic, hence I dislike humans but love computers.
cbailey
User
User
Posts: 65
Joined: Sat Jun 04, 2005 4:05 am

Post 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?
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post 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.
I like logic, hence I dislike humans but love computers.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post 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
Last edited by Joakim Christiansen on Mon Nov 21, 2005 5:09 am, edited 1 time in total.
I like logic, hence I dislike humans but love computers.
cbailey
User
User
Posts: 65
Joined: Sat Jun 04, 2005 4:05 am

Post by cbailey »

I'm still confused :shock:

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.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Image
This is all in the Purebasic help file and all is explained clearly!!!
--Kale

Image
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

The F1 Key is your friend :wink:
cbailey
User
User
Posts: 65
Joined: Sat Jun 04, 2005 4:05 am

Post 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..
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

np

did you try the link i posted above?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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:
--Kale

Image
cbailey
User
User
Posts: 65
Joined: Sat Jun 04, 2005 4:05 am

Post by cbailey »

BTW, thanks blueznl! Now if only I can get that in printable format :)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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?
cbailey
User
User
Posts: 65
Joined: Sat Jun 04, 2005 4:05 am

Post 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.
Post Reply