Re: WaitWindowEvent() - question (win/lin)
Posted: Sun Apr 24, 2016 11:29 am
it depends on the type of message though. if you post messages to the window que, then yes. but if you send messages to the window proc, then it doesnt really matter. you could even use SetGadgetState() etc. from withing a thread, to update the progress. no one is forcing you to post messages to the window que.
and as long as you dont mess around with the state of the gadget, from any other thread, its perfectly safe. even if you do, windows is very forgiving, but its a pretty bad habbit though.
personally, i only use the window que for the user interaction. everything else i do with callbacks. in your example, dragging the window will stop updating the clock, because the window que is paused as well. if you use a callback however, it will work independently.
there is really no right or wrong. different tools, for different tasks.
c ya,
nco2k
personally, i only use the window que for the user interaction. everything else i do with callbacks. in your example, dragging the window will stop updating the clock, because the window que is paused as well. if you use a callback however, it will work independently.
there is really no right or wrong. different tools, for different tasks.
Code: Select all
Enumeration
#MainWindow
#ClockDisplay
#SettingsButton
EndEnumeration
Define settingsWindow, requiredInfo, doneButton, infoDone, wFlags
Procedure OpenSettingsWindow(parentWindow.i)
Shared settingsWindow, requiredInfo, doneButton, wFlags
settingsWindow = OpenWindow(#PB_Any, #PB_Any, #PB_Any,
300, 200, "Settings Window",
wFlags, WindowID(parentWindow))
requiredInfo = StringGadget(#PB_Any, 100, 80, 100, 30, "")
doneButton = ButtonGadget(#PB_Any, 100, 130, 100, 30, "DONE")
SetActiveGadget(requiredInfo)
EndProcedure
Procedure CloseSettingsWindow(done.i)
Shared infoDone, settingsWindow
If infoDone
infoDone = #False
CloseWindow(settingsWindow)
DisableWindow(#MainWindow, #False)
Else
If done
MessageRequester("Settings", "Input Required!")
Else
If MessageRequester("Settings", "Confirm Abort Settings?",
#PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
CloseWindow(settingsWindow)
DisableWindow(#MainWindow, #False)
EndIf
EndIf
EndIf
EndProcedure
Procedure ClockDisplay()
SetGadgetText(#ClockDisplay, FormatDate("%hh:%ii:%ss", Date()))
EndProcedure
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 600, 400, "Main Window", wFlags)
TextGadget(#ClockDisplay, 10, 10, 200, 30, FormatDate("%hh:%ii:%ss", Date()))
ButtonGadget(#SettingsButton, 100, 330, 400, 50, "SETTINGS")
AddWindowTimer(#MainWindow, 0, 1000)
BindEvent(#PB_Event_Timer, @ClockDisplay(), #MainWindow)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case #MainWindow
appQuit = 1
Case settingsWindow
CloseSettingsWindow(0)
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #SettingsButton
DisableWindow(#MainWindow, #True)
OpenSettingsWindow(#MainWindow)
Case doneButton
CloseSettingsWindow(1)
Case requiredInfo
Select EventType()
Case #PB_EventType_Change
If Trim(GetGadgetText(requiredInfo))
infoDone = #True
Else
infoDone = #False
EndIf
EndSelect
EndSelect
EndSelect
Until appQuit = 1nco2k