Just starting out? Need help? Post your questions and find answers here.
PowerSoft
User
Posts: 65 Joined: Sun Aug 16, 2015 2:54 pm
Post
by PowerSoft » Wed Apr 19, 2017 11:30 am
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
OS X 10.10.5 PB 5.31(x64)
Kwai chang caine
Always Here
Posts: 5353 Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France
Post
by Kwai chang caine » Wed Apr 19, 2017 11:51 am
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 happiness is a road...
Not a destination
Bisonte
Addict
Posts: 1232 Joined: Tue Oct 09, 2007 2:15 am
Post
by Bisonte » Wed Apr 19, 2017 11:51 am
Code: Select all
????????? = SetWindowTitle(Window, time$)
P ureB asic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom
English is not my native language...
(I often use DeepL to translate my texts.)
ts-soft
Always Here
Posts: 5756 Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany
Post
by ts-soft » Wed Apr 19, 2017 2:19 pm
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
?
PureBasic 5.73 |
SpiderBasic 2.30 |
Windows 10 Pro (x64) |
Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
TI-994A
Addict
Posts: 2512 Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:
Post
by TI-994A » Wed Apr 19, 2017 5:18 pm
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
Texas Instruments TI-99/4A Home Computer :
the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
PowerSoft
User
Posts: 65 Joined: Sun Aug 16, 2015 2:54 pm
Post
by PowerSoft » Sat Apr 22, 2017 3:35 pm
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
OS X 10.10.5 PB 5.31(x64)
Marc56us
Addict
Posts: 1479 Joined: Sat Feb 08, 2014 3:26 pm
Post
by Marc56us » Sat Apr 22, 2017 4:38 pm
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
ts-soft
Always Here
Posts: 5756 Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany
Post
by ts-soft » Sat Apr 22, 2017 5:06 pm
@Marc56us
But when you move the window, your time is stopping. Better is to use BindEvent()!
PureBasic 5.73 |
SpiderBasic 2.30 |
Windows 10 Pro (x64) |
Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
TI-994A
Addict
Posts: 2512 Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:
Post
by TI-994A » Sat Apr 22, 2017 5:32 pm
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
Texas Instruments TI-99/4A Home Computer :
the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel