Jump to content

Clock in GDI+


Recommended Posts

Hi again

Funny how things go around. WBD you once provided me that multi-language script. Anyways added it into your script. I think what the team should work on next is a context menu to change always on top, colour and that kind of thing. Glad you are still looking to build upon it.

Picea

#NoTrayIcon
#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\ponx.ico
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Comment=http://mclaveau.com
#AutoIt3Wrapper_Res_Fileversion=0.2
#AutoIt3Wrapper_Res_LegalCopyright=Michel Claveau Informatique
#AutoIt3Wrapper_Res_Language=1036
#AutoIt3Wrapper_Res_Field=CompanyName|Michel Claveau Informatique
#AutoIt3Wrapper_Res_Field=ProductVersion|0.2
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
; credits to WideBoyDixon
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#Include <Date.au3>

Opt("GUIOnEventMode", 1)
$width = 200
$height = 200

$xx=-1
$yy=-1
if $CmdLine[0]>0 then
$xx=$CmdLine[1]
EndIf
if $CmdLine[0]>1 then
$yy=$CmdLine[2]
EndIf
If $xx<0 Then $xx=@DesktopWidth-$width+30
If $yy<0 Then $yy=0


$hWnd = GUICreate("Clock", $width-30, $height-30, $xx,$yy)
GUISetBkColor(0xFF88FF)
GUISetStyle($WS_POPUP,$WS_EX_LAYERED, $hWnd)
_WinAPI_SetLayeredWindowAttributes($hWnd, 0xFF88FF)

GUISetOnEvent($GUI_EVENT_CLOSE, "close")

_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
_GDIPlus_GraphicsSetSmoothingMode($backbuffer, 4)

$inc = 0
AdlibEnable("_DrawClock",200)
$lgBrush = _GDIPlus_CreateLineBrushFromRect(0, 0, $width, $height, -1, -1, 0xFF7878FF, 0xFF000000, 0)
$irBrush = _GDIPlus_CreateLineBrushFromRect(0, 0, $width, $height, -1, -1, 0xFF000000, 0xFF7878FF, 0)
$nuBrush = _GDIPlus_BrushCreateSolid(0xFFFFFF22)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$nuFont = _GDIPlus_FontCreate($hFamily, 12, 1)
$nuFont2 = _GDIPlus_FontCreate($hFamily, 8, 1)

$hourBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
$minuteBrush = _GDIPlus_BrushCreateSolid(0xFFD0D0D0)
$secondPen = _GDIPlus_PenCreate(0xFFFF0000, 1)

$bitmap2 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer2 = _GDIPlus_ImageGetGraphicsContext($bitmap2)

_GDIPlus_GraphicsSetSmoothingMode($backbuffer2, 4)
;_GDIPlus_GraphicsClear($backbuffer2, 0xFFFFFFFF)

; _GDIPlus_GraphicsFillEllipse($backbuffer2, 25, 25, $width-30, $height-30, $lgBrush)
; _GDIPlus_GraphicsFillEllipse($backbuffer2, 35, 35, $width-30-20, $height-30-20, $irBrush)
; _GDIPlus_GraphicsFillEllipse($backbuffer2, 38, 38, $width-30-20-6, $height-30-20-6, $lgBrush)

_GDIPlus_GraphicsFillEllipse($backbuffer2, 0, 0, $width-30, $height-30, $lgBrush)
_GDIPlus_GraphicsFillEllipse($backbuffer2, 10, 10, $width-30-20, $height-30-20, $irBrush)
_GDIPlus_GraphicsFillEllipse($backbuffer2, 13, 13, $width-30-20-6, $height-30-20-6, $lgBrush)


$pi = 3.14159265358979
$degToRad = $pi / 180
$coeff=int(($width)/3)-4
For $i=12 to 1 step -1
$j=360/12*$i-90
If $j>=360 Then $j-=360
$x=int(Cos($j*$degToRad)*$coeff+$coeff)+16
$y=int(Sin($j*$degToRad)*$coeff+$coeff)+16
If $i>9 Then $x-=2
_DrawMyText($i, $x,$y)
Next

$tmp=GetDayOfWeek() &" "& GetMonth()&" "&@MDAY
$xdat=12-StringLen($tmp)
$xdat=$xdat*4

