Page 1 of 1
Put time on the caption of the main form
Posted: Wed Apr 19, 2017 11:30 am
by PowerSoft
How do I put the actual time in the caption of my main form?
Thanks for any help
Code: Select all
; The main event loop as usual, the only change is to call the automatically
; generated event procedure for each window.
Repeat
Event = WaitWindowEvent()
Select EventWindow()
Case #FrmMainGenerator ; button generate gedrukt
FrmMain_Events(event) ; execute form main events
Case #FrmMainCopy ; button copy gedrukt
FrmMain_Events(event) ; execute form main events
EndSelect
PutTimeInCaption()
Until Event = #PB_Event_CloseWindow ; Quit on any window close
Procedure PutTimeInCaption()
time$=FormatDate("%mm/%dd/%yyyy", Date()) +" "+FormatDate("%hh:%ii:%ss", Date())
?????????
EndProcedure
Re: Put time on the caption of the main form
Posted: Wed Apr 19, 2017 11:51 am
by Kwai chang caine
Perhaps like this
Code: Select all
Enumeration
#FrmMainGenerator
#FrmMainCopy
EndEnumeration
Procedure PutTimeInCaption()
time$=FormatDate("%mm/%dd/%yyyy", Date()) +" "+FormatDate("%hh:%ii:%ss", Date())
SetWindowTitle(#FrmMainGenerator, Time$)
EndProcedure
Procedure FrmMain_Events(event)
EndProcedure
OpenWindow(#FrmMainGenerator, 100, 100,500, 100, "Window")
Repeat
Event = WaitWindowEvent(10)
Select EventWindow()
Case #FrmMainGenerator , #FrmMainCopy
FrmMain_Events(event) ; execute form main events
EndSelect
PutTimeInCaption()
Until Event = #PB_Event_CloseWindow ; Quit on any window close
Re: Put time on the caption of the main form
Posted: Wed Apr 19, 2017 11:51 am
by Bisonte
Code: Select all
????????? = SetWindowTitle(Window, time$)
Re: Put time on the caption of the main form
Posted: Wed Apr 19, 2017 2:19 pm
by ts-soft
Code: Select all
Procedure EventSetTitle()
SetWindowTitle(0, FormatDate("%mm/%dd/%yyyy %hh:%ii:%ss", Date()))
EndProcedure
OpenWindow(0, #PB_Ignore, #PB_Ignore, 640, 20, "")
AddWindowTimer(0, 1, 250)
BindEvent(#PB_Event_Timer, @EventSetTitle(), 0, 1)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
?
Re: Put time on the caption of the main form
Posted: Wed Apr 19, 2017 5:18 pm
by TI-994A
PowerSoft wrote:How do I put the actual time in the caption of my main form?
Code: Select all
; The main event loop as usual, the only change is to call the automatically
; generated event procedure for each window.
A multi-window approach:
Code: Select all
Global windows
Procedure UpdateTime()
Protected win = EventWindow()
SetWindowTitle(win, "Window " + Str(GetWindowData(win)) + " - " +
FormatDate("%mm/%dd/%yyyy %hh:%ii:%ss", Date()))
EndProcedure
Procedure CloseWin()
CloseWindow(EventWindow())
windows - 1
EndProcedure
Procedure AddTime(win.i)
Static nextTimer
If IsWindow(win)
nextTimer + 1
windows + 1
AddWindowTimer(win, nextTimer, 1000)
BindEvent(#PB_Event_Timer, @UpdateTime())
BindEvent(#PB_Event_CloseWindow, @CloseWin(), win)
SetWindowData(win, nextTimer)
EndIf
EndProcedure
win1 = OpenWindow(#PB_Any, 200, 200, 600, 300, "Window 1")
win2 = OpenWindow(#PB_Any, 300, 300, 600, 300, "Window 2")
win3 = OpenWindow(#PB_Any, 400, 400, 600, 300, "Window 3")
AddTime(win1)
AddTime(win2)
AddTime(win3)
While WaitWindowEvent() ! #PB_Event_CloseWindow And windows : Wend
Re: Put time on the caption of the main form
Posted: Sat Apr 22, 2017 3:35 pm
by PowerSoft
Kwai chang caine wrote:Perhaps like this
Code: Select all
Enumeration
#FrmMainGenerator
#FrmMainCopy
EndEnumeration
Procedure PutTimeInCaption()
time$=FormatDate("%mm/%dd/%yyyy", Date()) +" "+FormatDate("%hh:%ii:%ss", Date())
SetWindowTitle(#FrmMainGenerator, Time$)
EndProcedure
Procedure FrmMain_Events(event)
EndProcedure
OpenWindow(#FrmMainGenerator, 100, 100,500, 100, "Window")
Repeat
Event = WaitWindowEvent(10)
Select EventWindow()
Case #FrmMainGenerator , #FrmMainCopy
FrmMain_Events(event) ; execute form main events
EndSelect
PutTimeInCaption()
Until Event = #PB_Event_CloseWindow ; Quit on any window close
The time is printed in the main window, but is not automaticly updated.
Only when there are activities!
Like when the mouse is going over the window
Re: Put time on the caption of the main form
Posted: Sat Apr 22, 2017 4:38 pm
by Marc56us
As ts-soft and TI-994A said: uses a
Timer to force the execution of a procedure at a given interval.
http://www.purebasic.com/documentation/ ... timer.html
(your sample with timer)
I deleted the procedure because one line is enough to update the title of the window.
I am very lazy
Code: Select all
Enumeration
#FrmMainGenerator
#FrmMainCopy
#Sec
EndEnumeration
; Note needed, see below
; Procedure PutTimeInCaption()
; time$=FormatDate("%mm/%dd/%yyyy", Date()) +" "+FormatDate("%hh:%ii:%ss", Date())
; SetWindowTitle(#FrmMainGenerator, Time$)
; EndProcedure
Procedure FrmMain_Events(event)
EndProcedure
OpenWindow(#FrmMainGenerator, 100, 100,500, 100, "Window")
; --- Add timer (1sec)
AddWindowTimer(#FrmMainGenerator, #Sec, 1000)
Repeat
Event = WaitWindowEvent(10)
If Event = #PB_Event_Timer
SetWindowTitle(#FrmMainGenerator,
FormatDate("%mm/%dd/%yyyy %hh:%ii:%ss",
Date()))
EndIf
Select EventWindow()
Case #FrmMainGenerator, #FrmMainCopy
FrmMain_Events(event) ; execute form main events
EndSelect
;PutTimeInCaption()
Until Event = #PB_Event_CloseWindow ; Quit on any window close

Re: Put time on the caption of the main form
Posted: Sat Apr 22, 2017 5:06 pm
by ts-soft
@Marc56us
But when you move the window, your time is stopping. Better is to use BindEvent()!
Re: Put time on the caption of the main form
Posted: Sat Apr 22, 2017 5:32 pm
by TI-994A
PowerSoft wrote:The time is printed in the main window, but is not automaticly updated.
Here's a simplified, single-window version:
Code: Select all
Procedure UpdateTime()
SetWindowTitle(win, "Window Title - " +
FormatDate("%mm/%dd/%yyyy %hh:%ii:%ss", Date()))
EndProcedure
OpenWindow(0, 300, 300, 600, 300, "Window Title")
AddWindowTimer(0, 0, 1000)
BindEvent(#PB_Event_Timer, @UpdateTime())
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend