Select...Case question with Window Gadgets.

Just starting out? Need help? Post your questions and find answers here.
Maximus_Primal
User
User
Posts: 12
Joined: Sat Dec 18, 2004 7:01 pm
Location: England, UK
Contact:

Select...Case question with Window Gadgets.

Post by Maximus_Primal »

I have used PureVisionXP to export the code to a set of windows for my progam with an eventloop for the main window. This (and the examples provided) use the Select...Case set of commands which I am strugling with a little.

I have an "About" window which pops up okay from within the main loop. This then transfers to a seperate procedure to run a small loop so you have to it the close window gadget in the top right or a standard button on the middle of the window. The button gadget works fine, but I cannot get the close gadget on the window to work.

I assume it is something simple that I have done or missed. I looked at the code exported (which lets the main window close and program to exit) but this doesn't appear to work :(

Can someone take a look at the code (shown below) and tell me what I have missed please. It is annoying as the button gadget works perfectly....

Thanks

Max

Code: Select all

Procedure AboutWindow(x)
aboutquit=0
Repeat

EventID=WaitWindowEvent()
Select EventID

Case #PB_Event_Gadget
 Select EventGadgetID()
  Case #Gadget_AboutWindow_AboutClose
  aboutquit=1
 EndSelect
  
EventID=WaitWindowEvent()
 Select EventID
  Case #PB_Event_CloseWindow
   If EventWindowID()=#Window_AboutWindow
    aboutquit=1
   EndIf
 EndSelect
EndSelect

Until aboutquit=1

 CloseWindow(#Window_AboutWindow)
EndProcedure
The code used to call the window is this:
The "WIndow_AboutWIndow" was defined by PureVisionXP when it exported the window Code. "AboutWindow" is the procedure above.

Code: Select all

Case #MenuBar_MainWindow_About
  Window_AboutWindow()
  AboutWindow(1)
Real Power Comes From Sharing With Those Who Think They Have It All!
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4790
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

You've got it a bit backward:):)

Post by Fangbeast »

PureVision exports code for your windows (including the gadgets in those windows) into procedures and then a separate event handler if you let it.

Your program from purevision should look like this:

Code: Select all

procedure MyMainWindow()
  ; all my gadgets etc
  buttongadget(#OpenAbout, 1, 5, 50, 20, "Close")
endprocedure

procedure AboutWindow()
  ; all my gadgets
  buttongadget(#CloseAbout, 1, 5, 50, 20, "Close")
endprocedure

; Now my main event handler

if MyMainWindow

quit = 0

  repeat

    eventid = waitwindowevent

    if eventid = #PB_Event_CloseWindow
      select eventwindowid()
        case MyMainWindow
          quit = 1
      endselect
    endif

    if eventid = #PB_Event_Gadget
      select eventgadgetid()
        case #CloseAbout
          closewindow(#AboutWindow)
        case #OpenAbout
          AboutWindow()
      endselect
    endif

 until quit

endif

end

Last edited by Fangbeast on Mon Jul 18, 2005 2:39 pm, edited 1 time in total.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Max,

When you've got several windows open use EventWindowID() to find out which one raised an event.

I hope the following example helps.

Code: Select all

Enumeration ;Windows
  #MainWindow
  #AboutWindow
EndEnumeration

Enumeration ;Gadgets
  ;MainWindow
  #OpenAboutButton
  
  ;AboutWindow
  #CloseAboutButton
  
EndEnumeration

OpenWindow(#MainWindow, 0, 0, 100, 100, #PB_Window_ScreenCentered |#PB_Window_SystemMenu, "Main")
CreateGadgetList(WindowID(#MainWindow))
ButtonGadget(#OpenAboutButton, 10, 10, 80, 80, "About")

OpenWindow(#AboutWindow, 0, 0, 50, 50,#PB_Window_WindowCentered|#PB_Window_Invisible,"About", WindowID(#MainWindow))
CreateGadgetList(WindowID(#AboutWindow))
ButtonGadget(#CloseAboutButton, 10, 10, 30, 30, "OK")

CloseMainWindow = #False

Repeat
  event = WaitWindowEvent()
  Select EventWindowID()
    Case #MainWindow
      Select event
        Case #PB_Event_Gadget
          If EventGadgetID() = #OpenAboutButton
            HideWindow(#AboutWindow, #False)
          EndIf
        Case #PB_Event_CloseWindow
          CloseMainWindow = #True
 
      EndSelect
      
    Case #AboutWindow
      Select event
        Case #PB_Event_Gadget
          If EventGadgetID() = #CloseAboutButton
            HideWindow(#AboutWindow, #True)
          EndIf
      EndSelect
      
  EndSelect
  
Until CloseMainWindow = #True
Maximus_Primal
User
User
Posts: 12
Joined: Sat Dec 18, 2004 7:01 pm
Location: England, UK
Contact:

Post by Maximus_Primal »

Thanks to both of you for your help on this. I tried both of your suggestions to try and make sense of something and in the end got this:

Code: Select all


Procedure AboutWindow(x)
aboutquit=0
Repeat

event = WaitWindowEvent() 
  Select EventWindowID() 
    Case #Window_AboutWindow
     
      Select event 
        Case #PB_Event_Gadget 
          If EventGadgetID() = #Gadget_AboutWindow_AboutClose
            aboutquit=1
          EndIf 
        Case #PB_Event_CloseWindow 
          aboutquit=1
      EndSelect
           
  EndSelect 

Until aboutquit=1

 CloseWindow(#Window_AboutWindow)
EndProcedure
It works and does the job. I also had a "Really Exit" window with the same problem and with a slightly modified version of this I got that working as well.

THANK YOU BOTH AGAIN!!! :) It was annoying I could not see the answer to a simple problem.

Max
Real Power Comes From Sharing With Those Who Think They Have It All!
Post Reply