_DrawMyTextPetit($tmp,int($width*0.3)-16+$xdat,int($height*0.52))

GUIRegisterMsg($WM_PAINT,"MY_PAINT")
GUISetState()
Do
_WinMove("Clock")
Until Not Sleep(249)


Func MY_PAINT($hWnd,$uMsg,$lParam,$wParam)
_DrawClock()
Return $GUI_RUNDEFMSG
EndFunc


Func _DrawClock()
$diametre=100-15
$rayon=$diametre/2
_GDIPlus_GraphicsDrawImage($backbuffer,$bitmap2,0,0)
;Create angles
$secondAngle = 8.0 * ATan(1) * @SEC / 60.0
$minuteAngle = 8.0 * ATan(1) * (@MIN + @SEC / 60.0) / 60.0
$hourAngle = 8.0 * ATan(1) * (@HOUR + @MIN / 60.0) / 12.0

;Draw Hour Hand
Local $HourArrow[5][2] = [[4, 0], _
[Int(40 * Sin($hourAngle)) + $diametre, Int(-40 * Cos($hourAngle)) + $diametre], _
[Int(-5 * Cos($hourAngle)) + $diametre, Int(-5 * Sin($hourAngle)) + $diametre], _
[Int(5 * Cos($hourAngle)) + $diametre, Int(5 * Sin($hourAngle)) + $diametre], _
[Int(40 * Sin($hourAngle)) + $diametre, Int(-40 * Cos($hourAngle)) + $diametre]]

_GDIPlus_GraphicsFillPolygon($backbuffer, $HourArrow, $hourBrush)
;~ _GDIPlus_GraphicsFillEllipse($backbuffer, 115, 115, 10, 10, $hourBrush)

Local $MinuteArrow[5][2] = [[4, 0], _
[Int(70 * Sin($minuteAngle)) + $diametre, Int(-70 * Cos($minuteAngle)) + $diametre], _
[Int(-5 * Cos($minuteAngle)) + $diametre, Int(-5 * Sin($minuteAngle)) + $diametre], _
[Int(5 * Cos($minuteAngle)) + $diametre, Int(5 * Sin($minuteAngle)) + $diametre], _
[Int(70 * Sin($minuteAngle)) + $diametre, Int(-70 * Cos($minuteAngle)) + $diametre]]

_GDIPlus_GraphicsFillPolygon($backbuffer, $MinuteArrow, $minuteBrush)
;;;_GDIPlus_GraphicsFillEllipse($backbuffer, 115, 115, 10, 10, $minuteBrush)
_GDIPlus_GraphicsFillEllipse($backbuffer, $width/2-20, $width/2-20, 10, 10, $minuteBrush)

_GDIPlus_GraphicsDrawLine($backbuffer, $diametre, $diametre, Int(70 * Sin($secondAngle)) + $diametre, _
Int(-70 * Cos($secondAngle)) + $diametre, $secondPen)

_GDIPlus_GraphicsDrawImage($graphics, $bitmap, 0, 0)
EndFunc


Func _DrawMyText($text, $x, $y)
$tLayout = _GDIPlus_RectFCreate($x, $y)
$aInfo = _GDIPlus_GraphicsMeasureString($backbuffer2, $text, $nuFont, $tLayout, $hFormat)
_GDIPlus_GraphicsDrawStringEx($backbuffer2, $text, $nuFont, $aInfo[0], $hFormat, $nuBrush)
EndFunc;==>_DrawMyText

Func _DrawMyTextPetit($text, $x, $y)
$tLayout = _GDIPlus_RectFCreate($x, $y)
$aInfo = _GDIPlus_GraphicsMeasureString($backbuffer2, $text, $nuFont2, $tLayout, $hFormat)
_GDIPlus_GraphicsDrawStringEx($backbuffer2, $text, $nuFont2, $aInfo[0], $hFormat, $nuBrush)
EndFunc;==>_DrawMyText

