PostEvent() help, help
Posted: Sun Mar 02, 2025 2:01 pm
Hello everyone,
This is my first time using PostEvent and there is something I don't understand.
In the small test program below, when I launch the program in the PureBasic editor, the message appears after 2 seconds (the 2 seconds simulate the duration of the procedure).
On the other hand, if I compile the program and launch the .exe, the message never appears!
I searched the documentation but couldn't find why!
Thank you for your help
ps: I did not put a button to launch the procedure because the program that I write with PostEvent will be launched by another program and must start automatically.
This is my first time using PostEvent and there is something I don't understand.
In the small test program below, when I launch the program in the PureBasic editor, the message appears after 2 seconds (the 2 seconds simulate the duration of the procedure).
On the other hand, if I compile the program and launch the .exe, the message never appears!
I searched the documentation but couldn't find why!
Thank you for your help
ps: I did not put a button to launch the procedure because the program that I write with PostEvent will be launched by another program and must start automatically.
Code: Select all
EnableExplicit
Declare traitement()
Global fenetre.i
Global bt_quitter
Global traitement.i
Global gadgetid.i
Global txt_message.i
Global quitter.b
fenetre = OpenWindow(#PB_Any, 0, 0, 400, 200, "PostEvent", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
bt_quitter = ButtonGadget(#PB_Any, 290, 160, 100, 30, "Quitter")
txt_message =TextGadget(#PB_Any, 10, 100, 200, 30, "")
quitter = #False
traitement()
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
quitter = #True
;===== Evènements sur les gadgets
Case #PB_Event_Gadget
gadgetid = EventGadget()
;===== Clic sur bouton Quitter
If gadgetid = bt_quitter
Select EventType()
Case #PB_EventType_LeftClick
quitter = #True
EndSelect
EndIf
;===== PostEvent
Case traitement
SetGadgetText(txt_message, "Traitement terminé")
EndSelect
Until quitter
CloseWindow(fenetre)
End
Procedure traitement()
Delay(2000) ; simulate procedure duration
PostEvent(traitement)
EndProcedure