The last in the 'clock trilogy' .. :)
This small program demos calling an API function .. and it is quite useful.
[Updated: 7 Aug 2011 - see below]
' Desktop (dragable) Time Display
'
' GWS - September 2007 - Creative Basic code
def w:window
def time:string
def flags,false,true,drag,xm,ym:int
def x,y,wid,hgt,xn,yn,scrW,scrH:int
getscreensize scrW,scrH
declare "user32",SetWindowPos(win:window,ins:int,x:int,y:int,wid:int,hgt:int,flags:int),int
window w,(scrW-60)/2,0,60,18,@nocaption,0,"",main
control w,"B,,50,0,10,18,0,1"
setwindowcolor w, 0x555555
setid "SWP_NOMOVE",2
setid "SWP_NOSIZE",1
setid "HWND_TOPMOST",-1
setid "WM_NCLBUTTONDOWN",0xA1
setid "HTCAPTION",2
false = (1 = 2)
true = not false
drag = false
flags = @SWP_NOMOVE|@SWP_NOSIZE
SetWindowPos(w,@HWND_TOPMOST,0,0,0,0,flags)
frontpen w, 0xffff00
setfont w, "Times New Roman",8,400
timeset
starttimer w,10000,1
run = 1
WAITUNTIL run = 0
stoptimer w,1
closewindow w
END
SUB main
select @CLASS
case @IDCLOSEWINDOW
run = 0
case @IDCONTROL
select @CONTROLID
case 1
run = 0
endselect
case @IDLBUTTONDN
' To Move the Window by dragging it .. (Steve's method)
SendMessage w, @WM_NCLBUTTONDOWN,@HTCAPTION,0
case @idtimer
timeset
endselect
RETURN
sub timeset
' set time in HH.MM format and display it ..
time = left$(time$,5)
move w,12,1
print w,time
return
best wishes, :)
Graham
Yeah!
I remember that one.
ok, just wait , i may have some(things) to share too ;D
That's great .. :)
This forum will be a mine of useful ideas .. and programming tips.
Graham
Hi folks,
I've updated this little program to include a right-mouse click context menu.
If you right-click on the clock, and then click on the colour option, you will get a new colour for the display at each click.
' Desktop (dragable) Time Display
' GWS - September 2007 - Creative Basic code
' Updated Aug 2011 for right mouse click contextmenu with colour changes ..
def w:window
def time:string
def flags,false,true,drag,xm,ym:int
def x,y,wid,hgt,xn,yn,scrW,scrH:int
def colours[7],clr:int
getscreensize scrW,scrH
declare "user32",SetWindowPos(win:window,ins:int,x:int,y:int,wid:int,hgt:int,flags:int),int
window w,(scrW-60)/2,0,60,18,@nocaption,0,"",main
control w,"B,,50,0,10,18,0,1"
setwindowcolor w, 0x444444
setid "SWP_NOMOVE",2
setid "SWP_NOSIZE",1
setid "HWND_TOPMOST",-1
setid "WM_NCLBUTTONDOWN",0xA1
setid "HTCAPTION",2
false = (1 = 2)
true = not false
colours[0] = 0xffff00,0x7CFB28,0x00FFFF,0xEF6EEF,0x1080FF,0xFFFFFF
clr = 0
drag = false
flags = @SWP_NOMOVE|@SWP_NOSIZE
SetWindowPos(w,@HWND_TOPMOST,0,0,0,0,flags)
frontpen w, colours[clr]
setfont w, "Times New Roman",8,500
timeset
starttimer w,100,1
run = 1
WAITUNTIL run = 0
stoptimer w,1
closewindow w
END
SUB main
select @CLASS
case @IDCLOSEWINDOW
run = 0
case @IDCONTROL
select @CONTROLID
case 1
run = 0
endselect
case @IDRBUTTONUP
contextmenu w, @MOUSEX, @MOUSEY,"I,About,0,97","I,Colour,0,98","I,Exit,0,99"
case @IDLBUTTONDN
' To Move the Window by dragging it .. (Steve's method)
SendMessage w, @WM_NCLBUTTONDOWN,@HTCAPTION,0
case @IDMENUPICK
select @MENUNUM
case 97
a$ = "Desktop Clock" + chr$(10) + "Version 1.5"
messagebox w,a$,"Creative Basic" ,0|0x40
case 98
clr = clr + 1
if clr > 5 then clr = 0
frontpen w, colours[clr]
case 99
run = 0
endselect
case @IDTIMER
timeset
endselect
RETURN
sub timeset
' set time in HH.MM format and display it ..
time = left$(time$,5)
move w,12,1
print w,time
return
all the best, :)
Graham