Something's very important:
1. There should always be only one event loop in the program.
2. Never use a delay in the event loop.
3. Only use WindowEvent() in special cases, otherwise always WaitWindowEvent(...)
4. Use EnableExplicit to avoid typing errors of variables
Added
5. Use not Long (Event.l) for default variables. Use Integer (Event.i). Integer is 32bit on x86 and 64bit on x64 programs.
P.S
Small example...
Update
Code: Select all
;-TOP
EnableExplicit
; -----------------------------------------------------------------------------
Enumeration windows
#Main
#Dialog
EndEnumeration
Enumeration menus
#MainMenu
EndEnumeration
Enumeration menuitems
#MainMenuExit
#MainMenuDialog
EndEnumeration
Enumeration gadgets
#MainList
#DialogString
#DialogOk
EndEnumeration
; -----------------------------------------------------------------------------
Global ExitApplication
; -----------------------------------------------------------------------------
Procedure OpenDialogWindow()
If OpenWindow(#Dialog, #PB_Ignore, #PB_Ignore, 300, 80, "Dialog Window", #PB_Window_SystemMenu, WindowID(#Main))
StringGadget(#DialogString, 10, 10, 280, 25, "")
ButtonGadget(#DialogOk, 150 - 30, 45, 60, 25 , "Ok")
DisableWindow(#Main, 1)
EndIf
EndProcedure
; -----------------------------------------------------------------------------
Procedure DoEventDialog()
Select Event()
Case #PB_Event_CloseWindow
DisableWindow(#main, 0)
CloseWindow(#Dialog)
Case #PB_Event_Gadget
Select EventGadget()
Case #DialogOk
AddGadgetItem(#MainList, - 1, GetGadgetText(#DialogString))
DisableWindow(#main, 0)
CloseWindow(#Dialog)
EndSelect
EndSelect
EndProcedure
; -----------------------------------------------------------------------------
Procedure Main()
Protected Event
If OpenWindow(#main, #PB_Ignore, #PB_Ignore, 800, 600, "Main Window", #PB_Window_SystemMenu)
CreateMenu(#MainMenu, WindowID(#Main))
MenuTitle("&File")
MenuItem(#MainMenuDialog, "&Open Dialog")
MenuItem(#MainMenuExit, "E&xit")
ListViewGadget(#MainList, 0, 0, WindowWidth(#Main), WindowHeight(#Main) - MenuHeight())
; Event Loop
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
If EventWindow() = #Main
ExitApplication = 1
EndIf
Case #PB_Event_Menu
Select EventMenu()
Case #MainMenuExit
ExitApplication = 1
Case #MainMenuDialog
OpenDialogWindow()
EndSelect
EndSelect
; Do dialog events
Select EventWindow()
Case #Dialog
DoEventDialog()
EndSelect
Until ExitApplication
EndIf
EndProcedure : Main()
End
; -----------------------------------------------------------------------------