Func close()
_GDIPlus_GraphicsDispose($backbuffer2)
_GDIPlus_BitmapDispose($bitmap2)
_GDIPlus_PenDispose($secondPen)
_GDIPlus_BrushDispose($minuteBrush)
_GDIPlus_BrushDispose($hourBrush)
_GDIPlus_FontDispose($nuFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($nuBrush)
_GDIPlus_BrushDispose($irBrush)
_GDIPlus_BrushDispose($lgBrush)
_GDIPlus_GraphicsDispose($backbuffer)
_GDIPlus_BitmapDispose($bitmap)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_Shutdown()
Exit
EndFunc;==>close

;==== GDIPlus_CreateLineBrushFromRect ===
;Description - Creates a LinearGradientBrush object from a set of boundary points and boundary colors.
; $aFactors - If non-array, default array will be used.
; Pointer to an array of real numbers that specify blend factors. Each number in the array
; specifies a percentage of the ending color and should be in the range from 0.0 through 1.0.
;$aPositions - If non-array, default array will be used.
; Pointer to an array of real numbers that specify blend factors' positions. Each number in the array
; indicates a percentage of the distance between the starting boundary and the ending boundary
; and is in the range from 0.0 through 1.0, where 0.0 indicates the starting boundary of the
; gradient and 1.0 indicates the ending boundary. There must be at least two positions
; specified: the first position, which is always 0.0, and the last position, which is always
; 1.0. Otherwise, the behavior is undefined. A blend position between 0.0 and 1.0 indicates a
; line, parallel to the boundary lines, that is a certain fraction of the distance from the
; starting boundary to the ending boundary. For example, a blend position of 0.7 indicates
; the line that is 70 percent of the distance from the starting boundary to the ending boundary.
; The color is constant on lines that are parallel to the boundary lines.
; $iArgb1 - First Top color in 0xAARRGGBB format
; $iArgb2 - Second color in 0xAARRGGBB format
; $LinearGradientMode - LinearGradientModeHorizontal = 0x00000000,
; LinearGradientModeVertical = 0x00000001,
; LinearGradientModeForwardDiagonal = 0x00000002,
; LinearGradientModeBackwardDiagonal = 0x00000003
; $WrapMode - WrapModeTile = 0,
; WrapModeTileFlipX = 1,
; WrapModeTileFlipY = 2,
; WrapModeTileFlipXY = 3,
; WrapModeClamp = 4
; GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect, ARGB color1, ARGB color2,
; LinearGradientMode mode, GpWrapMode wrapMode, GpLineGradient **lineGradient)
; Reference: [url="http://msdn.microsoft.com/en-us/library/ms534043(VS.85).aspx"]http://msdn.microsoft.com/en-us/library/ms534043(VS.85).aspx[/url]
;
Func _GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth, $iHeight, $aFactors, $aPositions, _
$iArgb1 = 0xFF0000FF, $iArgb2 = 0xFFFF0000, $LinearGradientMode = 0x00000001, $WrapMode = 0)

Local $tRect, $pRect, $aRet, $tFactors, $pFactors, $tPositions, $pPositions, $iCount

If $iArgb1 = -1 Then $iArgb1 = 0xFF0000FF
If $iArgb2 = -1 Then $iArgb2 = 0xFFFF0000
If $LinearGradientMode = -1 Then $LinearGradientMode = 0x00000001
If $WrapMode = -1 Then $WrapMode = 1

$tRect = DllStructCreate("float X;float Y;float Width;float Height")
$pRect = DllStructGetPtr($tRect)
DllStructSetData($tRect, "X", $iX)
DllStructSetData($tRect, "Y", $iY)
DllStructSetData($tRect, "Width", $iWidth)
DllStructSetData($tRect, "Height", $iHeight)

;Note: Withn _GDIPlus_Startup(), $ghGDIPDll is defined
$aRet = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushFromRect", "ptr", $pRect, "int", $iArgb1, _
"int", $iArgb2, "int", $LinearGradientMode, "int", $WrapMode, "int*", 0)

If IsArray($aFactors) = 0 Then Dim $aFactors[4] = [0.0, 0.4, 0.6, 1.0]
If IsArray($aPositions) = 0 Then Dim $aPositions[4] = [0.0, 0.3, 0.7, 1.0]

$iCount = UBound($aPositions)
$tFactors = DllStructCreate("float[" & $iCount & "]")
$pFactors = DllStructGetPtr($tFactors)
For $iI = 0 To $iCount - 1
DllStructSetData($tFactors, 1, $aFactors[$iI], $iI + 1)
Next
$tPositions = DllStructCreate("float[" & $iCount & "]")
$pPositions = DllStructGetPtr($tPositions)
For $iI = 0 To $iCount - 1
DllStructSetData($tPositions, 1, $aPositions[$iI], $iI + 1)
Next

$hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _
"ptr", $pFactors, "ptr", $pPositions, "int", $iCount)
Return $aRet[6]; Handle of Line Brush
EndFunc;==>_GDIPlus_CreateLineBrushFromRect




Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)
If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03
If Not $isColorRef Then
$i_transcolor = Hex(String($i_transcolor), 6)
$i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
EndIf
Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages)
Select
Case @error
Return SetError(@error, 0, 0)
Case $Ret[0] = 0
Return SetError(4, _WinAPI_GetLastError(), 0)
Case Else
Return 1
EndSelect
EndFunc;==>_WinAPI_SetLayeredWindowAttributes


;===============================================================================
;
; Description: Moves any Window by Left Mouse "Click & Drag"
; Syntax: _WinMove($hWnd) or _WinMove($s_Title)
; Parameter(s): $s_hWnd = as returned by GUICreate()
; $s_Title = title of window to be moved
; Requirement(s): None
; Return Value(s): On Success - Repositions the Window
; On Failure - Returns ""
; Author(s): Valuater, Valuater [at] aol [.com], Inspired by Martin
;
;===============================================================================
Func _WinMove($hWnd)
If Not WinActive($hWnd) Then Return
Local $a_R = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", '0x1')
If @error Or BitAND($a_R[0], 0x8000) <> 0x8000 Then Return
Local $a = WinGetPos($hWnd), $b = MouseGetPos()
If $b[0] < $a[0] Or $b[1] < $a[1] Or $b[0] > $a[2] + $a[0] Or $b[1] > $a[3] + $a[1] Then Return
While WinActive($hWnd)
Local $c = MouseGetPos()
WinMove($hWnd, '', $a[0] + $c[0] - $b[0], $a[1] + $c[1] - $b[1])
$a_R = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", '0x1')
If @error Or BitAND($a_R[0], 0x8000) <> 0x8000 Then Return
WEnd
EndFunc;==>_WinMove

; Author(s): WideBoyDixon
Func GetDayOfWeek()
    Return _WinAPI_GetLocaleInfo(_WinAPI_GetUserDefaultLCID(), 49 + Mod(@WDAY + 5, 7))
EndFunc  ;==>GetDayOfWeek

Func GetMonth()
    Return _WinAPI_GetLocaleInfo(_WinAPI_GetUserDefaultLCID(), 67 + @MON)
EndFunc  ;==>GetMonth

Func Getyear()
    Return StringRight(@YEAR, 2)
EndFunc  ;==>Getyear

Func _WinAPI_GetLocaleInfo($Locale, $LCType)
    Local $aResult = DllCall("kernel32.dll", "long", "GetLocaleInfo", "long", $Locale, "long", $LCType, "ptr", 0, "long", 0)
    If @error Then Return SetError(1, 0, "")
    Local $lpBuffer = DllStructCreate("char[" & $aResult[0] & "]")
    $aResult = DllCall("kernel32.dll", "long", "GetLocaleInfo", "long", $Locale, "long", $LCType, "ptr", DllStructGetPtr($lpBuffer), "long", $aResult[0])
    If @error Or ($aResult[0] = 0) Then Return SetError(1, 0, "")
    Return SetError(0, 0, DllStructGetData($lpBuffer, 1))
EndFunc

Func _WinAPI_GetUserDefaultLCID()
    Local $aResult = DllCall("kernel32.dll", "long", "GetUserDefaultLCID"); Get the default LCID for this user
    If @error Then Return SetError(1, 0, 0)
    Return SetError(0, 0, $aResult[0])
EndFunc
;=========================
Link to comment
Share on other sites

Hi, WideBoyDixon. This is a great work, I have long sat and admired it. Beautiful.

5+

One suggestion. Try to use SetBitmap() function from the examples of AutoIt (AlphaBlend.au3), prepare skins (PNG), and then ... will be just a commercial product!

:)

Edited by Yashied
Link to comment
Share on other sites

Michel; try changing this part and notice the difference

