Parent window disappears on openwindow

Just starting out? Need help? Post your questions and find answers here.
liam
User
User
Posts: 38
Joined: Tue Jul 03, 2007 3:48 am
Location: Philippines

Parent window disappears on openwindow

Post by liam »

hello guys, im trying to open a modal window from my main window and my problem is that the parent window disappears as soon as the child window appears. then it hangs all of a sudden.
i want the child window to be able to appear with the parent in the background but inaccessible until the cancel button on the child is pressed closing it then enabling the parent window back again.
here is my code:

Code: Select all

Enumeration
  #PARENTWINDOW
  #MAINMENUBAR
  #MENU_FILE_OPEN
EndEnumeration

Enumeration
  #CHILDWINDOW
  #CHILD_BUTTON_CANCEL
EndEnumeration

Procedure OpenChildWindow()
  If OpenWindow(#CHILDWINDOW, 545, 318, 508, 242, "Child Window: Mommy! Where are you?????",  #PB_Window_WindowCentered, #PARENTWINDOW)
    ButtonGadget(#CHILD_BUTTON_CANCEL, 395, 205, 90, 25, "CANCEL")
  EndIf
EndProcedure

If OpenWindow(#PARENTWINDOW, 490, 193, 800, 620, "Parent Window (Go to File > Open to open a child window)",  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
  If CreateMenu(#MAINMENUBAR, WindowID(#PARENTWINDOW))
    MenuTitle("File")
    MenuItem(#MENU_FILE_OPEN, "&Open...")
  EndIf 
EndIf    

Repeat
  Event = WaitWindowEvent()
  Select Event 
    Case #PB_Event_Menu
      Select EventMenu()
        Case #MENU_FILE_OPEN
          OpenChildWindow()
          DisableWindow(#PARENTWINDOW,#True)
          StickyWindow(#CHILDWINDOW,#True)            
      EndSelect
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #CHILD_BUTTON_CANCEL
          CloseWindow(#CHILDWINDOW)
          DisableWindow(#PARENTWINDOW,#False)
          SetActiveWindow(#PARENTWINDOW)
      EndSelect
  EndSelect  
Until Event = #PB_Event_CloseWindow
PureBasic 4.51(x86) on WinXP SP3
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Parent window disappears on openwindow

Post by IdeasVacuum »

It's the Enumeration - you should have all Windows in the same Enumeration.

Code: Select all

Enumeration
  #PARENTWINDOW
  #MAINMENUBAR
  #MENU_FILE_OPEN
  #CHILDWINDOW
  #CHILD_BUTTON_CANCEL
EndEnumeration

Procedure OpenChildWindow()
  If OpenWindow(#CHILDWINDOW, 545, 318, 508, 242, "Child Window: Mommy! Where are you?????",  #PB_Window_WindowCentered, #PARENTWINDOW)
    ButtonGadget(#CHILD_BUTTON_CANCEL, 395, 205, 90, 25, "CANCEL")
  EndIf
EndProcedure

Procedure OpenParent()
If OpenWindow(#PARENTWINDOW, 490, 193, 800, 620, "Parent Window (Go to File > Open to open a child window)",  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
  If CreateMenu(#MAINMENUBAR, WindowID(#PARENTWINDOW))
    MenuTitle("File")
    MenuItem(#MENU_FILE_OPEN, "&Open...")
  EndIf
EndIf
EndProcedure

OpenParent()

Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_Menu
      Select EventMenu()
        Case #MENU_FILE_OPEN
          DisableWindow(#PARENTWINDOW,#True)
          OpenChildWindow()
          StickyWindow(#CHILDWINDOW,#True)           
      EndSelect
     
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #CHILD_BUTTON_CANCEL
          CloseWindow(#CHILDWINDOW)
          DisableWindow(#PARENTWINDOW,#False)
          SetActiveWindow(#PARENTWINDOW)
      EndSelect
  EndSelect 
Until Event = #PB_Event_CloseWindow 

End
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
liam
User
User
Posts: 38
Joined: Tue Jul 03, 2007 3:48 am
Location: Philippines

Re: Parent window disappears on openwindow

Post by liam »

i see. so even if i place the openchildwindow procedure in a separate file, does it mean that i still need to put its gadget enumerations in the enumeration in my main form?
PureBasic 4.51(x86) on WinXP SP3
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Parent window disappears on openwindow

Post by Trond »

liam wrote:i see. so even if i place the openchildwindow procedure in a separate file, does it mean that i still need to put its gadget enumerations in the enumeration in my main form?
Files do not matter, to the compiler it looks like one big file with contents of the included files pasted at the IncludeFile statements. But you should have one enumeration for each object type:

Code: Select all

Enumeration ; Windows
  #WndMain
  #WndParent
  #WndOptions
  #WndOther
  ...
EndEnumeration

Enumeration ; Gadgets
  #Main_LblHeader
  #Main_StrInput
  #Main_BtnOk
  #Options_BtnOk
  #Options_ChkOption1
  ...
EndEnumeration
Alternatively you can chain enumerations:

Code: Select all

Enumeration ; Main Windows Gadgets
  #Main_LblHeader
  #Main_StrInput
  #Main_BtnOk
  #Main_GadgetEnumeration ; Place last
EndEnumerations

Enumeration #Main_GadgetEnumeration ; Option Window Gadgets
  #Options_BtnOk
  #Options_ChkOption1
  ...
EndEnumeration
liam
User
User
Posts: 38
Joined: Tue Jul 03, 2007 3:48 am
Location: Philippines

Re: Parent window disappears on openwindow

Post by liam »

ok now i get it. thanks for the explanation and tips trond!
PureBasic 4.51(x86) on WinXP SP3
Post Reply