I am having trouble returning focus back to my main window after lunching a second window off a gadget icon selection.
This is my main loop (the Debug commands are there to tell me what has focus at key points, the DisplayEntry() line is a procedure which displays data on this screen and is not relavant to the problem):
Code: Select all
If Window_WindowMain()
SetWindowCallback(@WindowCallback())
DisplayEntry()
Debug "Entry Displayed on main window: " + Str(GetActiveWindow())
quitWindowMain=0
Repeat
EventID =WaitWindowEvent()
MenuID =EventMenu()
GadgetID =EventGadget()
WindowID =EventWindow()
Select EventID
Case #PB_Event_CloseWindow
If WindowID=#Window_WindowMain
quitWindowMain=1
EndIf
Case #PB_Event_Gadget
Select GadgetID
Case #Gadget_WindowMain_MagCover
Select EventType()
Case #PB_EventType_LeftDoubleClick
Case #PB_EventType_RightDoubleClick
Case #PB_EventType_RightClick
Default
EndSelect
Case #Gadget_WindowMain_Panel3
Case #Gadget_WindowMain_Mdb_ExitButton
Exit_Mdb()
Case #Gadget_WindowMain_Mdb_No
Case #Gadget_WindowMain_Mdb_Search
Case #Gadget_WindowMain_Mdb_Yes
Case #Gadget_WindowMain_Mdb_Del
Case #Gadget_WindowMain_Mdb_Edt
Case #Gadget_WindowMain_Mdb_Add
NewEntry_WindowSwapTo()
NewEntry_MainLoop()
NewEntry_WindowSwapBack()
Debug "Back To Main Loop: " + Str(GetActiveWindow())
SetActiveWindow(#Window_WindowMain)
Debug "SetActiveWindow command run: " + Str(GetActiveWindow())
Case #Gadget_WindowMain_Mdb_Prev
Case #Gadget_WindowMain_Mdb_Next
Case #Gadget_WindowMain_Mdb_Config
EndSelect
EndSelect
Until quitWindowMain
CloseWindow(#Window_WindowMain)
EndIf
End
Code: Select all
Procedure NewEntry_MainLoop()
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndProcedure
Procedure NewEntry_WindowSwapTo()
Debug "About to Open NewEntry Window: " + Str(GetActiveWindow())
DisableWindow(#Window_WindowMain,1)
HideWindow(#Window_WindowMain,1)
Window_WindowNewEntry()
Debug "NewEntry Window Open: " + Str(GetActiveWindow())
EndProcedure
Procedure NewEntry_WindowSwapBack()
DisableWindow(#Window_WindowNewEntry,1)
HideWindow(#Window_WindowNewEntry,1)
CloseWindow(#Window_WindowNewEntry)
Debug "NewEntry Closed: " + Str(GetActiveWindow())
HideWindow(#Window_WindowMain,0)
EndProcedure
Entry Displayed on main window: 1
About to open NewEntry Window: 1
NewEntry WIndow Open: 2
NewEntry Closed: -1
Back to Main Loop: 1
SetActiveWindow Command run: 1
To me this says the main window (1) is active until the NewEntry Window (2) is opened so focus is switched to that. When I close the window nothing has focus (-1) and then when the main window (1) is unhidden focus goes back to that.
But when I try to click on the window I get the alarm "ding" sound when I click the mose anywhere on thw window and the window cannot be selected or touched. I cannot close the window and have to force PB to kill the program,
Can anyone explain why this happening and guide me on how to correct it so I get the main window back after the NewEntry one closes.
Many thanks
Arcee