It is currently Sat Dec 05, 2020 6:16 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: how to create a child window correctly
PostPosted: Mon Sep 07, 2020 4:37 pm 
Offline
User
User

Joined: Sat Jan 17, 2015 5:24 pm
Posts: 39
I would like to create several child windows and select which one is activated via buttons in the parent window. The following code does not work as I expected. I was hoping to create all the child windows and simply hide them until needed.
Code:
Enumeration
  #MainWindow
  #ChildWindow
  #MainButton1
  #MainButton2
  #ChildButton1
  #ChildButton2
EndEnumeration

; open main window and create one button
OpenWindow(#MainWindow, 0, 0, 1000, 580, "Main window", #PB_Window_SystemMenu | #PB_Window_TitleBar)
SetWindowColor(0, RGB(191,255,255))
 
ButtonGadget( #MainButton1, 200, 100, 50, 30, "MB1 " )
 
; open child window and create one button 
OpenWindow(#ChildWindow, 100, 100, 500, 400, "Child Window", #PB_Window_TitleBar, WindowID(#MainWindow))
ButtonGadget( #ChildButton1, 300, 200, 50, 30, "CB 1" )

; hide child window and create another button in main window
HideWindow(#ChildWindow, #True )
SetActiveWindow(#MainWindow)
ButtonGadget( #MainButton2, 300, 300, 50, 30, "MB 2" ) ;<<<< button appears in the child window

Repeat
  Event = WaitWindowEvent()

  Select Event
    Case #PB_Event_Gadget
      i = GetActiveGadget ()
      Select i
        Case #MainButton1
          SetActiveWindow( #ChildWindow )
          HideWindow(#ChildWindow, #False )       
        Case #ChildButton1
          HideWindow(#ChildWindow, #True )
      EndSelect
  EndSelect
 
Until Event = #PB_Event_CloseWindow ; Quit on any window close


From these results, it appears that I have to create and populate each child whenever it is to be activated. Is that the case :?:


Top
 Profile  
Reply with quote  
 Post subject: Re: how to create a child window correctly
PostPosted: Mon Sep 07, 2020 4:58 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3739
Hi
Try MDIGadget() it may help

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: how to create a child window correctly
PostPosted: Mon Sep 07, 2020 5:30 pm 
Offline
Always Here
Always Here

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 5076
Location: Germany
You have to re-use the GadgetList.

Also your GetActiveGadget() is wrong.

Code:
Enumeration
  #MainWindow
  #ChildWindow
  #MainButton1
  #MainButton2
  #ChildButton1
  #ChildButton2
EndEnumeration

; open main window and create one button
OpenWindow(#MainWindow, 0, 0, 1000, 580, "Main window", #PB_Window_SystemMenu | #PB_Window_TitleBar)
SetWindowColor(0, RGB(191,255,255))
ButtonGadget( #MainButton1, 200, 100, 50, 30, "MB1 " )

; open child window and create one button
OpenWindow(#ChildWindow, 100, 100, 500, 400, "Child Window", #PB_Window_TitleBar, WindowID(#MainWindow))
ButtonGadget( #ChildButton1, 300, 200, 50, 30, "CB 1" )

; hide child window and create another button in main window
HideWindow(#ChildWindow, #True )
SetActiveWindow(#MainWindow)

UseGadgetList(WindowID(#MainWindow))
ButtonGadget(#MainButton2, 300, 300, 50, 30, "MB 2" ) ;<<<< button appears in the child window

Repeat
  Event = WaitWindowEvent()
 
  Select Event
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #MainButton1
          SetActiveWindow( #ChildWindow )
          HideWindow(#ChildWindow, #False )       
        Case #ChildButton1
          HideWindow(#ChildWindow, #True )
      EndSelect
  EndSelect
 
Until Event = #PB_Event_CloseWindow ; Quit on any window close


Btw. Up to now no answer if your RS232 stuff works now or not.


Top
 Profile  
Reply with quote  
 Post subject: Re: how to create a child window correctly
PostPosted: Thu Sep 24, 2020 12:54 am 
Offline
User
User

Joined: Sat Jan 17, 2015 5:24 pm
Posts: 39
Thanks for all your help. I have finally decided to simply stay with regular windows and make sure I have all the gadgets for the main window defined before I activate another window.


Top
 Profile  
Reply with quote  
 Post subject: Re: how to create a child window correctly
PostPosted: Thu Sep 24, 2020 9:18 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 649
Location: Germany, Saarbrücken
If you are working with multiple windows you should also use EventWindow() to determine in which window the event occured. This is helpful if you want to see which window has moved, got resized or on which one the close button was clicked.

_________________
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.


Top
 Profile  
Reply with quote  
 Post subject: Re: how to create a child window correctly
PostPosted: Thu Sep 24, 2020 3:20 pm 
Offline
User
User

Joined: Sat Jan 17, 2015 5:24 pm
Posts: 39
Hi NicTheQuick, Thanks for the "heads up."


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 62 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye