Posted: Fri Nov 03, 2006 11:31 pm
OK, thanks very much for testing. It seems the clock uses some cpu on some machines but I don't know why. Frustrating.
http://www.purebasic.com
https://www.purebasic.fr/english/
Oh, yeah...netmaestro wrote:Check the program name...
Yes, like the your previous VistaClock, which included 2 backgrounds.What if we would like a background for the clock? Razz (not transparent)
Code: Select all
; Define
UsePNGImageDecoder()
UseTIFFImageDecoder()
Global Alpha = 255
Global UhrX=260
Global UhrY=260
Global MidX=UhrX>>1
Global MidY=UhrY>>1
Global Stunde,Minute,Sekunde
Global Zeit,LetzteZeit
Global WinID,ImageDC
Enumeration
#Hintergrund
#Zeichenflaeche
#Stundenzeiger
#ImgBack
#ImgBorder
#ImgGloss
#ImgLongPointer
#ImgMediumPointer
#ImgSmallPointer
EndEnumeration
DataSection
Uhr:
IncludeBinary "fiat.png"
StundenZeiger:
IncludeBinary "z1.bmp"
EndDataSection
Global Dim SinQ(59)
Global Dim CosQ(59)
For i=0 To 59
SinQ(i)=Sin(i/30*#PI)*MidX
CosQ(i)=Cos(i/30*#PI)*MidY
Next i
; EndDefine
Procedure MyLineXY(x,y,x1,y1,Color,Width=3)
hDC=ImageDC;GetDC_(WindowID(0))
pen=CreatePen_(#PS_SOLID,Width,#Black)
hPenOld=SelectObject_(hDC,pen)
MoveToEx_(hDC,x-1,y,0):LineTo_(hDC,x1-1,y1)
MoveToEx_(hDC,x,y-1,0):LineTo_(hDC,x1,y1-1)
MoveToEx_(hDC,x+1,y,0):LineTo_(hDC,x1+1,y1)
MoveToEx_(hDC,x,y+1,0):LineTo_(hDC,x1,y1+1)
DeleteObject_(pen)
DeleteObject_(hPenOld)
pen=CreatePen_(#PS_SOLID,Width,Color)
hPenOld=SelectObject_(hDC,pen)
MoveToEx_(hDC,x,y,0):LineTo_(hDC,x1,y1)
DeleteObject_(pen)
DeleteObject_(hPenOld)
EndProcedure
Procedure UpdateClock()
Zeit=Date()
If Zeit<>LetzteZeit
LetzteZeit=Zeit
Stunde=Hour(Zeit)
Minute=Minute(Zeit)
Sekunde=Second(Zeit)
; Fresh copy of background to draw on
CreateImage(#Zeichenflaeche,UhrX,UhrY)
ImageDC=StartDrawing(ImageOutput(#Zeichenflaeche))
DrawAlphaImage(ImageID(#Hintergrund),0,0)
MyLineXY(MidX-SinQ(Stunde)>>5,MidY+CosQ(Stunde)>>5,MidX+(SinQ(Stunde)*1)>>1,MidY-(CosQ(Stunde)*1)>>1,#White,3)
MyLineXY(MidX-SinQ(Minute)>>5,MidY+CosQ(Minute)>>5,MidX+(SinQ(Minute)*6)>>3,MidY-(CosQ(Minute)*6)>>3,#White,5)
MyLineXY(MidX-SinQ(Sekunde)>>3,MidY+CosQ(Sekunde)>>3,MidX+(SinQ(Sekunde)*7)>>3,MidY-(CosQ(Sekunde)*7)>>3,#Black,1)
; Update the window
Static ContextOffset.POINT
Static BlendMode.BLENDFUNCTION
Static BitmapInfo.BITMAP
GetObject_(ImageID(#Zeichenflaeche),SizeOf(BITMAP),@BitmapInfo)
BlendMode\SourceConstantAlpha=Alpha
BlendMode\AlphaFormat=1
UpdateLayeredWindow_(WindowID(0),0,0,@BitmapInfo+4,ImageDC,@ContextOffset,0,@BlendMode,2)
FreeImage(#Zeichenflaeche)
StopDrawing()
EndIf
EndProcedure
#APPNAME = "Clock"
OpenWindow(1, 0, 0, 0, 0, #APPNAME + " Parent", #PB_Window_Invisible)
OpenWindow(0, 0, 0, 512, 384, #APPNAME, #PB_Window_Invisible, WindowID(1))
SetWindowLong_(WindowID(0), #GWL_EXSTYLE, GetWindowLong_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_LAYERED)
CatchImage(#Hintergrund,?Uhr)
CatchImage(#Stundenzeiger,?Stundenzeiger)
UpdateClock()
HideWindow(0,0)
SetParent_(WindowID(0),0)
StickyWindow(0,1)
quit=0
Repeat
UpdateClock()
Select WaitWindowEvent(250)
Case #WM_LBUTTONDOWN
SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
Case #WM_CHAR
quit=#True
EndSelect
Until quit
Be patient, its on my notebook far, far away...jack wrote:@Michael Vogel, could you give a link to your images "fiat.png" and "z1.bmp" ?