Opening Windowed Screen in Child Wipes Out Parent (Main)

Just starting out? Need help? Post your questions and find answers here.
hudsonjo
User
User
Posts: 43
Joined: Mon Aug 18, 2014 12:04 am

Opening Windowed Screen in Child Wipes Out Parent (Main)

Post by hudsonjo »

Hello PB Forum,

My game app is progressing well, but I've hit a snag when opening a sub-menu (a child window) for player sign-in. The procedure runs fine, until I have to open a small, windowed screen in the child window to facilitate Keyboard input. For reasons unknown, when this is done and upon opening the 'Sign In' sub-window, the Main Window (parent) is instantly wiped out and left orphaned. I suspect maybe I've left a detail or something undone...? Any ideas?

For clarity I've provided some working code below. ...Just a brief snippet of the process to demonstrate the problem.

Many thanks!

Code: Select all

Enumeration
#Window_Main
#Window_SignIn
#Text_Names
#Text_Pin
#Listview_User
#Listview_Pswd
#Button_Select2
#Button_Done2
#Button_Cancel2
EndEnumeration

#Arial_16 = 16                                           ;Font for Sign In Name.
Arial_16  = LoadFont(#Arial_16,"Arial",16,#PB_Font_Bold) ;Font for Sign In Name.
#TableGrn = $008000                                      ;Color for Gaming Table.
#TableYel = $03CFFF                                      ;Color for Table Lettering.

InitSprite() : InitKeyboard()       ;Prepare Programming Environment.

Procedure.s GetKeyBoard()
  Debug "LINE 197: Start GetKeyBoard()"
  Repeat
    FlipBuffers()
    Debug "LINE 200: GetKeyBoard() - Top of Loop w/ ChrBuffer$ = " + ChrBuffer$
    Event = WaitWindowEvent(10)                        ;Waits until a Click is detected from Windows.
    ExamineKeyboard()                                  ;Check Keyboard for Activity.
    If KeyboardReleased(#PB_Key_Back)                  ;Was a Backspace Key Released?
      ChrBuffer$ = Left(ChrBuffer$, Len(ChrBuffer$)-1) ;Back up 1 Chr from 'ChrBuffer$' - holds Chrs typed.
    Else                                               ;Not BS Key, so...
      NewChr$ = KeyboardInkey()                        ;Store new Chr from Keyboard.
      Debug "LINE 207: GetKeyBoard() - Before FindString w/ NewChr$ = " + NewChr$
      If FindString("-=+@#$_()|<>?1234567890 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", NewChr$) ; ;Validate the New Character.
        ChrBuffer$ + NewChr$                           ;Concat the new Char into the current buffer.
        Debug "LINE 210: GetKeyBoard() - After KbInKey() w/ ChrBuffer$ = " + ChrBuffer$
      EndIf
    EndIf
    Debug "LINE 212: GetKeyBoard() - Bottom of Loop w/ ChrBuffer$ = " + ChrBuffer$
    StartDrawing(ScreenOutput())
      DrawingMode(#PB_2DDrawing_Default)
      DrawingFont(FontID(#Arial_16))                   ;Set Font/Size.
      If Right(ChrBuffer$,1) = "_"                  ;For Blinking Cursor.
        RTrim(ChrBuffer$, "_")
        DrawText(5, 1, "Name <Enter>: " + ChrBuffer$ + " ", #White, #Blue)
      Else 
        DrawText(5, 1, "Name <Enter>: " + ChrBuffer$ + "_", #White, #Blue)
      EndIf
    StopDrawing()
  Until KeyboardPushed(#PB_Key_Return) Or KeyboardPushed(#PB_Key_PadEnter)    ;Event = #PB_Key_Return
  Debug "LINE 214: End GetKeyBoard() w/ ChrBuffer$ = " + ChrBuffer$
  ProcedureReturn ChrBuffer$
EndProcedure ;GetKeyBoard()

Procedure SignIn(User$,Pswd,Credits,Cost,Player, Date$, Time$)
  
;*** Set up 'NewLists' for the SignIn Menu ***
;*********************************************

  NewList User$()                         ;Define a New List of Player's Names.
  AddElement(User$())                   ;Add a name Slot to the List.
  User$() = "Add Player"                ;Store the "Add Player" choice in Slot 1.
;Read in Player Data File.
;#PLAYER_FILE = 1                                       ;Provide a "PB" Number for file.
;For Nam = 1 To EOF                                     ;It takes ?? reads to load in the Names.
;    PLAYERVAR(0)\USERNAME$ = ReadString(#PLAYER_FILE) ;Get name of a player from Data File.
;    AddElement(User$.s())                  ;Add a name Slot to the List.
;    User() = USERNAME$                     ;Store the UserName in Slot.
;  Next

;*** Initiate a 'Child' Window for the "Sign In" Menu ***
;********************************************************
OpenWindow(#Window_SignIn, 1050, 400, 320, 280, " SIGN-IN - PLAYER #" + Str(Player+1), #PB_Window_SystemMenu |
           #PB_Window_TitleBar, WindowID(#Window_MAIN))    ;This window is defined as child of #Window_Main.
OpenWindowedScreen(WindowID(#Window_SignIn),10,0,300,30)
  ClearScreen(#Blue)                        ;Blue.
  ;SetGadgetFont(#PB_Default, FontID(#Britannic_16))                    ; Set Britannic_16 as new Font.
  TextGadget(#Text_Names, 10, 32, 180, 30, "NAMES", #PB_Text_Border | #PB_Text_Center) ;Label for list of Player Names.
  TextGadget(#Text_Pin, 200, 32, 110, 30, "PIN", #PB_Text_Border | #PB_Text_Center) ;Label for list of Passwords.
  SetGadgetFont(#PB_Default, FontID(#Arial_16))                        ; Set Arial 16 as new Font.
  ListViewGadget(#Listview_User, 10, 65, 180, 170)                     ;Declare List Gadget for Player Names.
  ListViewGadget(#Listview_Pswd, 200, 65, 110, 170)                    ;Declare List Gadget for Passwords.
  ButtonGadget(#Button_Select2, 10, 240, 90, 30, "Select")             ;Declare Button Gadget to Select a Name.
  ButtonGadget(#Button_Done2, 110, 240, 80, 30, "Done")                ;Declare Button Gadget to be Done.
  ButtonGadget(#Button_Cancel2, 210, 240, 100, 30, "Cancel")           ;Declare Button Gadget to Cancel Sigb In.

;**** POPULATE "SIGN-IN" LIST ****
;*******************************
FirstElement(User$())                                    ;Inititialize to 1st slot in User Name List.
For Device = 1 To  ListSize(User$())
   AddGadgetItem(#Listview_User, -1, User$())            ;Add next User Name to the end of list.
   NextElement(User$())                                  ;Point to next User Name Item in Bet Type List.
Next
;*** Highlight List Item ***
SetGadgetState(#Listview_User,0)                 ;User may Click on a Listed User.
Repeat
  Repeat
    Event = WaitWindowEvent()                       ;Waits until a Click is detected from Windows.
    GadgetID = EventGadget()                        ;IDs which Gadget the User clicked on?
    If Event = #PB_Event_Gadget                     ;If a Gadget Event has Occurred...
      If GadgetID = #Button_Cancel2                 ;If "Cancel2" Button is clicked ('True'), then.
        Event = #Button_Cancel2
        CloseWindow(#Window_SignIn)                ;Close Sign In Window. 
;        ProcedureReturn 0
      ElseIf GadgetID = #Button_Done2                 ;If "Done" Button is clicked ('True'), then...
        CloseWindow(#Window_SignIn)                ;Close Sign In Window. 
;        ProcedureReturn 0
      ElseIf GadgetID = #Button_Select2               ;If "Select2" Button is clicked ('True'), then...
        Event = #Button_Select2                       ;  preset "Event" to Break out of Loop.
        NameSelected = GetGadgetState(#Listview_User) ;Get List Line# of selected UserName.
        PswdSelected = GetGadgetState(#Listview_Pswd) ;Get List Line# of selected Password.
      EndIf
    EndIf
  Until Event = #Button_Cancel2 Or Event = #Button_Select2
  Debug "LINE 275: After SignIn Selection Loop"
  
  Select NameSelected
    Case 0            ;0 = Add Player.
      FlipBuffers()
;      AddElement(User$())                   ;Add a name Slot to the List of User().
;      User$() = "Goofy"                     ;Store a test name in Slot 1.
      Debug "LINE 281: Before GetKeyBoard w/ Usr$ = " + Usr$      
      User$() = GetKeyBoard()                      ;Get new Name to Store in User List Slot 1.
      Debug "LINE 283: After GetKeyBoard w/ Usr$ = " + Usr$

      FirstElement(User$())                                    ;Inititialize to 1st slot in User Name List.
      For Device = 1 To  ListSize(User$())
        AddGadgetItem(#Listview_User, -1, User$())            ;Add next User Name to the end of list.
        NextElement(User$())                                  ;Point to next User Name Item in Bet Type List.
      Next
    Case 1            ;TBD.
      End
  EndSelect
Until Event = #PB_Event_CloseWindow               ;  set "Event" ready to close window & Exit loop.
CloseWindow(#Window_SignIn)                      ;Close SIGN IN Selection Window. 
EndProcedure ;SignIn

;*** Open Main Window of this DEMO. ***
;***********************************
OpenWindow(#Window_MAIN, 800, 100, 400, 400, " DEMO: MAIN WINDOW", #PB_Window_SystemMenu |
           #PB_Window_TitleBar)
OpenWindowedScreen(WindowID(#Window_MAIN),0,0,400, 400)
ClearScreen(#TableGrn)                        ;Green.
    StartDrawing(ScreenOutput())                       ;Sim Main Window w/ User Prompt.
      DrawingMode(#PB_2DDrawing_Default)
      DrawingFont(FontID(#Arial_16))                   ;Set Font/Size.
      DrawText(20, 20, "DEMO --- MAIN  SCREEN --- DEMO", #TableYel, #TableGrn)
      DrawText(100, 100, "<LEFT-CLICK>", #TableYel, #TableGrn)   ;To Prompt User.
    StopDrawing()
Repeat
  Event = WaitWindowEvent(20)              ;Wait for User Action - Mouse Click.
Until Event = #PB_Event_LeftClick Or Event = #PB_Event_CloseWindow

SignIn(User$,Pswd,Credits,Cost,Player, Date$, Time$)  ;Call Proc to Open 'Child' of #Window_Main.

Repeat
  Event = WaitWindowEvent(20)              ;Wait for User Action - Mouse Click.
Until Event = #PB_Event_LeftClick Or Event = #PB_Event_CloseWindow
CloseWindow(#Window_MAIN)                      ;Close MAIN Window. 

End
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Opening Windowed Screen in Child Wipes Out Parent (Main)

Post by Demivec »

I have not had the opportunity to test your code but i do have some observations after reading it.

You can only have one screen per program, windowed or otherwise. When you open a second windowed screen without closing the first one it causes your issues. I would think that you have basically two choices.

One is to create the sub screen in the child window as a part of the original windowed screen display. This means you are creating and handling the windows, their events and display including overlapping displays. It means you also are limited to only displaying child windows withi. The boundaries of the original window.

Another choice is to do the display of the child window by using a window with a canvas gadget in it instead of a windowed screen. The canvas gadget allows most things to be drawn as on a screen except Sprites. It also has its own methods for keyboard input.

You might use a window with an OpenGLgadget also. This would also allow sprites to be shown. I'm not sure if this would also count as a second screen though.
hudsonjo
User
User
Posts: 43
Joined: Mon Aug 18, 2014 12:04 am

Re: Opening Windowed Screen in Child Wipes Out Parent (Main)

Post by hudsonjo »

Hi Demivec,

Thank you for your ideas. If what you say is true, that's very disappointing. So I will look carefully into your suggestions. I want to re-emphasize that it is only the attempt to put the "OpenWindowedScreen" command inside the child (Sign In) window that causes problems. If I comment it out, my problems go away... except then I can't get to the Keyboard. It's puzzling, but it would appear that I can open multiple child windows if I didn't need the "screen".

Much appreciated!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Opening Windowed Screen in Child Wipes Out Parent (Main)

Post by netmaestro »

I was going to clean it up and get it working but it's late here now and it's in such a mess it's going to take some time and thought to organize it all. A couple of points to ponder:

1. There is no need for a windowed screen on your signin window.
2. Your whole program should not have more than one event loop. I count four in yours. Think your logic through and try to reduce it to a single event loop. A single event loop can handle multiple windows, just use EventWindow() to distinguish between them. If you can't manage it, I'll probably have some time tomorrow to spend on it. Or maybe someone else will take an interest.
BERESHEIT
hudsonjo
User
User
Posts: 43
Joined: Mon Aug 18, 2014 12:04 am

Re: Opening Windowed Screen in Child Wipes Out Parent (Main)

Post by hudsonjo »

netMaestro,

Thanks for your reply. I feel reassured to have your interest. My main window already uses the OpenWindowedScreen command. I did re-review the requirements in the PB manual for the OpenWindowedScreen command and noted that it does in fact state that only one windowed screen can be opened at one time. But no further details.

I only need the Windowed Screen for access to the KB input. (I would like to be able to type names & passwords into the "Sign In" menu list). Too bad there's no KeyboardIn Gadget!

Yes, I agree that there are more loops than would be necessary in the "real" program, but this is just to facilitate a "quick and dirty" demo routine to show the basic 'screen' problem for this forum. Not sure now what the minimum would be though.

If you have time, I would absolutely be delighted to see your recommendations.

Much appreciated!
User avatar
C87
Enthusiast
Enthusiast
Posts: 176
Joined: Mon Jul 17, 2017 7:22 am
Location: Cotswolds England

Re: Opening Windowed Screen in Child Wipes Out Parent (Main)

Post by C87 »

@hudsonjo
I have run your code but I haven't looked at amending it at all. Having said that, maybe this example may help you a little.

It is a modal screen set of four screens. From the opening screen you can open three other screens. Once a child screen is open,
you cannot access its parent screen. You cannot close a parent if a child screen is open.
You will not need three guesses to see that it is not a finished product. I developed it for a modal screen set from an example by SROD
and MKSOFT. Initially I had major problems with Gadget numbers being deleted and recreated and MKSOFT's suggestions fixed that.

Personally, I prefer a Modal screen set because it means I remain in control. All of my work is in database applications so I cannot
have users jumping all over the place in a way that isn't controlled. As I have never attempted a game application, so have no idea if
this example will help for your development.

It is only an example that I used for testing. I have spent far longer than I envisaged in creating database applications in PureBasic.
After longer than I care to remember, I'm getting there. But I do keep slipping back into MS Access for a new development as the RAD
is so much quicker. I find the Form Designer in PureBasic difficult/unusable due to there not being any Events or other RAD features.
By the time I've done I'll probably have nearly created a program writer to automate the job in PureBasic.

There are five programs in the set: STD001.pb ; STD003Enumeration.pbi ; STD100.pbi ; STD110.pbi ; STD120.pbi

Code: Select all

;
; STD001.pb  
; 
;╔════════════════════════════════════════════════════════════════════════════════════╗
;║ Main and sub modal windows. Prelim screen set suggestions                          ║                              
;║ The Procedures in each have their own eventloops For simplicity.                   ║
;║ I find it easier To keep a track of things this way.  I tend to use modal screens  ║
;║ in order to control the way the user accesses data and to prevent a parent screen  ║
;║ from being closed whilst leaving an orphaned child screen open. I could also hide  ║
;║ a parent screen when a child is opened but I don't bother doing so                 ║
;║ Modal screen developed from SROD  2004 modified Dec21                              ║
;║ The enumeration following suggestions from MKSOFT                                  ║
;║ Object is to show a modal screen-set example by C87  (tidied up a little June22)   ║
;║ No OnError code, all very basic (excuse the pun) created to test modal operation   ║
;║ ───────────────────────────────────────────────────────────────────────────────────║
;║ See {{ Opening Windowed Screen in Child Wipes Out Parent (Main)                    ║
;║           https://www.purebasic.fr/english/viewtopic.php?t=79239 }}                ║
;╚════════════════════════════════════════════════════════════════════════════════════╝
; Enumerate Order : Windows, Menus, MenuItems, Gadgets, Toolbars, StatusBars, Fonts, Images
; NOTE! I may refer to a Screen or a Window....which are the same!!
;
EnableExplicit
UseSQLiteDatabase()
UsePNGImageDecoder()  

;XIncludeFile "ADS009.pbi"    ; data functions
;XIncludeFile "ADS006.pbi     ; globals & button images

XIncludeFile "STD003Enumeration.pbi"
; XIncludeFile "STD006Global.pbi"   ; not included here
XIncludeFile "STD120.pbi"
XIncludeFile "STD110.pbi"   ;  
XIncludeFile "STD100.pbi"
;
UseModule InitEnumeration  ;Common ex MKSOFT
;
Enumeration Windows
  #MainWindow
  #SecondWindow
EndEnumeration

Enumeration Gadgets
  #Button1
  #Button2
  #Button3
  #Button4
  #Button_X2
  #Button_X1
EndEnumeration
;
; ------------------------------------------------------------------------------------------
; Start of opening screen (usually with a menu and or buttons to open other system screens )
;
Global.i EventID 

Define btnEXIT_1.i
btnEXIT_1 = 0
; 
OpenWindow(#MainWindow,0,0,600,600,"FIRST WINDOW", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget) 
;
;Add a couple of buttons.
ButtonGadget(#Button1, 320, 116, 125,30,"Get 2nd Window")
ButtonGadget(#Button2, 320, 156, 125,30,"Open 3rd Window")
ButtonGadget(#Button_x1, 490, 490, 50,50, "EXIT1")
 TextGadget(#PB_Any, 10, 350, 250,80,"Initial Opening screen. Giving access to application with Buttons or Menus. Here we can open screen1 and also screen4 (which is also opened from screen2)")
 
;opening screen event loop.
  Repeat
    EventID=WaitWindowEvent()
    Select eventid 
      Case #PB_Event_Gadget
        Select EventGadget()   ; was ID
          Case #Button1; Bring up 2nd window.
            Open100::DoOpen100() ; SecondWindow()
          Case #Button2; Hide first window and bring up 2nd window.
            ;//HideWindow(#MainWindow,1)
            Open110::DoOpen110() ;//SecondWindow()
            ;//HideWindow(#MainWindow,0)
          Case #Button_X1
            ;CloseWindow(#MainWindow)
            btnEXIT_1 = 1
        EndSelect
    EndSelect 
  Until EventID=#PB_Event_CloseWindow Or btnEXIT_1 =1
; 
; ╔═══════════════════════════════════════════════╗
; ║ ██████████   PROGRAM STD001 END    ██████████ ║
; ╚═══════════════════════════════════════════════╝ 
;
  
  

Code: Select all

; STD003Enumeration.pbi                                                                          
; ╔════════════════════════════════════════════════════════════╗
; ║   PROGRAM STD003  Xincluded 001                            ║
; ║   Based on Suggestions by MKSOFT                           ║
; ║ 30thNov21    PureBasicTest Errors losing gadgets           ║
; ╚════════════════════════════════════════════════════════════╝ 
;
; Enumerate Order : Windows, Menus, MenuItems, Gadgets, Toolbars, StatusBars, Fonts, Images, DBFile, DBTables
;
DeclareModule InitEnumeration ;Common
  ;
  Enumeration Windows ;0
  EndEnumeration
  
  Enumeration Menus; 200
  EndEnumeration
  
  Enumeration MenuItems 0
  EndEnumeration
  
  Enumeration Gadgets ;400
  EndEnumeration
  
  Enumeration Toolbars 0
  EndEnumeration
  
  Enumeration Statusbars 0
  ;  ; *******************Needed?? Maybe just use #PB_Any
  EndEnumeration
  
  Enumeration Fonts ;600
  EndEnumeration
  
  Enumeration Images ;800
  EndEnumeration
  
  Enumeration Events ;1000
  EndEnumeration
  
  Enumeration DBFILE ;1200
  EndEnumeration
  
  Enumeration DBTABLES
  EndEnumeration
  
EndDeclareModule

Module InitEnumeration
  ;
EndModule
;
; ╔═══════════════════════════════════════════════╗
; ║ ██████████   PROGRAM 003Enum END   ██████████ ║
; ╚═══════════════════════════════════════════════╝ 
;

Code: Select all

; STD100.pbi
; ╔════════════════════════════════════════════════════════════╗
; ║   PROGRAM STD100       SubForm to STD110                   ║
; ║ 30thNov21    PureBasicTest Errors losing gadgets now fixed ║
; ║ STD001, STD003, STD006, STD110, STD120                     ║
; ╚════════════════════════════════════════════════════════════╝ 
;
DeclareModule Open100
  ;Declare FnBtn1()
  ;Declare FnBtn2()
  ;Declare FnBtn3()
  ;Declare FnExitWin1()
  Declare DoOpen100()
  
EndDeclareModule ; 

Module Open100
  
 EnableExplicit
UseSQLiteDatabase()
UsePNGImageDecoder()  

;
UseModule InitEnumeration  ;Common ex MKSoft
;                          ;


Enumeration Windows
  #MainWindow
  #SecondWindow
EndEnumeration

Enumeration Gadgets
  ;#Button1
  ;#Button2
  #Button3
  ;#Button4
  #Button_X2
  ;#Button_X1
EndEnumeration

Procedure DoOpen100() ;SecondWindow()
 Protected.i EventID2, btnEXIT
  btnEXIT = 0 
  ;The following OpenWindow() command uses the parentID paramater (see help file) which, together
  ;with the corresponding event loop, forces this to be a Modal form.
  ;
  OpenWindow(#SecondWindow,175,0,639,243,"Second Window",#PB_Window_SystemMenu|#PB_Window_TitleBar|#PB_Window_MinimizeGadget |#PB_Window_ScreenCentered) ;, WindowID(#MainWindow))
  ButtonGadget(#Button3,320,106,125, 30, "SCREEN-3")
  ButtonGadget(#Button_X2, 400,180, 60,60,"EXIT 2")
  Repeat
    EventID2=WaitWindowEvent()
    Select EventGadget()      
      Case  #button3
        ;MessageRequester("START 3","Should open 3rd",0)
        Open110::DoOpen110()  ; open in AT2110
        ;DoOpen110()
        ;MessageRequester("END 3rd", "Clicked 3 ended return orig Wins should be closed",0)
      Case #Button_X2
        ;MessageRequester("EXIT","Exit Clicked >"+Str(btnEXIT),0)
        btnEXIT =1
        ;CloseWindow(#SecondWindow)
    EndSelect
  Until btnEXIT = 1 ; EventID2= #PB_Event_CloseWindow And EventWindow() = #SecondWindow;Or btnEXIT = 1  ; Make sure the correct window is being closed!
  If btnEXIT = 1
    CloseWindow(#SecondWindow)
    btnEXIT =0
  EndIf
  ;
EndProcedure  ; DoOpen100()  ;second
;
EndModule ; Open100
;
;
; ╔═══════════════════════════════════════════════╗
; ║ ██████████   PROGRAM STD100 END    ██████████ ║
; ╚═══════════════════════════════════════════════╝ 
 

Code: Select all

;  STD110.pbi
; ╔════════════════════════════════════════════════════════════╗
; ║   PROGRAM STD110  Opened from Menu PBT110                  ║
; ║ 30thNov21    PureBasicTest Errors losing gadgets           ║
; ║ PBT001, PBT002, PBT110, PBR120                             ║
; ╚════════════════════════════════════════════════════════════╝ 
; Enumerate Order : Windows, Menus, MenuItems, Gadgets, Toolbars, StatusBars, Fonts, Images
;
; UseModule MasterEnum
DeclareModule Open110
  Declare FnBtn1()
  Declare FnBtn2()
  Declare FnBtn3()
  Declare FnExitWin1()
  Declare DoOpen110()
  
EndDeclareModule ; DoScreen1
                 ;
 ;    BtnAdd()  ; not in use
 ;    BtnEdit()
 ;    BtnSave()
 ;    BtnCancel()
 ;    BtnDele()
 ;    BtnExit()
;
Module Open110
   UseModule InitEnumeration ; in 995
  ;
  ;
  ;
    Global.i GdgtList, EventID110, SecondWin
  Enumeration Windows 
    #Win_110
    ;#Button_X
    ;
  EndEnumeration
  
  Enumeration Gadgets   
    #Button_1     
    #BUTTON_2
    #BUTTON_3
    #BUTTON_X
 
    #TEXT_Show
    #TEXT_Show1
    #TestScrVar
    #AnotherVar1
    #AnotherVar2
  EndEnumeration
  ;
  ;
  Procedure FnBtn1()      ; Some of these will work and maybe some won't in this example....amend as you wish
    ;GdgtList = WindowID(#Win_110) ;GadgetID(#Win_110)
    Debug #Win_110
    Debug #Button_1
    Debug #TEXT_Show
   ; TextGadget(Str(#TEXT_Show), 100,10,70,25,"Message1") 
  EndProcedure
  ;
  Procedure FnBtn2()
    ;MessageRequester( "4th Screen","Not in use 22ndDec",0)
    Open120::DoOpen120()    ; In PBT120.pbi
    ;DoOpen120()
  EndProcedure
  ; 
  Procedure FnBtn3()
    ;GdgtList = WindowID(#Win_110) ;GadgetID(#Win_110)
    Debug #TEXT_Show1
    Debug #Win_110
    TextGadget(#TEXT_Show1, 100,10,70,25,"        ") 
  EndProcedure
  ;
  Procedure FnExitWin1()
  ;  
  ;  CloseWindow(#Win_110) 
  ;  ;
  EndProcedure   
  ;
 
 ;Debug #WIN_110
   ;
  Procedure DoOpen110()
    ;
    
    ;
    Define btnEXIT_110 : btnEXit_110 = 0
    ;
    OpenWindow(#Win_110, 0, 0, 500, 500, "Test Modal Windows Operation Screen Nº 3  *** STD110  ***", #PB_Window_ScreenCentered|#PB_Window_SystemMenu) 
    StickyWindow(#Win_110, #True)
      
    StringGadget(#TestScrVar,20,300,80,25,"")                   : TextGadget(#PB_Any, 300, 300, 50,20,Str(#TestScrVar))
      
    ButtonGadget(#BUTTON_1, 10, 10, 50, 50, "Btn1")             : TextGadget(#PB_Any, 300,  10, 50,20, Str(#Button_1))
    ButtonGadget(#BUTTON_2, 10, 90, 150, 50, "Open Subscreen 4"): TextGadget(#PB_Any, 300,  90, 50,20, Str(#Button_2))
    ButtonGadget(#BUTTON_3, 10,170, 50, 50, "Btn3")             : TextGadget(#PB_Any, 300, 170, 50,20, Str(#Button_3))
    ;
    ButtonGadget(#BUTTON_X,420,420, 60, 60, "Exit 3")             : TextGadget(#PB_Any, 400, 440, 50,20,Str(#Button_X))
    TextGadget(#PB_Any, 10, 480, 50,20,"Nº"+Str(#WIN_110))
    ;
    BindEvent(#PB_Event_CloseWindow, @FnExitWin1())
    ;
    BindGadgetEvent(#BUTTON_1, @FnBtn1())
    BindGadgetEvent(#BUTTON_2, @FnBtn2())
    BindGadgetEvent(#Button_3, @FnBtn3())
    ;   BindGadgetEvent(#Button_X, @FnExitWin1())
      ; 
    TextGadget(#PB_Any, 10, 350, 250,90,"Out of interest the gadget numbers are shown to the right to test they remain constant")
    TextGadget(#PB_Any, 100, 50, 50,20,Str(#TEXT_Show))
    TextGadget(#PB_Any, 150, 50, 50,20,Str(#TEXT_Show1))
    ;TextGadget(#PB_Any, 100, 170, 50,20,Str(#TEXT_Show))
    ;TextGadget(#PB_Any, 150, 170, 50,20,Str(#TEXT_Show1))
    ;
    ;..................................................
  ;Main event loop. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Repeat
    EventID110=WaitWindowEvent()
    Select eventid110 
      Case #PB_Event_Gadget
        Select EventGadget()   ; was ID
          Case #Button_1; Bring up 2nd window.
            ;SecondWindow()
          Case #Button_2; Hide first window and bring up 2nd window.
            ;HideWindow(#MainWindow,1)
            Open120::DoOpen120()  ;3rd Window() SEE FnBtn2()
            ;HideWindow(#MainWindow,0)
          Case #BUTTON_X
            ;CloseWindow(#Win_110)
            btnEXIT_110 = 1
        EndSelect
    EndSelect
  Until btnEXIT_110 = 1  ;EventID110=#PB_Event_CloseWindow ;'%%%%%%%%%%%%%
  If btnEXIT_110 = 1
    CloseWindow(#Win_110)
    btnEXIT_110 = 0
  EndIf
  
  EndProcedure ; DoOpen110()
  ; 
EndModule  ; Open110
;
; ╔═══════════════════════════════════════════════╗
; ║ ██████████   PROGRAM STD110 END    ██████████ ║
; ╚═══════════════════════════════════════════════╝ 

Code: Select all

;  STD120.pbi
; ╔════════════════════════════════════════════════════════════╗
; ║   PROGRAM STD120       SubForm to STD110                   ║
; ║ 30thNov21    PureBasicTest Errors losing gadgets fixed     ║
; ║ STD001, STD003, STD006, STD110, STD120                     ║
; ╚════════════════════════════════════════════════════════════╝ 
;
;
Global.i GdgtList, EventID120

DeclareModule Open120
  Declare FnBtn1()
  Declare FnBtn2()
  Declare FnBtn3()
  Declare FnExitWin1()
  Declare DoOpen120()
EndDeclareModule ; DoScreen1


Module Open120
  ;
  UseModule InitEnumeration  ; in 995
  
 Enumeration Windows          
    #Win120
    ;#BUTTON_X3
    
  EndEnumeration
  
  Enumeration  Gadgets      ; these may or may not be in use in this example...amend as you wish
    ;#Win120
    #BUTTON_1
    #BUTTON_2
    #BUTTON_3
    #BUTTON_X
   ;Win_120
  ;EndEnumeration
  ;
  ;Enumeration Gadgets
   #TEXT_Show3
   #TEXT_Show31
    #TestScrVar3
  EndEnumeration
  ;
  Procedure FnBtn1()
  Debug #TEXT_Show3
  Debug #TEXT_Show31
  Debug "------X13"
    TextGadget(#TEXT_Show3, 100,10,70,25,"Message1") 
  EndProcedure
  ;
  Procedure FnBtn2()
    ;
    ;
  EndProcedure
  ; 
  Procedure FnBtn3()
    
    Debug #TEXT_Show3
    Debug #TEXT_Show31
    Debug "=======X33"
    TextGadget(#TEXT_Show31, 100,10,70,25,"   **    ") 
  EndProcedure
  ;
  Procedure FnExitWin1()
    
   ; CloseWindow(#Win120) 
    ;
    
  EndProcedure    
 
  ;
   ;Debug #Win120
  ;
  Procedure DoOpen120()
    ;
  
    ;
    Protected.s mStr3$, mStr31$
    Protected.i btnEXIT_120 : btnEXIT_120 = 0
  mStr3$ = "MESSAGE"
  mStr31$ = "*******"
  ;
  OpenWindow(#Win120, 100, 100, 500, 500, "Test Modal Window Operation Screen Nº 4 ***  STD120   ***", #PB_Window_SystemMenu) 
  StickyWindow(#Win120,#True)     ; Does seem  to stop 110 from closing and leaving this open 
  ;
  StringGadget(#TestScrVar3,20,300,80,25,"")        : TextGadget(#PB_Any, 300, 300, 50,20, Str(#TestScrVar3))
     
  ButtonGadget(#BUTTON_1, 10, 10, 50, 50, "Btn1")  : TextGadget(#PB_Any, 300,  10, 50,20, Str(#Button_1)+"*")
  ButtonGadget(#BUTTON_2, 10, 90, 50, 50, "Btn2")  : TextGadget(#PB_Any, 300,  90, 50,20, Str(#Button_2))
  ButtonGadget(#BUTTON_3, 10,170, 50, 50, "Btn3")  : TextGadget(#PB_Any, 300, 170, 50,20, Str(#Button_3))
  ButtonGadget(#BUTTON_X,420,420, 60, 60, "Exit 4")  : TextGadget(#PB_Any, 400, 440, 50,20, Str(#BUTTON_X))
      
  TextGadget(#PB_Any, 10, 480, 50,20,"WinNº " + Str(#Win120))
  ;   
  BindGadgetEvent(#BUTTON_1, @FnBtn1())
  BindGadgetEvent(#BUTTON_2, @FnBtn2())
  BindGadgetEvent(#Button_3, @FnBtn3())
  BindGadgetEvent(#Button_X, @FnExitWin1())
  TextGadget(#PB_Any, 10, 350, 250,80,"Gadget numbers shown, of no real interest or purpose. Just used when initially setting up.")
     
  TextGadget(#PB_Any, 100, 50, 50,20,Str(#TEXT_Show3))
  TextGadget(#PB_Any, 150, 50, 50,20,Str(#TEXT_Show31))
  ;
  ;....................................
  ;Main event loop. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Repeat
    EventID120=WaitWindowEvent()
    Select eventid120 
      Case #PB_Event_Gadget
        Select EventGadget()   ; was ID
          ;Case #Button_1; Bring up 2nd window.
            ;SecondWindow()
          ;Case #Button_2; Hide first window and bring up 2nd window.
            ;HideWindow(#MainWindow,1)
            ;SecondWindow()
            ;HideWindow(#MainWindow,0)
          Case #BUTTON_X
            btnEXIT_120 = 1 ;CloseWindow(#Win120)
        EndSelect
    EndSelect
  Until btnEXIT_120 = 1 ; EventID120=#PB_Event_CloseWindow ;'%%%%%%%%%%%%%
  If btnEXIT_120 = 1 
    CloseWindow(#Win120)
    btnEXIT_120 = 0
  EndIf
  ;
EndProcedure ; DoOpen120()
;
  ;
EndModule  ; Open120
;
; ╔═══════════════════════════════════════════════╗
; ║ ██████████   PROGRAM STD120 END    ██████████ ║
; ╚═══════════════════════════════════════════════╝ 
If it's falling over......just remember the computer is never wrong!
Post Reply