Page 1 of 1

Parent window disappears on openwindow

Posted: Thu May 26, 2011 10:42 am
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

Re: Parent window disappears on openwindow

Posted: Thu May 26, 2011 12:01 pm
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

Re: Parent window disappears on openwindow

Posted: Thu May 26, 2011 12:42 pm
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?

Re: Parent window disappears on openwindow

Posted: Thu May 26, 2011 1:17 pm
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

Re: Parent window disappears on openwindow

Posted: Thu May 26, 2011 1:25 pm
by liam
ok now i get it. thanks for the explanation and tips trond!