$hWnd = GUICreate("Clock", $width-30, $height-30, $xx,$yy)
GUISetBkColor(0xFF88FF)
GUISetStyle($WS_POPUP,$WS_EX_LAYERED, $hWnd)

To

$hWnd = GUICreate("Clock", $width-30, $height-30, $xx,$yy, $WS_POPUP,$WS_EX_LAYERED)
GUISetBkColor(0xFF88FF)
;GUISetStyle($WS_POPUP,$WS_EX_LAYERED, $hWnd)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hi!

WideBoyDixon:

- Sorry, I don't understand english (& I don't know write english) ; therefore, I don't understand yours month's names

- OK, you translated month's names, but you forgot to translate hours numbers (1 ... 12) ;o)

- is your clock the next Big-Ben?

GEOSoft:

You are right.

But I like my three lines, because:

- more easy to (de)/comment only one line, for testing

- it was my code, then it's (normally) better (or I become senile)

- but... Yes, we can (use your suggest)

For all:

I add the var $reverse ... :

; credits to WideBoyDixon
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#Include <Date.au3>

Opt("GUIOnEventMode", 1)
$width = 200
$height = 200
$reverse=True

$xx=-1
$yy=-1
if $CmdLine[0]>0 then
$xx=$CmdLine[1]
EndIf
if $CmdLine[0]>1 then
$yy=$CmdLine[2]
EndIf
If $xx<0 Then $xx=@DesktopWidth-$width+30
If $yy<0 Then $yy=0

Dim $mois[13]=[' ','Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre']


$hWnd = GUICreate("Clock", $width-30, $height-30, $xx,$yy,$WS_POPUP,$WS_EX_LAYERED);for GEOSoft satisfaction.
;$hWnd = GUICreate("Clock", $width-30, $height-30, $xx,$yy)
GUISetBkColor(0xFF88FF)
;GUISetStyle($WS_POPUP,$WS_EX_LAYERED, $hWnd)
_WinAPI_SetLayeredWindowAttributes($hWnd, 0xFF88FF)

GUISetOnEvent($GUI_EVENT_CLOSE, "close")

_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
_GDIPlus_GraphicsSetSmoothingMode($backbuffer, 4)

$inc = 0
AdlibEnable("_DrawClock",200)
$lgBrush = _GDIPlus_CreateLineBrushFromRect(0, 0, $width, $height, -1, -1, 0xFF7878FF, 0xFF000000, 0)
$irBrush = _GDIPlus_CreateLineBrushFromRect(0, 0, $width, $height, -1, -1, 0xFF000000, 0xFF7878FF, 0)
$nuBrush = _GDIPlus_BrushCreateSolid(0xFFFFFF22)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$nuFont = _GDIPlus_FontCreate($hFamily, 12, 1)
$nuFont2 = _GDIPlus_FontCreate($hFamily, 8, 1)

$hourBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
$minuteBrush = _GDIPlus_BrushCreateSolid(0xFFD0D0D0)
$secondPen = _GDIPlus_PenCreate(0xFFFF0000, 1)

$bitmap2 = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer2 = _GDIPlus_ImageGetGraphicsContext($bitmap2)

_GDIPlus_GraphicsSetSmoothingMode($backbuffer2, 4)
;_GDIPlus_GraphicsClear($backbuffer2, 0xFFFFFFFF)

; _GDIPlus_GraphicsFillEllipse($backbuffer2, 25, 25, $width-30, $height-30, $lgBrush)
; _GDIPlus_GraphicsFillEllipse($backbuffer2, 35, 35, $width-30-20, $height-30-20, $irBrush)
; _GDIPlus_GraphicsFillEllipse($backbuffer2, 38, 38, $width-30-20-6, $height-30-20-6, $lgBrush)

_GDIPlus_GraphicsFillEllipse($backbuffer2, 0, 0, $width-30, $height-30, $lgBrush)
_GDIPlus_GraphicsFillEllipse($backbuffer2, 10, 10, $width-30-20, $height-30-20, $irBrush)
_GDIPlus_GraphicsFillEllipse($backbuffer2, 13, 13, $width-30-20-6, $height-30-20-6, $lgBrush)


