Page 1 of 1

BareBones - Skeleton

Posted: Sat Jul 12, 2003 6:37 am
by TronDoc
I've been searching this forum,the help file & user's sites; experimenting
with everything I've found remotely resembling what I'm after...
...to no avail. Apparently some of the older examples and
snippets I've come across no longer function due to
changes in PureBasic itself.

Problem: I'm trying to incorporate an "About" window similar to
PureBasic's in a program of mine. Looking at the ide, common
and about sources is helpful, but I keep confusing myself on
how to get it to work in my own app.

What goes wrong: I have the main app, I've "included" the about
source and my "about" menu item calls the about window and
displays it just fine.. ..BUT.. ..I can't figure out how to properly
handle events to allow the closing of the about window and
return to my main app. Either I end up closing everything
or I end up in an endless loop and have to quit from the debugger.

Help wanted: A skeleton program showing how a main app can
call another window, get it's events and return to the main app.
--OR--
Pseudo code pointing out the structure I should be following
to accomplish this.

My understanding (possibly incorrect) would be as follows:
--Pseudo code--

run main app
show main window
handle events()
end

proc about()
show about window
handle aboutevents()
end proc

the mess I've made of my attempts can be found here:
http://trondoc.ezwebtech.com/prgrmng/d3/about.zip

Thanks.

Joe

P.S. I am not asking anyone to write the program for me! :D
P.P.S. If you suspect you've posted code somewhere that
may no longer work because of PureBasic updates..
..find it and kill it! LOL :lol: I'm sure I'm guilty of this
also.... ....I know of no simple/quick way to accomplish it either.

Posted: Sat Jul 12, 2003 7:15 am
by Karbon
You're going to kick yourself when I tell you :-)

You're doing everything just fine except that you're passing the same window ID as your main window to openwindow when you call Open_Window_About() thus closing the main window..

Just change the #Window_About constant in about.pb to a different number (remember all windows need a unique identifier!)

Re: BareBones - Skeleton

Posted: Sat Jul 12, 2003 7:27 am
by ricardo

Code: Select all

Procedure AnotherWindow()
  If OpenWindow(1,100,150,250,200,#PB_Window_SystemMenu,"OtherWindow")
    CreateGadgetList(WindowID())
    ButtonGadget(11,100,100,50,25,"Test")
  EndIf
EndProcedure


If OpenWindow(0,0,0,450,200,#PB_Window_SystemMenu,"Test")
  CreateGadgetList(WindowID())
  ButtonGadget(1,150,100,150,25,"Open another window")
  Repeat
    EventID=WaitWindowEvent()
    
    Select EventID
      
    Case #PB_EventGadget
      Select EventGadgetID()
        Case 1
          AnotherWindow()
        Case 11;The gadget from the other window must have DIFFERENT ids
          MessageRequester("click","Button from 2nd window",0)
      EndSelect
    Case #PB_EventCloseWindow
      If EventWindowID()= 1 ;Here you detect if the window to close is your additional window
        CloseWindow(1)
        UseWindow(0)
      Else
        Quit = 1
      EndIf
  EndSelect
  
Until Quit = 1
EndIf
In resume there are 2 important things:

1.- Check which window receives the #PB_EventCloseWindow by using the EventWindowID() that let you know which one was.

2.- The Gadgets of you additional windows must have different number ids from the ones of the main window, then it could be handled in the same event loop.

Best Regards

Posted: Sat Jul 12, 2003 8:43 am
by TronDoc
:arrow: :oops: kicking self! :roll: