I see this as very strange or a bug. What am I doing wrong?
Code: Select all
IncludeFile "Window2.pb"
Global MainWindow.l,Wnd2.l
MainWindow = OpenWindow(#PB_Any, 0, 0, 600, 220, "", #PB_Window_SystemMenu)
frmMain = OpenWindow(#PB_Any, 0, 0, 600, 220, "", #PB_Window_SystemMenu)
CreateMenu(100, WindowID(frmMain))
MenuTitle("File")
MenuItem(101, "Open")
Repeat
event = WaitWindowEvent()
If EventWindow() = Wnd2;Select window.
Window2::Event_Handler(event)
Debug EventWindow()
EndIf ;EventWindow()
;Not the second window so must be the main window
Select event
Case #PB_Event_Menu
Select EventMenu()
;Only one menu item
Case 101
;Show the 2nd window
Debug "Open 2nd"
Wnd2 = Window2::OpenWnd2()
EndSelect ;Eventmenu
Case #PB_Event_CloseWindow
End
EndSelect ;Event
ForEver
Code: Select all
DeclareModule Window2
Global ThisWindow.l
Global Ok.i = 0
Declare.l OpenWnd2()
Declare Event_Handler(event)
EndDeclareModule
Module Window2
Global btnOk, btnCancel
Procedure.l OpenWnd2()
ThisWindow = OpenWindow(#PB_Any, x, y, 280, 180, "Test Window", #PB_Window_SystemMenu)
btnOk = ButtonGadget(#PB_Any, 130, 140, 60, 30, "Ok")
btnCancel = ButtonGadget(#PB_Any, 210, 140, 60, 30, "Cancel")
ProcedureReturn ThisWindow
EndProcedure
Procedure Event_Handler(event)
Select event
Case #PB_Event_CloseWindow
CloseWindow(ThisWindow)
Case #PB_Event_Gadget
Select EventGadget()
Case btnOk
Ok = 1
CloseWindow(ThisWindow)
Case btnCancel
Ok = 0
CloseWindow(ThisWindow)
EndSelect
EndSelect
EndProcedure
EndModule
Works fine. Click menu item and second window opens click close and all is ok.
However I noticed that whatever event happens on either window when both are open EventWindow() allways comes back with the second window identifier even with mouse move events on the main window! Moving the two apart has no effect. You can see this from the debug statements I have added.