$pi = 3.14159265358979
$degToRad = $pi / 180
$coeff=int(($width)/3)-4
For $i=1 to 12 
If $reverse Then
$j=360-360/12*$i-90
Else
$j=360/12*$i-90
EndIf
If $j>=360 Then $j-=360
$x=int(Cos($j*$degToRad)*$coeff+$coeff)+16
$y=int(Sin($j*$degToRad)*$coeff+$coeff)+16
If $i>9 Then $x-=4
_DrawMyText($i, $x,$y)
Next


$tmp=@MDAY &" "& $mois[int(@MON)]
$xdat=12-StringLen($tmp)
$xdat=$xdat*4

_DrawMyTextPetit($tmp,int($width*0.3)-16+$xdat,int($height*0.52))

GUIRegisterMsg($WM_PAINT,"MY_PAINT")
GUISetState()
Do
_WinMove("Clock")
Until Not Sleep(249)


Func MY_PAINT($hWnd,$uMsg,$lParam,$wParam)
_DrawClock()
Return $GUI_RUNDEFMSG
EndFunc


Func _DrawClock()
$diametre=100-15
$rayon=$diametre/2
_GDIPlus_GraphicsDrawImage($backbuffer,$bitmap2,0,0)
;Create angles
If $reverse Then
$secondAngle = 8.0 * ATan(1) * (60-@SEC)/60.0
$minuteAngle = 8.0 * ATan(1) * ((60-@MIN) - @SEC/60.0) / 60.0
$hourAngle = 8.0 * ATan(1) * ((12-@HOUR) - (@MIN)/60.0) / 12.0
Else
$secondAngle = 8.0 * ATan(1) * @SEC / 60.0
$minuteAngle = 8.0 * ATan(1) * (@MIN + @SEC / 60.0) / 60.0
$hourAngle = 8.0 * ATan(1) * (@HOUR + @MIN / 60.0) / 12.0
EndIf

;Draw Hour Hand
Local $HourArrow[5][2] = [[4, 0], _
[Int(40 * Sin($hourAngle)) + $diametre, Int(-40 * Cos($hourAngle)) + $diametre], _
[Int(-5 * Cos($hourAngle)) + $diametre, Int(-5 * Sin($hourAngle)) + $diametre], _
[Int(5 * Cos($hourAngle)) + $diametre, Int(5 * Sin($hourAngle)) + $diametre], _
[Int(40 * Sin($hourAngle)) + $diametre, Int(-40 * Cos($hourAngle)) + $diametre]]

_GDIPlus_GraphicsFillPolygon($backbuffer, $HourArrow, $hourBrush)
;~ _GDIPlus_GraphicsFillEllipse($backbuffer, 115, 115, 10, 10, $hourBrush)

Local $MinuteArrow[5][2] = [[4, 0], _
[Int(70 * Sin($minuteAngle)) + $diametre, Int(-70 * Cos($minuteAngle)) + $diametre], _
[Int(-5 * Cos($minuteAngle)) + $diametre, Int(-5 * Sin($minuteAngle)) + $diametre], _
[Int(5 * Cos($minuteAngle)) + $diametre, Int(5 * Sin($minuteAngle)) + $diametre], _
[Int(70 * Sin($minuteAngle)) + $diametre, Int(-70 * Cos($minuteAngle)) + $diametre]]

_GDIPlus_GraphicsFillPolygon($backbuffer, $MinuteArrow, $minuteBrush)
;;;_GDIPlus_GraphicsFillEllipse($backbuffer, 115, 115, 10, 10, $minuteBrush)
_GDIPlus_GraphicsFillEllipse($backbuffer, $width/2-20, $width/2-20, 10, 10, $minuteBrush)

_GDIPlus_GraphicsDrawLine($backbuffer, $diametre, $diametre, Int(70 * Sin($secondAngle)) + $diametre, _
Int(-70 * Cos($secondAngle)) + $diametre, $secondPen)

_GDIPlus_GraphicsDrawImage($graphics, $bitmap, 0, 0)
EndFunc


Func _DrawMyText($text, $x, $y)
$tLayout = _GDIPlus_RectFCreate($x, $y)
$aInfo = _GDIPlus_GraphicsMeasureString($backbuffer2, $text, $nuFont, $tLayout, $hFormat)
_GDIPlus_GraphicsDrawStringEx($backbuffer2, $text, $nuFont, $aInfo[0], $hFormat, $nuBrush)
EndFunc;==>_DrawMyText

