Page 1 of 1
Why is the Clock stopping when the MessageRequester dialog box appears ?
Posted: Tue May 21, 2024 2:32 am
by hoangdiemtinh
I am new to PB.
My primary language is not US/UK. I am using Google Translate.
Why is the Clock stopping when the MessageRequester dialog box appears ? How to fix this ? Thank you.
Code: Select all
TextGadget(#text_CLOCK, 10, 10, 80, 20, "8:18:18", #PB_Text_Center | #SS_CENTERIMAGE)
AddWindowTimer(#main_Window, #Timer_1, 1000)
.....
.....
Case #PB_Event_Timer
SetGadgetText(#text_CLOCK, FormatDate("%hh:%ii:%ss", Date()))
Re: Why is the Clock stopping when the MessageRequester dialog box appears ?
Posted: Tue May 21, 2024 2:54 am
by AZJIO
A modal window in a graphical user interface is a window that blocks the user from interacting with its parent application until the user closes the window.
Re: Why is the Clock stopping when the MessageRequester dialog box appears ?
Posted: Tue May 21, 2024 3:03 am
by hoangdiemtinh
@AZJIO, Is there a solution, like Thread, to fix this problem ?
Re: Why is the Clock stopping when the MessageRequester dialog box appears ?
Posted: Tue May 21, 2024 4:11 am
by AZJIO
1. You can call cmd.exe and pass text for output
Code: Select all
Title$ = "Title"
Message$ = "Message"
tmp$ = "Title " + Title$ + " & @Echo off & @Echo. & Color 1e & @Echo. " + Message$ + "& "
tmp$ = EscapeString(tmp$)
RunProgram("cmd.exe", "/c (" + tmp$ + " set /p Ok=^>^>)", "")
2. You can compile a small file using a MessageRequester in it, where the text is transmitted via the command line.
Code: Select all
Define Title$
Define Message$
Define flag
Define Count = CountProgramParameters()
If Count > 0
Message$ = ProgramParameter(0)
If Count > 1
Title$ = ProgramParameter(1)
If Count > 2
flag = Val(ProgramParameter(2))
EndIf
EndIf
MessageRequester(Title$, Message$, flag)
EndIf
3. You can make your own window, but do not make it modal, that is, not blocking the parent window.
Code: Select all
If OpenWindow(0, 0, 0, 520, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 120, 30, "Window")
TextGadget(3, 10, 50, 210, 20, "0")
If OpenWindow(1, 0, 0, 220, 100, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_Invisible)
TextGadget(2, 10, 10, 210, 20, "Hello")
ButtonGadget(1, 10, 40, 120, 30, "Close")
StickyWindow(1, #True)
EndIf
AddWindowTimer(0, 0, 1000)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Timer
i+1
SetGadgetText(3, Str(i))
Case #PB_Event_Gadget
Select EventGadget()
Case 0
HideWindow(1, #False)
Case 1
HideWindow(1, #True)
EndSelect
Case #PB_Event_CloseWindow
wn = EventWindow()
If wn
HideWindow(1, #True)
Else
CloseWindow(0)
CloseWindow(1)
End
EndIf
EndSelect
ForEver
EndIf
Re: Why is the Clock stopping when the MessageRequester dialog box appears ?
Posted: Tue May 21, 2024 8:48 am
by BarryG
Apparently you're not supposed to update gadgets from a thread, but this works. So until the compiler complains about it: sue me.
Code: Select all
Global WindowID, ButtonID, TextID, ClockThread
Procedure UpdateClock(param)
Repeat
SetGadgetText(TextID, FormatDate("%hh:%ii:%ss", Date()))
Delay(500)
ForEver
EndProcedure
WindowID = OpenWindow(0, 200, 200, 300, 100, "Clock Update Example", #PB_Window_SystemMenu)
ButtonID = ButtonGadget(#PB_Any, 50, 20, 200, 25, "Show MessageRequster")
TextID = TextGadget(#PB_Any, 50, 60, 200, 20, "", #PB_Text_Center)
ClockThread = CreateThread(@UpdateClock(), 0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = ButtonID
MessageRequester("Information", "This is a non-blocking message.")
EndIf
EndSelect
ForEver
Re: Why is the Clock stopping when the MessageRequester dialog box appears ?
Posted: Tue May 21, 2024 9:04 am
by hoangdiemtinh
Thanks @BarryG.
Great code. The problem has been resolved.
Re: Why is the Clock stopping when the MessageRequester dialog box appears ?
Posted: Tue May 21, 2024 11:04 am
by Mindphazer
BarryG wrote: Tue May 21, 2024 8:48 am
Apparently you're not supposed to update gadgets from a thread, but this works. So until the compiler complains about it: sue me.
Hi Barry,
it does work on Windows, but does not on MacOS. That's why, unless the code is to be used on Windows only, you're not supposed to do it

Re: Why is the Clock stopping when the MessageRequester dialog box appears ?
Posted: Tue May 21, 2024 11:46 am
by BarryG
I would've thought the compiler throw a warning message then, like it does if you use WindowEvent() in a thread? But it doesn't, so I assumed it's okay to use.
Re: Why is the Clock stopping when the MessageRequester dialog box appears ?
Posted: Tue May 21, 2024 6:01 pm
by Michael Vogel
Nothing complete new, just another option...
Code: Select all
Procedure Message(nil)
MessageRequester("Hi","ho")
PostEvent(9999)
EndProcedure
If OpenWindow(0, 0, 0, 520, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 120, 30, "Window")
ButtonGadget(9,10,50,120,30,"Requester")
TextGadget(3, 10, 100, 210, 20, "0")
If OpenWindow(1, 0, 0, 220, 100, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_Invisible)
TextGadget(2, 10, 10, 210, 20, "Hello")
ButtonGadget(1, 10, 40, 120, 30, "Close")
StickyWindow(1, #True)
EndIf
AddWindowTimer(0, 0, 100)
Repeat
Select WaitWindowEvent()
Case 9999
DisableGadget(9,0)
Case #PB_Event_Timer
i+1
SetGadgetText(3, StrF(i/10,1))
Case #PB_Event_Gadget
Select EventGadget()
Case 0
HideWindow(1, #False)
Case 1
HideWindow(1, #True)
Case 9
DisableGadget(9,1)
CreateThread(@Message(),#Null)
EndSelect
Case #PB_Event_CloseWindow
wn = EventWindow()
If wn
HideWindow(1, #True)
Else
CloseWindow(0)
CloseWindow(1)
End
EndIf
EndSelect
ForEver
EndIf