Func _DrawMyTextPetit($text, $x, $y)
$tLayout = _GDIPlus_RectFCreate($x, $y)
$aInfo = _GDIPlus_GraphicsMeasureString($backbuffer2, $text, $nuFont2, $tLayout, $hFormat)
_GDIPlus_GraphicsDrawStringEx($backbuffer2, $text, $nuFont2, $aInfo[0], $hFormat, $nuBrush)
EndFunc;==>_DrawMyText

Func close()
_GDIPlus_GraphicsDispose($backbuffer2)
_GDIPlus_BitmapDispose($bitmap2)
_GDIPlus_PenDispose($secondPen)
_GDIPlus_BrushDispose($minuteBrush)
_GDIPlus_BrushDispose($hourBrush)
_GDIPlus_FontDispose($nuFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($nuBrush)
_GDIPlus_BrushDispose($irBrush)
_GDIPlus_BrushDispose($lgBrush)
_GDIPlus_GraphicsDispose($backbuffer)
_GDIPlus_BitmapDispose($bitmap)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_Shutdown()
Exit
EndFunc;==>close

;==== GDIPlus_CreateLineBrushFromRect ===
;Description - Creates a LinearGradientBrush object from a set of boundary points and boundary colors.
; $aFactors - If non-array, default array will be used.
; Pointer to an array of real numbers that specify blend factors. Each number in the array
; specifies a percentage of the ending color and should be in the range from 0.0 through 1.0.
;$aPositions - If non-array, default array will be used.
; Pointer to an array of real numbers that specify blend factors' positions. Each number in the array
; indicates a percentage of the distance between the starting boundary and the ending boundary
; and is in the range from 0.0 through 1.0, where 0.0 indicates the starting boundary of the
; gradient and 1.0 indicates the ending boundary. There must be at least two positions
; specified: the first position, which is always 0.0, and the last position, which is always
; 1.0. Otherwise, the behavior is undefined. A blend position between 0.0 and 1.0 indicates a
; line, parallel to the boundary lines, that is a certain fraction of the distance from the
; starting boundary to the ending boundary. For example, a blend position of 0.7 indicates
; the line that is 70 percent of the distance from the starting boundary to the ending boundary.
; The color is constant on lines that are parallel to the boundary lines.
; $iArgb1 - First Top color in 0xAARRGGBB format
; $iArgb2 - Second color in 0xAARRGGBB format
; $LinearGradientMode - LinearGradientModeHorizontal = 0x00000000,
; LinearGradientModeVertical = 0x00000001,
; LinearGradientModeForwardDiagonal = 0x00000002,
; LinearGradientModeBackwardDiagonal = 0x00000003
; $WrapMode - WrapModeTile = 0,
; WrapModeTileFlipX = 1,
; WrapModeTileFlipY = 2,
; WrapModeTileFlipXY = 3,
; WrapModeClamp = 4
; GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect, ARGB color1, ARGB color2,
; LinearGradientMode mode, GpWrapMode wrapMode, GpLineGradient **lineGradient)
; Reference: [url="http://msdn.microsoft.com/en-us/library/ms534043(VS.85).aspx"]http://msdn.microsoft.com/en-us/library/ms534043(VS.85).aspx[/url]
;
Func _GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth, $iHeight, $aFactors, $aPositions, _
$iArgb1 = 0xFF0000FF, $iArgb2 = 0xFFFF0000, $LinearGradientMode = 0x00000001, $WrapMode = 0)

Local $tRect, $pRect, $aRet, $tFactors, $pFactors, $tPositions, $pPositions, $iCount

If $iArgb1 = -1 Then $iArgb1 = 0xFF0000FF
If $iArgb2 = -1 Then $iArgb2 = 0xFFFF0000
If $LinearGradientMode = -1 Then $LinearGradientMode = 0x00000001
If $WrapMode = -1 Then $WrapMode = 1

$tRect = DllStructCreate("float X;float Y;float Width;float Height")
$pRect = DllStructGetPtr($tRect)
DllStructSetData($tRect, "X", $iX)
DllStructSetData($tRect, "Y", $iY)
DllStructSetData($tRect, "Width", $iWidth)
DllStructSetData($tRect, "Height", $iHeight)

;Note: Withn _GDIPlus_Startup(), $ghGDIPDll is defined
$aRet = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushFromRect", "ptr", $pRect, "int", $iArgb1, _
"int", $iArgb2, "int", $LinearGradientMode, "int", $WrapMode, "int*", 0)

If IsArray($aFactors) = 0 Then Dim $aFactors[4] = [0.0, 0.4, 0.6, 1.0]
If IsArray($aPositions) = 0 Then Dim $aPositions[4] = [0.0, 0.3, 0.7, 1.0]

$iCount = UBound($aPositions)
$tFactors = DllStructCreate("float[" & $iCount & "]")
$pFactors = DllStructGetPtr($tFactors)
For $iI = 0 To $iCount - 1
DllStructSetData($tFactors, 1, $aFactors[$iI], $iI + 1)
Next
$tPositions = DllStructCreate("float[" & $iCount & "]")
$pPositions = DllStructGetPtr($tPositions)
For $iI = 0 To $iCount - 1
DllStructSetData($tPositions, 1, $aPositions[$iI], $iI + 1)
Next

$hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _
"ptr", $pFactors, "ptr", $pPositions, "int", $iCount)
Return $aRet[6]; Handle of Line Brush
EndFunc;==>_GDIPlus_CreateLineBrushFromRect




Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)
If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03
If Not $isColorRef Then
$i_transcolor = Hex(String($i_transcolor), 6)
$i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
EndIf
Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages)
Select
Case @error
Return SetError(@error, 0, 0)
Case $Ret[0] = 0
Return SetError(4, _WinAPI_GetLastError(), 0)
Case Else
Return 1
EndSelect
EndFunc;==>_WinAPI_SetLayeredWindowAttributes


;===============================================================================
;
; Description: Moves any Window by Left Mouse "Click & Drag"
; Syntax: _WinMove($hWnd) or _WinMove($s_Title)
; Parameter(s): $s_hWnd = as returned by GUICreate()
; $s_Title = title of window to be moved
; Requirement(s): None
; Return Value(s): On Success - Repositions the Window
; On Failure - Returns ""
; Author(s): Valuater, Valuater [at] aol [.com], Inspired by Martin
;
;===============================================================================
Func _WinMove($hWnd)
If Not WinActive($hWnd) Then Return
Local $a_R = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", '0x1')
If @error Or BitAND($a_R[0], 0x8000) <> 0x8000 Then Return
Local $a = WinGetPos($hWnd), $b = MouseGetPos()
If $b[0] < $a[0] Or $b[1] < $a[1] Or $b[0] > $a[2] + $a[0] Or $b[1] > $a[3] + $a[1] Then Return
While WinActive($hWnd)
Local $c = MouseGetPos()
WinMove($hWnd, '', $a[0] + $c[0] - $b[0], $a[1] + $c[1] - $b[1])
$a_R = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", '0x1')
If @error Or BitAND($a_R[0], 0x8000) <> 0x8000 Then Return
WEnd
EndFunc;==>_WinMove
Edited by Michel Claveau
Link to comment
Share on other sites

The only reason for the change was to get rid of the title bar that displayed. You can't always depend on setting the style properly with GUISetStyle() The surest method is to set it when the GUI is created.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I confess that some of the GDI+ that's been introduced in to this thread is a bit beyond me right now. I need to take some time to understand what various people have done. Once I've understood in more detail I would like to be able to do the following:

[1] Make the clock resizable (this *might* include an elliptical clock)

[2] Provide a context menu

[3] Make the colours configurable

[4] Allow an alarm to be set

[5] Allow the clock to be always on top

Yes the script is becoming huge. I only started this in order to teach myself some GDI+ but now it's almost becoming a proper application! However, I don't have a great reputation as a "finisher" so it might just end up kicking around for a while :)

WBD

Link to comment
Share on other sites

Half the things on your list can be done with knowledge og GUI's, On top etc is quite simple to do, and I'm sure you know about that... as for context menu's, see my first reply. Alarms can be done with something similar to Lurchmans script, colours should be easy too, especially if you make irt so a restart is necessary to apply (Ini functions). Overall, I am fairly sure you could break your reputaion and finish this! I know it probably won't be as efficient as a program like clocx, but it should be good!

MDiesel

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...