Sign in to follow this  
Followers 0
Malkey

World Clock GDI+GUI's

15 posts in this topic

#1 ·  Posted (edited)

Reposted :

In the playing of learning about the Simple Clock example (...\AutoIt3\Examples\GUI\Advanced\Clock.au3), this clock came about.

With this example, the clock can be moved by dragging the dots on the dial and the black dot at center has a context menu (right click to view).

The individual parts can be dragged if the Lock Pieces Position is not checked.

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <GuiConstantsEx.au3>
#include <Date.au3>
#include <Windowsconstants.au3>
#include <Misc.au3>
#include <Constants.au3>

; =============================================================================================
; Description ...: Modified Simple Clock using layered windows into World Clock
; =============================================================================================

Global Const $iDotOpacity   = 250
Global Const $iFaceOpacity   = 80
Global Const $iOpacity      = 128
Global Const $iTickLen      = 0.02
Global Const $AC_SRC_ALPHA   = 1
;Global Const $ULW_ALPHA    = 2
Global Const $nPI           = 3.1415926535897932384626433832795
;Global Const $WM_LBUTTONDOWN = 0x0201  ; Drag Window 1 of 3 addin

Global $scale   = 0.4                   ;0.3  to 1.5
Global $iHourRad = Int(140*$scale)
Global  $iMinRad = Int(200*$scale)
Global  $iRadius = Int(200*$scale)
Global  $iSecRad = Int(200*$scale)
Global $guislock  = 1
Global $iCenter   = Int(200*$scale)
Global Enum $eScrDC=0, $eMemDC, $eBitmap, $eWidth, $eHeight, $eGraphic, $ePen, $eCap, $eBrush, $eFormat, $eFamily, $eFont, $eLayout, $eLast
Global $hDial, $hFace, $hTime, $hHour, $hMin, $hSec, $hDot,$aTime, $aHour, $aMin, $aSec, $aCurr[3][2], $aLast[3][2], $btime, $nMsg
Global  $user32_dll = DllOpen ("user32.dll"), $Msg,$x = 420,$y = 50 ,$hrdiff = 0, $mindiff = 0,$locname = " UTC Time"

Global $ContextMenu, $MenuItemMoveClock, $MenuItemExit,$iRet,$MenuItemreassClock,$viewitemface,$lockpositem,$separator1

Global $scaleb2     = 0.4                   ;0.3  to 1.5
Global $iHourRadb2  = Int(140*$scaleb2)
Global  $iMinRadb2  = Int(200*$scaleb2)
Global  $iRadiusb2  = Int(200*$scaleb2)
Global  $iSecRadb2  = Int(200*$scaleb2)
Global $guislock    = 1
Global $iCenterb2   = Int(200*$scaleb2)
Global $hDialb2, $hFaceb2, $hTimeb2, $hHourb2, $hMinb2, $hSecb2, $hDotb2,$aTimeb2, $aHourb2, $aMinb2, $aSecb2, $aCurrb2[3][2], $aLastb2[3][2], $btimeb2
Global $xb2 = 620,$yb2 = 50 ,$hrdiffb2 =10, $mindiffb2 = 0,$locnameb2 = " A place to be time zone."
Global $ContextMenub2, $MenuItemMoveClockb2, $MenuItemExitb2,$MenuItemreassClockb2,$viewitemfaceb2,$viewitemshowclockb2

Opt ("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)
w1clock()

Func w1clock( )
    ClockInit()
    FaceDraw ()
    DialDraw ()
    Draw    ()
    DotDraw  ()
    ClockInitb2()
    FaceDrawb2 ()
    DialDrawb2 ()
    Drawb2  ()
    DotDrawb2  ()
    ClockLoop()
    ClockDone()
EndFunc

; ==================================================================================
; Finalize clock
; ==================================================================================
Func ClockDone()
  ; Finalize GDI+ resources
  TimeDone()
  HourDone()
  MinDone ()
  SecDone ()
  TimeDoneb2()
  HourDoneb2()
  MinDoneb2 ()
  SecDoneb2 ()
  ; Finalize GDI+ library
  _GDIPlus_Shutdown()
EndFunc

; ==================================================================================
; Initialize clock
; ==================================================================================
Func ClockInit()
    Local $iX, $iY, $viewitemclock,$MenuItemTimediff
    ; Calculate the dial frame caption size
    $iX =   -(_WinAPI_GetSystemMetrics($SM_CXFRAME))        ; -4
    $iY =   -(_WinAPI_GetSystemMetrics($SM_CYCAPTION) + _WinAPI_GetSystemMetrics($SM_CYFRAME))  ; -23
    ; Allocate the window resources
    $hDial = GUICreate("Clock", $iRadius * 2, $iRadius * 2, $x,  $y, 0, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST,$WS_EX_ACCEPTFILES))
        GUISetCursor (9, 1, $hDial)
        GuiRegisterMsg($WM_LBUTTONDOWN, "_WinMove") ; Drag Window 2 of 3 addin
        GUISetState()
    $hFace = GUICreate("Face", $iRadius * 1.9, $iRadius * 1.9, $iX, $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDial)
        GUISetState()
    $hTime = GUICreate("Time" , $iRadius * 2, $iRadius * 2, $iX, $iY+$iRadius*1.4, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDial)
        GUISetState()
    $hHour = GUICreate("Hour" , $iRadius * 2, $iRadius * 2, $iX , $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDial)
        GUISetState()
    $hMin  = GUICreate("Min"  , $iRadius * 2, $iRadius * 2, $iX, $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDial)
        GUISetState()
    $hSec  = GUICreate("Sec"  , $iRadius * 2, $iRadius * 2, $iX, $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDial)
        GUISetState()
    $hDot  = GUICreate("Dot"  , $iRadius * 2, $iRadius * 2, $iX, $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDial)
    $ContextMenu = GUICtrlCreateContextMenu ()
    $MenuItemMoveClock = GUICtrlCreateMenuitem ("Disassemble Clock", $ContextMenu, 0)
        GUICtrlSetOnEvent ($MenuItemMoveClock, "DissambleClock")
    $MenuItemreassClock = GUICtrlCreateMenuitem ("Re-assemble Clock", $ContextMenu, 1)
        GUICtrlSetOnEvent ($MenuItemreassClock, "reassembClock")
    $viewitemface = GUICtrlCreateMenuitem ("View Face",$ContextMenu,2)
        GUICtrlSetState($viewitemface,$GUI_CHECKED)
        GUICtrlSetOnEvent ($viewitemface, "viewface")
    $lockpositem = GUICtrlCreateMenuitem ("Lock Pieces Positions",$ContextMenu,3)
        GUICtrlSetState($lockpositem,$GUI_UNCHECKED)
        GUICtrlSetOnEvent ($lockpositem, "LockPos")
    $MenuItemMoveClock = GUICtrlCreateMenuitem ("Resize", $ContextMenu, 4)
        GUICtrlSetOnEvent ($MenuItemMoveClock, "resizeClock")
    $MenuItemTimediff = GUICtrlCreateMenuitem ("Set Time Difference", $ContextMenu, 5)
        GUICtrlSetOnEvent ($MenuItemTimediff, "TimeDiffConfig")
    $viewitemshowclockb2 = GUICtrlCreateMenuitem ("Show Other Clock",$ContextMenu,6)
        GUICtrlSetState($viewitemshowclockb2,$GUI_CHECKED)
        GUICtrlSetOnEvent ($viewitemshowclockb2, "Showclockb2")
    $separator1 = GUICtrlCreateMenuitem ("",$ContextMenu,7) ; create a separator line
    $MenuItemExit = GUICtrlCreateMenuitem ("Exit", $ContextMenu, 8)
        GUICtrlSetOnEvent ($MenuItemExit, "quitclk")
    GUISetState()
    $iRet = DllCall("User32.dll", "int", "SetWindowPos", "Hwnd", $hDial, "Hwnd", $hFace, _
        "int", 100, "int", 100, "int", 100, "int", 100, "uint", $SWP_NOSIZE + $SWP_NOMOVE)
  ; Initialize GDI+ library
    _GDIPlus_Startup()
  ; Initialize GDI+ resources
  TimeInit()
  HourInit()
  MinInit ()
  SecInit ()
  ; Hook non client hit test message so we can move the clock
  GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
EndFunc

; ==================================================================================
; Initialize clockb2
; ==================================================================================
Func ClockInitb2()
    Local $iX, $iY
    Local $viewitemclockb2,$MenuItemTimediffb2
    ; Calculate the dial frame caption size
    $iX =   -(_WinAPI_GetSystemMetrics($SM_CXFRAME))        ; -4
    $iY =   -(_WinAPI_GetSystemMetrics($SM_CYCAPTION) + _WinAPI_GetSystemMetrics($SM_CYFRAME))  ; -23
    ; Allocate the window resources
    $hDialb2 = GUICreate("Clockb2", $iRadiusb2 * 2, $iRadiusb2 * 2, $xb2,  $yb2, 0, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST,$WS_EX_ACCEPTFILES))
    GUISetCursor (9, 1, $hDialb2)
        GuiRegisterMsg($WM_LBUTTONDOWN, "_WinMove") ; Drag Window 2 of 3 addin
        GUISetState()
    $hFaceb2 = GUICreate("Faceb2", $iRadiusb2 * 1.9, $iRadiusb2 * 1.9, $iX, $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDialb2)
        GUISetState()
    $hTimeb2 = GUICreate("Timeb2" , $iRadiusb2 * 2, $iRadiusb2 * 2, $iX, $iY+$iRadiusb2*1.4, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDialb2)
        GUISetState()
    $hHourb2 = GUICreate("Hourb2" , $iRadiusb2 * 2, $iRadiusb2 * 2, $iX , $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDialb2)
        GUISetState()
    $hMinb2  = GUICreate("Minb2"  , $iRadiusb2 * 2, $iRadiusb2 * 2, $iX, $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDialb2)
        GUISetState()
    $hSecb2  = GUICreate("Secb2"  , $iRadiusb2 * 2, $iRadiusb2 * 2, $iX, $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDialb2)
        GUISetState()
    $hDotb2  = GUICreate("Dotb2"  , $iRadiusb2 * 2, $iRadiusb2 * 2, $iX, $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDialb2)

    $ContextMenub2 = GUICtrlCreateContextMenu ()
    $MenuItemMoveClockb2 = GUICtrlCreateMenuitem ("Disassemble Clock", $ContextMenub2, 0)
        GUICtrlSetOnEvent ($MenuItemMoveClockb2, "DissambleClockb2")
    $MenuItemreassClockb2 = GUICtrlCreateMenuitem ("Re-assemble Clock", $ContextMenub2, 1)
        GUICtrlSetOnEvent ($MenuItemreassClockb2, "reassembClockb2")
    $viewitemfaceb2 = GUICtrlCreateMenuitem ("View Face",$ContextMenub2,2)
        GUICtrlSetState($viewitemfaceb2,$GUI_CHECKED)
        GUICtrlSetOnEvent ($viewitemfaceb2, "viewfaceb2")
    $MenuItemMoveClockb2 = GUICtrlCreateMenuitem ("Resize", $ContextMenub2, 3)
        GUICtrlSetOnEvent ($MenuItemMoveClockb2, "resizeClockb2")
    $MenuItemTimediffb2 = GUICtrlCreateMenuitem ("Set Time Difference", $ContextMenub2, 4)
        GUICtrlSetOnEvent ($MenuItemTimediffb2, "TimeDiffConfigb2")
    $separator1 = GUICtrlCreateMenuitem ("",$ContextMenub2,5)   ; create a separator line
    $MenuItemExitb2 = GUICtrlCreateMenuitem ("Exit", $ContextMenub2, 6)
        GUICtrlSetOnEvent ($MenuItemExitb2, "quitclk")
    GUISetState()
    $iRet = DllCall("User32.dll", "int", "SetWindowPos", "Hwnd", $hDialb2, "Hwnd", $hFaceb2, _
        "int", 100, "int", 100, "int", 100, "int", 100, "uint", $SWP_NOSIZE + $SWP_NOMOVE)
  ; Initialize GDI+ library
    _GDIPlus_Startup()
  ; Initialize GDI+ resources
  TimeInitb2()
  HourInitb2()
  MinInitb2 ()
  SecInitb2 ()
  ; Hook non client hit test message so we can move the clock
  GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
EndFunc

; ===================================================================================
; Loop until user exits
; ===================================================================================
Func ClockLoop()
    $Msg = GUIGetMsg()
    Do
        Draw   ()
        Drawb2 ()
        sleep(250)
    until $Msg = $GUI_EVENT_CLOSE
EndFunc

; ==================================================================================
; Draw the center dot
; ==================================================================================
Func FaceDraw ()
    Local $aFace
    Local $aDot

    $aFace = ResourceInit($iRadius * 2, $iRadius * 2)
    $aFace[$eBrush] = _GDIPlus_BrushCreateSolid (0xFFE0FFFF)
    _GDIPlus_GraphicsFillEllipse($aFace[$eGraphic], ($iRadius*.09*cos(45*$nPI/180)) , ($iRadius*.09*Sin(45*$nPI/180)) ,$iRadius*1.9 , $iRadius*1.9,  $aFace[$eBrush])
   ResourceSet ($hFace, $aFace, $iFaceOpacity)
    ResourceDone($aFace)
EndFunc

; ================================================================================
; Draw the center dot
; ================================================================================
Func FaceDrawb2 ()
    Local $aFace
    Local $aDot
    $aFace = ResourceInit($iRadiusb2 * 2, $iRadiusb2 * 2)
    $aFace[$eBrush] = _GDIPlus_BrushCreateSolid (0xFFE0FFFF)
    _GDIPlus_GraphicsFillEllipse($aFace[$eGraphic], ($iRadiusb2*.09*cos(45*$nPI/180)) , ($iRadiusb2*.09*Sin(45*$nPI/180)) ,$iRadiusb2*1.9 , $iRadiusb2*1.9,  $aFace[$eBrush])
   ResourceSet ($hFaceb2, $aFace, $iFaceOpacity)
    ResourceDone($aFace)
EndFunc

; ==============================================================================
; Draw the center dot
; ==============================================================================
Func DotDraw()
  Local $aDot

  $aDot = ResourceInit($iRadius * 2, $iRadius * 2)
  $aDot[$eBrush] = _GDIPlus_BrushCreateSolid (0xFF000000)
  _GDIPlus_GraphicsFillEllipse($aDot[$eGraphic], $iRadius-10, $iRadius-10, 20, 20, $aDot[$eBrush])
  ResourceSet ($hDot, $aDot, $iDotOpacity)
  ResourceDone($aDot)
EndFunc

; ==============================================================================
; Draw the center dotColckb2
; ==============================================================================
Func DotDrawb2()
  Local $aDot

  $aDot = ResourceInit($iRadiusb2 * 2, $iRadiusb2 * 2)
  $aDot[$eBrush] = _GDIPlus_BrushCreateSolid (0xFF000000)
  _GDIPlus_GraphicsFillEllipse($aDot[$eGraphic], $iRadiusb2-10, $iRadiusb2-10, 20, 20, $aDot[$eBrush])
  ResourceSet ($hDotb2, $aDot, $iDotOpacity)
  ResourceDone($aDot)
EndFunc

; =============================================================================
; Draw the Clock elements
; =============================================================================
Func Draw ()
  ; Calculate current time element position
  $bTime = ModifyUTCTimeToArray($hrdiff, $mindiff)
  $aLast = $aCurr
  $aCurr[0][0] = $iCenter + Cos(TimeToRadians("sec", $bTime[7], $bTime[9])) * $iSecRad
  $aCurr[0][1] = $iCenter - Sin(TimeToRadians("sec", $bTime[7], $bTime[9] )) * $iSecRad
  $aCurr[1][0] = $iCenter + Cos(TimeToRadians("min", $bTime[7], $bTime[9] )) * $iMinRad
  $aCurr[1][1] = $iCenter - Sin(TimeToRadians("min", $bTime[7], $bTime[9] )) * $iMinRad
  $aCurr[2][0] = $iCenter + Cos(TimeToRadians("hour", $bTime[7], $bTime[9])) * $iHourRad
  $aCurr[2][1] = $iCenter - Sin(TimeToRadians("hour", $bTime[7], $bTime[9])) * $iHourRad
  TimeDraw($bTime[7], $bTime[9], $bTime[6], $bTime[4],$bTime[3],  StringTrimLeft( $bTime[0],2) )
  HourDraw()
  MinDraw ()
  SecDraw ()
EndFunc

; ==============================================================================
; Draw the clockb2 elements
; ==============================================================================
Func Drawb2 ()
  ; Calculate current time element position
  $bTimeb2 = ModifyUTCTimeToArray($hrdiffb2, $mindiffb2)
  $aLastb2 = $aCurrb2
  $aCurrb2[0][0] = $iCenterb2 + Cos(TimeToRadians("sec", $bTimeb2[7], $bTimeb2[9])) * $iSecRadb2
  $aCurrb2[0][1] = $iCenterb2 - Sin(TimeToRadians("sec", $bTimeb2[7], $bTimeb2[9] )) * $iSecRadb2
  $aCurrb2[1][0] = $iCenterb2 + Cos(TimeToRadians("min", $bTimeb2[7], $bTimeb2[9] )) * $iMinRadb2
  $aCurrb2[1][1] = $iCenterb2 - Sin(TimeToRadians("min", $bTimeb2[7], $bTimeb2[9] )) * $iMinRadb2
  $aCurrb2[2][0] = $iCenterb2 + Cos(TimeToRadians("hour", $bTimeb2[7], $bTimeb2[9])) * $iHourRadb2
  $aCurrb2[2][1] = $iCenterb2 - Sin(TimeToRadians("hour", $bTimeb2[7], $bTimeb2[9])) * $iHourRadb2
  TimeDrawb2($bTimeb2[7], $bTimeb2[9], $bTimeb2[6], $bTimeb2[4],$bTimeb2[3], StringTrimLeft( $bTimeb2[0],2) )
  HourDrawb2()
  MinDrawb2 ()
  SecDrawb2 ()
EndFunc

; ===============================================================================
; Draw the Clock dial
; ===============================================================================
Func DialDraw()
  Local $aDial, $hPen1, $hPen2, $iI, $iN, $iX1, $iY1, $iX2, $iY2
  $aDial = ResourceInit($iRadius * 2, $iRadius * 2)
  $hPen1 = _GDIPlus_PenCreate()
  $hPen2 = _GDIPlus_PenCreate(0xFFFF8000, 4)
  for $iI = 0 to 2 * $nPI Step $nPI / 30
    $iX1 = $iCenter + Cos($iI) * ($iRadius * (1.00 - $iTickLen))
    $iY1 = $iCenter - Sin($iI) * ($iRadius * (1.00 - $iTickLen))
    $iX2 = $iCenter + Cos($iI) * $iRadius
    $iY2 = $iCenter - Sin($iI) * $iRadius
    if Mod($iN, 5) = 0 then
    _GDIPlus_GraphicsDrawLine($aDial[$eGraphic], $iX1, $iY1, $iX2, $iY2, $hPen2)
    else
    _GDIPlus_GraphicsDrawLine($aDial[$eGraphic], $iX1, $iY1, $iX2, $iY2, $hPen1)
    endif
    $iN += 1
  next
  _GDIPlus_PenDispose($hPen2)
  _GDIPlus_PenDispose($hPen1)
  ResourceSet ($hDial, $aDial)
  ResourceDone($aDial)
EndFunc

; ============================================================================
; Draw the clockb2 dial
; ============================================================================
Func DialDrawb2()
  Local $aDial, $hPen1, $hPen2, $iI, $iN, $iX1, $iY1, $iX2, $iY2
  $aDial = ResourceInit($iRadiusb2 * 2, $iRadiusb2 * 2)
  $hPen1 = _GDIPlus_PenCreate()
  $hPen2 = _GDIPlus_PenCreate(0xFFFF8000, 4)
  for $iI = 0 to 2 * $nPI Step $nPI / 30
    $iX1 = $iCenterb2 + Cos($iI) * ($iRadiusb2 * (1.00 - $iTickLen))
    $iY1 = $iCenterb2 - Sin($iI) * ($iRadiusb2 * (1.00 - $iTickLen))
    $iX2 = $iCenterb2 + Cos($iI) * $iRadiusb2
    $iY2 = $iCenterb2 - Sin($iI) * $iRadiusb2
    if Mod($iN, 5) = 0 then
    _GDIPlus_GraphicsDrawLine($aDial[$eGraphic], $iX1, $iY1, $iX2, $iY2, $hPen2)
    else
    _GDIPlus_GraphicsDrawLine($aDial[$eGraphic], $iX1, $iY1, $iX2, $iY2, $hPen1)
    endif
    $iN += 1
  next
  _GDIPlus_PenDispose($hPen2)
  _GDIPlus_PenDispose($hPen1)
  ResourceSet ($hDialb2, $aDial)
  ResourceDone($aDial)
EndFunc

; ===========================================================================
; Finalize resources for the hour hand
; ===========================================================================
Func HourDone()
  _GDIPlus_PenDispose($aHour[$ePen])
  _GDIPlus_ArrowCapDispose($aHour[$eCap])
  ResourceDone($aHour)
EndFunc

; ==========================================================================
; Draw the hour hand
; ==========================================================================
Func HourDraw()
  if ($aLast[2][0] = $aCurr[2][0]) and ($aLast[2][1] = $aCurr[2][1]) then Return
  _GDIPlus_GraphicsDrawLine($aHour[$eGraphic], $iCenter, $iCenter, $aCurr[2][0], $aCurr[2][1], $aHour[$ePen])
  ResourceSet($hHour, $aHour)
EndFunc

; ===========================================================================
; Initialize resources for the hour hand
; ===========================================================================
Func HourInit()
  $aHour = ResourceInit($iRadius * 2, $iRadius * 2)
  $aHour[$ePen] = _GDIPlus_PenCreate(0xFFFF00FF)
  $aHour[$eCap] = _GDIPlus_ArrowCapCreate($iHourRad / 2, 8)
  _GDIPlus_PenSetCustomEndCap($aHour[$ePen], $aHour[$eCap])
EndFunc

; ============================================================================
; Finalize resources for the hour hand clockb2
; ============================================================================
Func HourDoneb2()
  _GDIPlus_PenDispose($aHourb2[$ePen])
  _GDIPlus_ArrowCapDispose($aHourb2[$eCap])
  ResourceDone($aHourb2)
EndFunc

; =============================================================================
; Draw the hour hand clockb2
; =============================================================================
Func HourDrawb2()
  if ($aLastb2[2][0] = $aCurrb2[2][0]) and ($aLastb2[2][1] = $aCurrb2[2][1]) then Return
  _GDIPlus_GraphicsDrawLine($aHourb2[$eGraphic], $iCenterb2, $iCenterb2, $aCurrb2[2][0], $aCurrb2[2][1], $aHourb2[$ePen])
  ResourceSet($hHourb2, $aHourb2)
EndFunc

; ============================================================================
; Initialize resources for the hour hand clockb2
; =============================================================================
Func HourInitb2()
  $aHourb2 = ResourceInit($iRadiusb2 * 2, $iRadiusb2 * 2)
  $aHourb2[$ePen] = _GDIPlus_PenCreate(0xFFFF00FF)
  $aHourb2[$eCap] = _GDIPlus_ArrowCapCreate($iHourRadb2 / 2, 8)
  _GDIPlus_PenSetCustomEndCap($aHourb2[$ePen], $aHourb2[$eCap])
EndFunc

; ==============================================================================
; Finalize resources for the minute hand
; ==============================================================================
Func MinDone()
  _GDIPlus_PenDispose($aMin[$ePen])
  _GDIPlus_ArrowCapDispose($aMin[$eCap])
  ResourceDone($aMin)
EndFunc

; ==============================================================================
; Draw the minute hand
; ==============================================================================
Func MinDraw()
  if ($aLast[1][0] = $aCurr[1][0]) and ($aLast[1][1] = $aCurr[1][1]) then Return
  _GDIPlus_GraphicsFillRect($aMin[$eGraphic], 0, 0, $iRadius * 2, $iRadius * 2)
  _GDIPlus_GraphicsDrawLine($aMin[$eGraphic], $iCenter, $iCenter, $aCurr[1][0], $aCurr[1][1], $aMin[$ePen])
  ResourceSet($hMin, $aMin)
EndFunc

; ============================================================================
; Initialize resources for the minute hand
; ============================================================================
Func MinInit()
  $aMin = ResourceInit($iRadius * 2, $iRadius * 2)
  $aMin[$ePen] = _GDIPlus_PenCreate(0xFFFF0000)
  $aMin[$eCap] = _GDIPlus_ArrowCapCreate($iMinRad / 2, 8)
  _GDIPlus_PenSetCustomEndCap($aMin[$ePen], $aMin[$eCap])
EndFunc

; =============================================================================
; Finalize resources for the minute hand clockb2
; =============================================================================
Func MinDoneb2()
  _GDIPlus_PenDispose($aMinb2[$ePen])
  _GDIPlus_ArrowCapDispose($aMinb2[$eCap])
  ResourceDone($aMinb2)
EndFunc

; =============================================================================
; Draw the minute hand clockb2
; =============================================================================
Func MinDrawb2()
  if ($aLastb2[1][0] = $aCurrb2[1][0]) and ($aLastb2[1][1] = $aCurrb2[1][1]) then Return
  _GDIPlus_GraphicsFillRect($aMinb2[$eGraphic], 0, 0, $iRadiusb2 * 2, $iRadiusb2 * 2)
  _GDIPlus_GraphicsDrawLine($aMinb2[$eGraphic], $iCenterb2, $iCenterb2, $aCurrb2[1][0], $aCurrb2[1][1], $aMinb2[$ePen])
  ResourceSet($hMinb2, $aMinb2)
EndFunc

; =============================================================================
; Initialize resources for the minute hand clockb2
; =============================================================================
Func MinInitb2()
  $aMinb2 = ResourceInit($iRadiusb2 * 2, $iRadiusb2 * 2)
  $aMinb2[$ePen] = _GDIPlus_PenCreate(0xFFFF0000)
  $aMinb2[$eCap] = _GDIPlus_ArrowCapCreate($iMinRadb2 / 2, 8)
  _GDIPlus_PenSetCustomEndCap($aMinb2[$ePen], $aMinb2[$eCap])
EndFunc

; =============================================================================
; Finalize resources for the second hand
; ==============================================================================
Func SecDone()
  _GDIPlus_PenDispose($aSec[$ePen])
  ResourceDone($aSec)
EndFunc

; ==============================================================================
; Draw the second hand
; ==============================================================================
Func SecDraw()
  if ($aLast[0][0] = $aCurr[0][0]) and ($aLast[0][1] = $aCurr[0][1]) then Return
  _GDIPlus_GraphicsFillRect($aSec[$eGraphic], 0, 0, $iRadius * 2, $iRadius * 2)
  _GDIPlus_GraphicsDrawLine($aSec[$eGraphic], $iCenter, $iCenter, $aCurr[0][0], $aCurr[0][1], $aSec[$ePen])
  ResourceSet($hSec, $aSec)
EndFunc

; =============================================================================
; Initialize resources for the second hand
; ==============================================================================
Func SecInit()
  $aSec = ResourceInit($iRadius * 2, $iRadius * 2)
  $aSec[$ePen] = _GDIPlus_PenCreate(0xFF000000)
EndFunc

; ==============================================================================
; Finalize resources for the second hand clockb2
; ==============================================================================
Func SecDoneb2()
  _GDIPlus_PenDispose($aSecb2[$ePen])
  ResourceDone($aSecb2)
EndFunc

; ==============================================================================
; Draw the second hand clockb2
; ==============================================================================
Func SecDrawb2()
  if ($aLastb2[0][0] = $aCurrb2[0][0]) and ($aLastb2[0][1] = $aCurrb2[0][1]) then Return
  _GDIPlus_GraphicsFillRect($aSecb2[$eGraphic], 0, 0, $iRadiusb2 * 2, $iRadiusb2 * 2)
  _GDIPlus_GraphicsDrawLine($aSecb2[$eGraphic], $iCenterb2, $iCenterb2, $aCurrb2[0][0], $aCurrb2[0][1], $aSecb2[$ePen])
  ResourceSet($hSecb2, $aSecb2)
EndFunc

; ==============================================================================
; Initialize resources for the second hand clockb2
; =============================================================================
Func SecInitb2()
  $aSecb2 = ResourceInit($iRadiusb2 * 2, $iRadiusb2 * 2)
  $aSecb2[$ePen] = _GDIPlus_PenCreate(0xFF000000)
EndFunc

; ==============================================================================
; Finalize drawing resources
; ==============================================================================
Func ResourceDone(ByRef $aInfo)
  _GDIPlus_GraphicsDispose($aInfo[$eGraphic])
  _WinAPI_ReleaseDC   (0, $aInfo[$eScrDC])
  _WinAPI_DeleteObject($aInfo[$eBitmap])
  _WinAPI_DeleteDC  ($aInfo[$eMemDC ])
EndFunc

; ==============================================================================
; Initialize bitmap resources
; ==============================================================================
Func ResourceInit($iWidth, $iHeight)
  Local $aInfo[$eLast + 1]

  $aInfo[$eScrDC  ] = _WinAPI_GetDC(0)
  $aInfo[$eMemDC  ] = _WinAPI_CreateCompatibleDC($aInfo[$eScrDC])
  $aInfo[$eBitmap ] = _WinAPI_CreateCompatibleBitmap($aInfo[$eScrDC], $iWidth, $iHeight)
  _WinAPI_SelectObject($aInfo[$eMemDC], $aInfo[$eBitmap])
  $aInfo[$eWidth  ] = $iWidth
  $aInfo[$eHeight ] = $iHeight
  $aInfo[$eGraphic] = _GDIPlus_GraphicsCreateFromHDC($aInfo[$eMemDC])
  _GDIPlus_GraphicsFillRect($aInfo[$eGraphic], 0, 0, $iWidth, $iHeight)
  Return $aInfo
EndFunc

; ===============================================================================
; Update layered window with resource information
; ===============================================================================
Func ResourceSet($hGUI, ByRef $aInfo, $iAlpha=-1)
  Local $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
  if $iAlpha = -1 then $iAlpha = $iOpacity
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", $aInfo[$eWidth ])
  DllStructSetData($tSize, "Y", $aInfo[$eHeight])
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend )
  DllStructSetData($tBlend, "Alpha" , $iAlpha   )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $aInfo[$eScrDC], 0, $pSize, $aInfo[$eMemDC], $pSource, 0, $pBlend, $ULW_ALPHA)
EndFunc

; ===========================================================================
; Finalize resources for the digital time
; ===========================================================================
Func TimeDone()
  _GDIPlus_FontDispose      ($aTime[$eFont  ])
  _GDIPlus_FontFamilyDispose  ($aTime[$eFamily])
  _GDIPlus_StringFormatDispose($aTime[$eFormat])
  _GDIPlus_BrushDispose     ($aTime[$eBrush ])
  ResourceDone($aTime)
EndFunc

; ============================================================================
; Draw the digital time
; ============================================================================
Func TimeDraw($hr,$min, $day,  $dayno,$Mth, $yr)
  Local $sString, $aSize
  if ($aLast[0][0] = $aCurr[0][0]) and ($aLast[0][1] = $aCurr[0][1]) then Return
  $sString = StringFormat(" %02d:%02d:%02d %s, %02d %s %02d %s", $hr , $min, @SEC, $day,$dayno,$Mth, $yr, $locname)
  $aSize   = _GDIPlus_GraphicsMeasureString($aTime[$eGraphic], $sString, $aTime[$eFont], $aTime[$eLayout], $aTime[$eFormat])
  DllStructSetData($aTime[$eLayout], "X", $iRadius - (DllStructGetData($aSize[0], "Width") / 2))
  DllStructSetData($aTime[$eLayout], "Y", $iRadius*2/ 3)
  _GDIPlus_GraphicsFillRect($aTime[$eGraphic], 0, 0, $iRadius * 2, $iRadius * 2)
  _GDIPlus_GraphicsDrawStringEx($aTime[$eGraphic], $sString, $aTime[$eFont], $aTime[$eLayout], $aTime[$eFormat], $aTime[$eBrush])
  ResourceSet($hTime, $aTime)
EndFunc

; ==========================================================================
; Initialize resources for the digital time
; ==========================================================================
Func TimeInit()
  $aTime = ResourceInit($iRadius * 2, $iRadius * 2)
  $aTime[$eBrush ] = _GDIPlus_BrushCreateSolid(0xFFFF8000)
  $aTime[$eFormat] = _GDIPlus_StringFormatCreate()
  $aTime[$eFamily] = _GDIPlus_FontFamilyCreate("Arial")
  $aTime[$eFont  ] = _GDIPlus_FontCreate($aTime[$eFamily], Int(24*$scale)+1, 1)
  $aTime[$eLayout] = _GDIPlus_RectFCreate(0, 0, $iRadius * 2 + 20, 100*$scale)
EndFunc

; ============================================================================
; Finalize resources for the digital timeClockb2
; ===========================================================================
Func TimeDoneb2()
  _GDIPlus_FontDispose      ($aTimeb2[$eFont  ])
  _GDIPlus_FontFamilyDispose  ($aTimeb2[$eFamily])
  _GDIPlus_StringFormatDispose($aTimeb2[$eFormat])
  _GDIPlus_BrushDispose     ($aTimeb2[$eBrush ])
  ResourceDone($aTimeb2)
EndFunc

; ============================================================================
; Draw the digital time clockb2
; ============================================================================
Func TimeDrawb2($hr,$min, $day,  $dayno,$Mth, $yr)
  Local $sString, $aSize
  if ($aLastb2[0][0] = $aCurrb2[0][0]) and ($aLastb2[0][1] = $aCurrb2[0][1]) then Return
  $sString = StringFormat(" %02d:%02d:%02d %s, %02d %s %02d %s", $hr , $min, @SEC, $day,$dayno,$Mth, $yr, $locnameb2)
  $aSize   = _GDIPlus_GraphicsMeasureString($aTimeb2[$eGraphic], $sString, $aTimeb2[$eFont], $aTimeb2[$eLayout], $aTimeb2[$eFormat])
  DllStructSetData($aTimeb2[$eLayout], "X", ($iRadiusb2 - (DllStructGetData($aSize[0], "Width") / 2)))
  DllStructSetData($aTimeb2[$eLayout], "Y", $iRadiusb2*2/ 3)
  _GDIPlus_GraphicsFillRect($aTimeb2[$eGraphic], 0, 0, $iRadiusb2 * 2, $iRadiusb2 * 2)
  _GDIPlus_GraphicsDrawStringEx($aTimeb2[$eGraphic], $sString, $aTimeb2[$eFont], $aTimeb2[$eLayout], $aTimeb2[$eFormat], $aTimeb2[$eBrush])
  ResourceSet($hTimeb2, $aTimeb2)
EndFunc

; ============================================================================
; Initialize resources for the digital time clockb2
; ============================================================================
Func TimeInitb2()
  $aTimeb2 = ResourceInit($iRadiusb2 * 2, $iRadiusb2 * 2)
  $aTimeb2[$eBrush ] = _GDIPlus_BrushCreateSolid(0xFFFF8000)
  $aTimeb2[$eFormat] = _GDIPlus_StringFormatCreate()
  $aTimeb2[$eFamily] = _GDIPlus_FontFamilyCreate("Arial")
  $aTimeb2[$eFont  ] = _GDIPlus_FontCreate($aTimeb2[$eFamily], Int(24*$scaleb2)+1, 1)
  $aTimeb2[$eLayout] = _GDIPlus_RectFCreate(0, 0, $iRadiusb2 * 2 + 20, 100*$scaleb2)
EndFunc

; =============================================================================
; Convert time value to radians
; =============================================================================
Func TimeToRadians($sTimeType,$hr ,$min)
  Switch $sTimeType
    case "sec"
    Return ($nPI / 2) - (@SEC  * ($nPI / 30))
    case "min"
    Return ($nPI / 2) - ($min  * ($nPI / 30)) - (Int(@SEC / 10) * ($nPI / 180))
    case "hour"
    Return ($nPI / 2) - ($hr * ($nPI / 6 )) - ($min / 12) * ($nPI / 30)
  EndSwitch
EndFunc

; ============================================================================
; Handle the WM_NCHITTEST message so our window can be dragged
; ============================================================================
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    if $hWnd = $hDial then Return $HTCAPTION
    if $hWnd = $hDialb2 then Return $HTCAPTION
EndFunc

;============================================================================
; $hrdiff = 0, $mindiff = 0 gives UTC time
;TimeMinusLocalTimeToArray(-5)   gives local time which is 5hrs behind UTC      like Jamaica.
;TimeMinusLocalTimeToArray(2,30) gives local time which is 2hrs 30mins infront of  UTC like India.
;try  http://www.timeticker.com/   for World times information
;=============================================================================
Func ModifyUTCTimeToArray($hrdiff = 0, $mindiff = 0)
   Local $tSystem,$tFile, $UTC,$UTC2,$UtcLocForm,$locminusUTC,$sNewDate,$datestr,$datar,$iWeekday
    Local $datearr[12]
    $tSystem = _Date_Time_GetSystemTime()
    $tFile   = _Date_Time_SystemTimeToFileTime(DllStructGetPtr($tSystem))
    $UTC =  StringSplit (_Date_Time_FileTimeToStr($tFile)," ")
    $UTC2 =  StringSplit ($UTC[1], "/")
    $UtcLocForm = $UTC2[3] & "/" & $UTC2[1] & "/" & $UTC2[2] & " " & $UTC[2]
    $locminusUTC = _DateDiff( 'n',_NowCalc(),$UtcLocForm)
    $sNewDate = _DateAdd( 'h',$hrdiff, _NowCalc())
    $sNewDate = _DateAdd( 'n',$mindiff + $locminusUTC , $sNewDate)
    ;MsgBox(0,"",_NowCalc() & "#   File time .:" & _Date_Time_FileTimeToStr($tFile) & "  date" & $sNewDate )
    $datestr = StringReplace ($sNewDate, "/", " ")
    $datestr = StringReplace ($datestr, ":"," ")
    $datar = StringSplit ($datestr , " ")
    ; [0] - No. in array    ;[1] - Year     ; [2] - Month   ; [3] - Day
    ; [4] - Hour            ; [5] - Minute   ; [6] - Second
    $iWeekday = _DateToDayOfWeek ($datar[1], $datar[2], $datar[3])
    $datearr[0] = $datar[1]                         ; Year
    $datearr[1] = $datar[2]                         ; Month number
    $datearr[2] = _DateToMonth($datar[2])           ; Month Long name
    $datearr[3] = _DateToMonth($datar[2],1)         ; Month Abbreviated name
    $datearr[4] = $datar[3]                         ; Day number
    $datearr[5] = _DateDayOfWeek($iWeekDay)         ; Day Long name
    $datearr[6] = _DateDayOfWeek($iWeekDay,1)       ; Day Abbreviated name
    $datearr[7] = $datar[4]                         ; Hour  (24hr )
    $datearr[8] = $datar[4] - (($datar[4] >= 13)*12)  ; Hour  (12hr )
    $datearr[9] = $datar[5]                         ; Minute
    $datearr[10] = $datar[6]                        ; Second
    If $datar[4] < 12 Then                          ; AM/PM
        $datearr[11] = "AM"
    Else
        $datearr[11] = "PM"
    EndIf
    Return $datearr
EndFunc

; ============================================================================
; Randomize Clock components
; ============================================================================
Func DissambleClock()
    Local $nxhr, $nyhr, $nxmin, $nymin,$nxtm, $nytm, $nxdot, $nydot,$nxsec, $nysec, $nxface, $nyface, $WinPos
    $nxhr = Random(@DesktopWidth * 0.25,@DesktopWidth * 0.75, 1)
    $nyhr = Random(@DesktopHeight * 0.25,@DesktopHeight * 0.75, 1)
    $nxmin = Random(@DesktopWidth * 0.25,@DesktopWidth * 0.75, 1)
    $nymin = Random(@DesktopHeight * 0.25,@DesktopHeight * 0.75, 1)
    $nxtm = Random(@DesktopWidth * 0.25,@DesktopWidth * 0.75, 1)
    $nytm = Random(@DesktopHeight * 0.25,@DesktopHeight * 0.75, 1)
    $nxdot = Random(@DesktopWidth * 0.25,@DesktopWidth * 0.75, 1)
    $nydot = Random(@DesktopHeight * 0.25,@DesktopHeight * 0.75, 1)
    $nxsec = Random(@DesktopWidth * 0.25,@DesktopWidth * 0.75, 1)
    $nysec = Random(@DesktopHeight * 0.25,@DesktopHeight * 0.75, 1)
    $nxface = Random(@DesktopWidth * 0.25,@DesktopWidth * 0.75, 1)
    $nyface = Random(@DesktopHeight * 0.25,@DesktopHeight * 0.75, 1)
    $WinPos = WinGetPos("Clock")
    for $m = 1 to 30 step 1
        WinMove("Min","",$WinPos[0]+int(($nxmin - $WinPos[0])*$m/30), $WinPos[1]+int(($nymin - $WinPos[1])*$m/30))
        WinMove("Hour","",$WinPos[0]+int(($nxhr - $WinPos[0])*$m/30), $WinPos[1]+int(($nyhr - $WinPos[1])*$m/30))
        WinMove("Time","",$WinPos[0]+int(($nxtm - $WinPos[0])*$m/30), $WinPos[1]+int(($nytm - $WinPos[1])*$m/30))
        WinMove("Dot","",$WinPos[0]+int(($nxdot - $WinPos[0])*$m/30), $WinPos[1]+int(($nydot - $WinPos[1])*$m/30))
        WinMove("Sec","",$WinPos[0]+int(($nxsec - $WinPos[0])*$m/30), $WinPos[1]+int(($nysec - $WinPos[1])*$m/30))
        WinMove("Face","",$WinPos[0]+int(($nxface - $WinPos[0])*$m/30), $WinPos[1]+int(($nyface - $WinPos[1])*$m/30))
        sleep(30)
    next
EndFunc

; ===========================================================================
; Randomize Clock components
; ===========================================================================
Func reassembClock()
    Local $WinPos, $WinPosmin, $WinPoshr,   $WinPostime, $WinPosdot,$WinPossec, $WinPosface, $adjfacex, $adjfacey, $WinPos
    $WinPos = WinGetPos("Clock")
    $WinPosmin = WinGetPos("Min")
    $WinPoshr = WinGetPos("Hour")
    $WinPostime = WinGetPos("Time")
    $WinPosdot = WinGetPos("Dot")
    $WinPossec = WinGetPos("Sec")
    $WinPosface = WinGetPos("Face")
    $adjfacex = $WinPos[0]-(2)
    $adjfacey = $WinPos[1]-(2)
    for $m = 1 to 30 ;step 10
        WinMove("Min","",$WinPosmin[0]-int(($WinPosmin[0] - $WinPos[0])*$m/30), $WinPosmin[1]-int(($WinPosmin[1] - $WinPos[1])*$m/30))
        WinMove("Hour","",$WinPoshr[0]-int(($WinPoshr[0] - $WinPos[0])*$m/30), $WinPoshr[1]-int(($WinPoshr[1] - $WinPos[1])*$m/30))
        WinMove("Time","",$WinPostime[0]-int(($WinPostime[0] - $WinPos[0])*$m/30), $WinPostime[1]-int(($WinPostime[1] - ($WinPos[1]+5+$WinPos[3]*2/3))*$m/30))
        WinMove("Dot","",$WinPosdot[0]-int(($WinPosdot[0] - $WinPos[0])*$m/30), $WinPosdot[1]-int(($WinPosdot[1] - $WinPos[1])*$m/30))
        WinMove("Sec","",$WinPossec[0]-int(($WinPossec[0] - $WinPos[0])*$m/30), $WinPossec[1]-int(($WinPossec[1] - $WinPos[1])*$m/30))
        WinMove("Face","",$WinPosface[0]-int(($WinPosface[0] - $adjfacex)*$m/30) , $WinPosface[1]-int(($WinPosface[1] - $adjfacey )*$m/30))
        sleep(30)
    next
EndFunc

; ===========================================================================
; Randomize clockb2 components
; ===========================================================================
Func DissambleClockb2()
    Local $nxhr, $nyhr, $nxmin, $nymin,$nxtm, $nytm, $nxdot, $nydot,$nxsec, $nysec, $nxface, $nyface, $WinPos
    $nxhr = Random(@DesktopWidth * 0.25,@DesktopWidth * 0.75, 1)
    $nyhr = Random(@DesktopHeight * 0.25,@DesktopHeight * 0.75, 1)
    $nxmin = Random(@DesktopWidth * 0.25,@DesktopWidth * 0.75, 1)
    $nymin = Random(@DesktopHeight * 0.25,@DesktopHeight * 0.75, 1)
    $nxtm = Random(@DesktopWidth * 0.25,@DesktopWidth * 0.75, 1)
    $nytm = Random(@DesktopHeight * 0.25,@DesktopHeight * 0.75, 1)
    $nxdot = Random(@DesktopWidth * 0.25,@DesktopWidth * 0.75, 1)
    $nydot = Random(@DesktopHeight * 0.25,@DesktopHeight * 0.75, 1)
    $nxsec = Random(@DesktopWidth * 0.25,@DesktopWidth * 0.75, 1)
    $nysec = Random(@DesktopHeight * 0.25,@DesktopHeight * 0.75, 1)
    $nxface = Random(@DesktopWidth * 0.25,@DesktopWidth * 0.75, 1)
    $nyface = Random(@DesktopHeight * 0.25,@DesktopHeight * 0.75, 1)
    ;MsgBox(0,""," $nx=" & $nx &"   $ny=" & $ny & "   wd=" & @DesktopWidth *.15 & "   Hd=" & @DesktopHeight*.15)
    $WinPos = WinGetPos("Clockb2")
    for $m = 1 to 30 step 1
        WinMove("Minb2","",$WinPos[0]+int(($nxmin - $WinPos[0])*$m/30), $WinPos[1]+int(($nymin - $WinPos[1])*$m/30))
        WinMove("Hourb2","",$WinPos[0]+int(($nxhr - $WinPos[0])*$m/30), $WinPos[1]+int(($nyhr - $WinPos[1])*$m/30))
        WinMove("Timeb2","",$WinPos[0]+int(($nxtm - $WinPos[0])*$m/30), $WinPos[1]+int(($nytm - $WinPos[1])*$m/30))
        WinMove("Dotb2","",$WinPos[0]+int(($nxdot - $WinPos[0])*$m/30), $WinPos[1]+int(($nydot - $WinPos[1])*$m/30))
        WinMove("Secb2","",$WinPos[0]+int(($nxsec - $WinPos[0])*$m/30), $WinPos[1]+int(($nysec - $WinPos[1])*$m/30))
        WinMove("Faceb2","",$WinPos[0]+int(($nxface - $WinPos[0])*$m/30), $WinPos[1]+int(($nyface - $WinPos[1])*$m/30))
        sleep(30)
    next
EndFunc

; ========================================================================
; Randomize clockb2 components
; =========================================================================
Func reassembClockb2()
    Local $WinPos, $WinPosmin, $WinPoshr,   $WinPostime, $WinPosdot,$WinPossec, $WinPosface, $adjfacex, $adjfacey, $WinPos
    $WinPos = WinGetPos("Clockb2")
    $WinPosmin = WinGetPos("Minb2")
    $WinPoshr = WinGetPos("Hourb2")
    $WinPostime = WinGetPos("Timeb2")
    $WinPosdot = WinGetPos("Dotb2")
    $WinPossec = WinGetPos("Secb2")
    $WinPosface = WinGetPos("Faceb2")
    $adjfacex = $WinPos[0]-(2)
    $adjfacey = $WinPos[1]-(2)
    ;$adjfacex = $WinPos[0]-($iRadius*.01 *cos(45*$nPI/180))
    ;$adjfacey = $WinPos[1]-($iRadius*.01 *Sin(45*$nPI/180))
    ;MsgBox(0,""," $nx=" & $nx &"   $ny=" & $ny & "   wd=" & @DesktopWidth *.15 & "   Hd=" & @DesktopHeight*.15)

    for $m = 1 to 30 ;step 10
        WinMove("Minb2","",$WinPosmin[0]-int(($WinPosmin[0] - $WinPos[0])*$m/30), $WinPosmin[1]-int(($WinPosmin[1] - $WinPos[1])*$m/30))
        WinMove("Hourb2","",$WinPoshr[0]-int(($WinPoshr[0] - $WinPos[0])*$m/30), $WinPoshr[1]-int(($WinPoshr[1] - $WinPos[1])*$m/30))
        WinMove("Timeb2","",$WinPostime[0]-int(($WinPostime[0] - $WinPos[0])*$m/30), $WinPostime[1]-int(($WinPostime[1] - ($WinPos[1]+5+$WinPos[3]*2/3))*$m/30))
        WinMove("Dotb2","",$WinPosdot[0]-int(($WinPosdot[0] - $WinPos[0])*$m/30), $WinPosdot[1]-int(($WinPosdot[1] - $WinPos[1])*$m/30))
        WinMove("Secb2","",$WinPossec[0]-int(($WinPossec[0] - $WinPos[0])*$m/30), $WinPossec[1]-int(($WinPossec[1] - $WinPos[1])*$m/30))
        WinMove("Faceb2","",$WinPosface[0]-int(($WinPosface[0] - $adjfacex)*$m/30) , $WinPosface[1]-int(($WinPosface[1] - $adjfacey )*$m/30))
        sleep(30)
    next
EndFunc

; ======================================================================
; Exit program
; =====================================================================
Func quitclk()
    $Msg = $GUI_EVENT_CLOSE
EndFunc

Func quitconfig()
    $nMsg = $GUI_EVENT_CLOSE
    MsgBox(0,""," here at quitconfig")
EndFunc

Func _WinMove($HWnd, $Command, $wParam, $lParam)
    If $guislock then
    If BitAND(WinGetState($HWnd), 32) Then Return $GUI_RUNDEFMSG
    ;DllCall("user32.dll", "long", "SendMessage", "hwnd", $HWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
    dllcall("user32.dll","int","SendMessage","hWnd", $HWnd, "int",$WM_NCLBUTTONDOWN,"int", $HTCAPTION,"int", 0)
    EndIf
    If $HWnd = $hFace Or $HWnd = $hDial Then
        $iRet = DllCall("User32.dll", "int", "SetWindowPos", "Hwnd", $hFace, "Hwnd", $hDial, _
            "int", 100, "int", 100, "int", 100, "int", 100, "uint", $SWP_NOSIZE + $SWP_NOMOVE) ; Z-order Parent $hDial sent to back.
    EndIf
    If $HWnd = $hFaceb2 Or $HWnd = $hDialb2 Then
        $iRet = DllCall("User32.dll", "int", "SetWindowPos", "Hwnd", $hFaceb2, "Hwnd", $hDialb2, _
            "int", 100, "int", 100, "int", 100, "int", 100, "uint", $SWP_NOSIZE + $SWP_NOMOVE) ; Z-order Parent $hDial sent to back.
    EndIf
EndFunc

; ================================================================
; Check if GUI (handle) is GUISetState(@SW_SHOW)- visible
; ================================================================
Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc

; ============================================================
; Toggle Clock Face  visibility
; =============================================================
Func viewface()
    If BitAnd(GUICtrlRead($viewitemface),$GUI_CHECKED) = $GUI_CHECKED Then
        GUICtrlSetState($viewitemface,$GUI_UNCHECKED)
        GUISetState(@SW_HIDE,$hFace)
    Else
        GUICtrlSetState($viewitemface,$GUI_CHECKED)
        GUISetState(@SW_SHOW,$hFace)
        $iRet = DllCall("User32.dll", "int", "SetWindowPos", "Hwnd", $hFace, "Hwnd", $hDial, _
        "int", 100, "int", 100, "int", 100, "int", 100, "uint", $SWP_NOSIZE + $SWP_NOMOVE) ; Z-order Parent $hDial sent to back.
    EndIf
    ;If IsVisible($hFace) Then
    ;   GUISetState(@SW_HIDE,$hFace)
    ;Else
    ;   GUISetState(@SW_SHOW,$hFace)
    ;EndIf
EndFunc

; =================================================================
; Toggle clockb2 Face  visibility
; ==================================================================
Func viewfaceb2()
    If BitAnd(GUICtrlRead($viewitemfaceb2),$GUI_CHECKED) = $GUI_CHECKED Then
        GUICtrlSetState($viewitemfaceb2,$GUI_UNCHECKED)
        GUISetState(@SW_HIDE,$hFaceb2)
    Else
        GUICtrlSetState($viewitemfaceb2,$GUI_CHECKED)
        GUISetState(@SW_SHOW,$hFaceb2)
        $iRet = DllCall("User32.dll", "int", "SetWindowPos", "Hwnd", $hFaceb2, "Hwnd", $hDialb2, _
        "int", 100, "int", 100, "int", 100, "int", 100, "uint", $SWP_NOSIZE + $SWP_NOMOVE) ; Z-order Parent $hDial sent to back.
    EndIf
EndFunc

; ==================================================================
; Toggle Clock Face  visibility
; ==================================================================
Func Showclockb2()
    If BitAnd(GUICtrlRead($viewitemshowclockb2),$GUI_CHECKED) = $GUI_CHECKED Then
        GUICtrlSetState($viewitemshowclockb2,$GUI_UNCHECKED)
        GUISetState(@SW_HIDE,$hDialb2)
        GUISetState(@SW_HIDE,$hTimeb2)
        GUISetState(@SW_HIDE,$hFaceb2)
        GUISetState(@SW_HIDE,$hDotb2)
        GUISetState(@SW_HIDE,$hHourb2)
        GUISetState(@SW_HIDE,$hMinb2)
        GUISetState(@SW_HIDE,$hSecb2)
    Else
        GUICtrlSetState($viewitemshowclockb2,$GUI_CHECKED)
        GUISetState(@SW_SHOW,$hDialb2)
        GUISetState(@SW_SHOW,$hTimeb2)
        GUISetState(@SW_SHOW,$hFaceb2)
        GUISetState(@SW_SHOW,$hDotb2)
        GUISetState(@SW_SHOW,$hHourb2)
        GUISetState(@SW_SHOW,$hMinb2)
        GUISetState(@SW_SHOW,$hSecb2)
        $iRet = DllCall("User32.dll", "int", "SetWindowPos", "Hwnd", $hFaceb2, "Hwnd", $hDialb2, _
        "int", 100, "int", 100, "int", 100, "int", 100, "uint", $SWP_NOSIZE + $SWP_NOMOVE) ; Z-order Parent $hDial sent to back.
    EndIf
EndFunc

; ==============================================================
; Lock all pieces of Clock in position
; ===============================================================
Func LockPos()
    If BitAnd(GUICtrlRead($lockpositem),$GUI_CHECKED) = $GUI_CHECKED Then
        GUICtrlSetState($lockpositem,$GUI_UNCHECKED)
        $guislock = 1
    Else
        GUICtrlSetState($lockpositem,$GUI_CHECKED)
        $guislock = 0
    EndIf
EndFunc

Func resizeclock()
    Local $MousePos,$MousePos1,$Num,$Mousescale, $modifier = 5
    Opt ("MouseCoordMode", 2)
    $guislock = 0
    GUISetCursor (13, 1, $hDot)
    ToolTip ("Click black dot and drag to resize the clock.  Release to set size.")
    While 1
        $MousePos = MouseGetPos ()
        $Mousescale = ($scale*100*$modifier) +  $MousePos[0]
        If _IsPressed ("01", $user32_dll) Then
            While _IsPressed ("01", $user32_dll)
                $MousePos1 = MouseGetPos ()
                $Num = Int(( $Mousescale - $MousePos1[0]  )/$modifier)
                If $num > 10 and $num < 190 then
                $scale      = $num/100
                $iCenter    = Int(200*$scale)
                $iHourRad   = Int(140*$scale)
                $iMinRad    = Int(200*$scale)
                $iRadius    = Int(200*$scale)
                $iSecRad    = Int(200*$scale)
                HourDone ()
                HourInit ()
                MinDone  ()
                MinInit  ()
                SecDone  ()
                SecInit  ()
                TimeDone ()
                TimeInit ()
                FaceDraw ()
                DialDraw ()
                DotDraw  ()
                Draw ()
                endif
                Sleep (30)
            WEnd
            ExitLoop
        EndIf
        Sleep (10)
    WEnd
    ToolTip ("")
    GUISetCursor ()
    $guislock = 1
    Opt ("MouseCoordMode", 1)
EndFunc

Func resizeClockb2()
    Local $MousePos,$MousePos1,$Num,$Mousescale, $modifier = 5
    Opt ("MouseCoordMode", 2)
    $guislock = 0
    GUISetCursor (13, 1, $hDotb2)
    ToolTip ("Click black dot and drag to resize the clock.  Release to set size.")
    While 1
        $MousePos = MouseGetPos ()
        $Mousescale = ($scaleb2*100*$modifier) +  $MousePos[0]
        If _IsPressed ("01", $user32_dll) Then
            While _IsPressed ("01", $user32_dll)
                $MousePos1 = MouseGetPos ()
                $Num = Int(( $Mousescale - $MousePos1[0]  )/$modifier)
                If $num > 10 and $num < 190 then
                $scaleb2        = $num/100
                $iCenterb2      = Int(200*$scaleb2)
                $iHourRadb2     = Int(140*$scaleb2)
                $iMinRadb2      = Int(200*$scaleb2)
                $iRadiusb2      = Int(200*$scaleb2)
                $iSecRadb2      = Int(200*$scaleb2)
                HourDoneb2 ()
                HourInitb2 ()
                MinDoneb2  ()
                MinInitb2  ()
                SecDoneb2  ()
                SecInitb2  ()
                TimeDoneb2 ()
                TimeInitb2 ()
                FaceDrawb2 ()
                DialDrawb2 ()
                DotDrawb2  ()
                Drawb2 ()
                endif
                Sleep (30)
            WEnd
            ExitLoop
        EndIf
        Sleep (10)
    WEnd
    ToolTip ("")
    GUISetCursor ()
    $guislock = 1
    Opt ("MouseCoordMode", 1)
EndFunc

;=======================================================================
;Set time difference for Clock
;=======================================================================
Func TimeDiffConfig()
    Local $Form2,$GroupBox1,$Input1,$Input2,$inputtimezone,$MyButton1,$MyButton2,$Label1,$Label2,$Label3,$Button1
    Opt ("GUIOnEventMode", 0)
    $Form2 = GUICreate("Time Difference Configure", 292, 183, 351, 263, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS))
    GUISetIcon("D:\003.ico")
    GUISetBkColor(0xA6CAF0)
    $GroupBox1 = GUICtrlCreateGroup("", 0, -1, 291, 143)
    $Input1 = GUICtrlCreateInput("", 22, 44, 61, 24)
    GUICtrlSetBkColor(-1, 0xFFFFE1)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $MyButton1 = GUICtrlCreateUpdown( $Input1)
            GUICtrlSetLimit(-1, 23,-23)
            GUICtrlSetData ($input1, $hrdiff )
    $Label1 = GUICtrlCreateLabel("Select Hours", 14, 22, 93, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $Input2 = GUICtrlCreateInput("", 165, 43, 61, 24)
    GUICtrlSetBkColor(-1, 0xFFFFE1)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $MyButton2 = GUICtrlCreateUpdown( $Input2)
            GUICtrlSetLimit(-1, 59,-59)
            GUICtrlSetData ($input2, $mindiff)
    $Label2 = GUICtrlCreateLabel("Select Hours", 157, 21, 93, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $inputtimezone = GUICtrlCreateInput($locname, 4, 108, 281, 21)
    GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif")
    $Label3 = GUICtrlCreateLabel("Enter text to display (Time Zone)", 28, 88, 228, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Button1 = GUICtrlCreateButton("&OK", 105, 149, 75, 25, 0)
    GUISetState(@SW_SHOW)
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE, $Button1
                GUISetState(@SW_HIDE,$Form2)
                ExitLoop
        EndSwitch
        $hrdiff  = GUICtrlRead($input1)
        $mindiff = GUICtrlRead($input2)
        $locname = GUICtrlRead($inputtimezone)
        HourDone ()
        HourInit ()
        MinDone  ()
        MinInit  ()
        SecDone  ()
        SecInit  ()
        TimeDone ()
        TimeInit ()
        FaceDraw ()
        DialDraw ()
        DotDraw  ()
        Draw    ()
        Sleep (30)
    WEnd
    Opt ("GUIOnEventMode", 1)
    Return 1
EndFunc

;=======================================================================
;Set time difference for clockb2
;=======================================================================
Func TimeDiffConfigb2()
    Local $Form2,$GroupBox1,$Input1,$Input2,$inputtimezone,$MyButton1,$MyButton2,$Label1,$Label2,$Label3,$Button1
    Opt ("GUIOnEventMode", 0)
    $Form2 = GUICreate("Time Difference Configure", 292, 183, 351, 263, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS))
    GUISetIcon("D:\003.ico")
    GUISetBkColor(0xA6CAF0)
    $GroupBox1 = GUICtrlCreateGroup("", 0, -1, 291, 143)
    $Input1 = GUICtrlCreateInput("", 22, 44, 61, 24)
    GUICtrlSetBkColor(-1, 0xFFFFE1)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $MyButton1 = GUICtrlCreateUpdown( $Input1)
            GUICtrlSetLimit(-1, 23,-23)
            GUICtrlSetData ($input1, $hrdiffb2 )
    $Label1 = GUICtrlCreateLabel("Select Hours", 14, 22, 93, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $Input2 = GUICtrlCreateInput("", 165, 43, 61, 24)
    GUICtrlSetBkColor(-1, 0xFFFFE1)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $MyButton2 = GUICtrlCreateUpdown( $Input2)
            GUICtrlSetLimit(-1, 59,-59)
            GUICtrlSetData ($input2, $mindiffb2)
    $Label2 = GUICtrlCreateLabel("Select Hours", 157, 21, 93, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $inputtimezone = GUICtrlCreateInput($locnameb2, 4, 108, 281, 21)
    GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif")
    $Label3 = GUICtrlCreateLabel("Enter text to display (Time Zone)", 28, 88, 228, 20)

    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Button1 = GUICtrlCreateButton("&OK", 105, 149, 75, 25, 0)
    GUISetState(@SW_SHOW)
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE, $Button1
                GUISetState(@SW_HIDE,$Form2)
                ExitLoop
        EndSwitch
        $hrdiffb2  = GUICtrlRead($input1)
        $mindiffb2 = GUICtrlRead($input2)
        $locnameb2 = GUICtrlRead($inputtimezone)
        HourDoneb2 ()
        HourInitb2 ()
        MinDoneb2  ()
        MinInitb2  ()
        SecDoneb2  ()
        SecInitb2  ()
        TimeDoneb2 ()
        TimeInitb2 ()
        FaceDrawb2 ()
        DialDrawb2 ()
        DotDrawb2  ()
        Drawb2  ()
        Sleep (30)
    WEnd
    Drawb2  ()
    Opt ("GUIOnEventMode", 1)
    Return 1
EndFunc

Edit:Now runs on current AutoIt version.

Edited by Malkey

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I have reduced the above clock to its basics. And added a graphics which can be found at

http://www.autoitscript.com/forum/index.php?s=&showtopic=64569&view=findpost&p=483796

The script below is only a static example of what is possible. All the _GDIPlus_MatrixRotate()'s does slow things down. There would be a better way of producing the same effect.

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <GuiConstantsEx.au3>

; =================================================================
; Description ...: Modified script  of Clock.au3 
; Author ........: Paul Campbell (PaulIA)
; Notes .........:
; =================================================================

; ================================================================
; Global constants
; =================================================================
Global Const $iOpacity          = 128
Global Const $nPI               = 3.1415926535897932384626433832795
Global Const $WM_LBUTTONDOWN = 0x0201  ; Drag Window 1 of 3 addin
Global Const $AC_SRC_ALPHA      = 1
Global Const $ULW_ALPHA         = 2
Global Enum $eScrDC=0, $eMemDC, $eBitmap, $eWidth, $eHeight, $eGraphic, $ePen, $eCap, $eBrush, $eFormat, $eFamily, $eFont, $eLayout, $eLast
 
; =================================================================
; Global variables
; =================================================================
Global $MenuItemExit, $ContextMenu, $separator1, $hRotate, $Msg
Global $user32_dll = DllOpen ("user32.dll")
Global $iRadius    = 200, $f = 1

; =================================================================
; Main
; =================================================================
Opt("MustDeclareVars", 1)
Opt ("GUIOnEventMode", 1)

ClockInit()
RotateDraw()
ClockLoop()
ClockDone()

; ===============================================================
; Finalize clock
; ===============================================================
Func ClockDone()
     
  ; Finalize GDI+ library
  _GDIPlus_Shutdown()
EndFunc

; ==============================================================
; Initialize clock
; ==============================================================
Func ClockInit()
  Local $iX, $iY

  ; Calculate the dial frame caption size
  $iX = -(_WinAPI_GetSystemMetrics($SM_CXFRAME))
  $iY = -(_WinAPI_GetSystemMetrics($SM_CYCAPTION) + _WinAPI_GetSystemMetrics($SM_CYFRAME)) 
  
  $hRotate = GUICreate("Rotate", $iRadius * 2, $iRadius * 2,  -1,  -1, 0, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
  
  $ContextMenu = GUICtrlCreateContextMenu ()
    $separator1 = GUICtrlCreateMenuitem ("",$ContextMenu)   ; create a separator line   
    $MenuItemExit = GUICtrlCreateMenuitem ("Exit", $ContextMenu)
        GUICtrlSetOnEvent ($MenuItemExit, "quitclk")  
  
  GuiRegisterMsg($WM_LBUTTONDOWN, "_WinMove")    ; Drag Window 2 of 3 addin
  GUISetState()
  
  ; Initialize GDI+ library
  _GDIPlus_Startup()
EndFunc

; =============================================================
; Loop until user exits
; =============================================================
Func ClockLoop()    
  do
      sleep(250)
    ;RotateDraw()
  until $Msg = $GUI_EVENT_CLOSE
EndFunc


; ===========Start of  _GDIPlus_MatrixRotate() Example ==========
; ===============================================================
; Draw Rotated text from 
;http://www.autoitscript.com/forum/index.php?s=&showtopic=64569&view=findpost&p=483796
; ===============================================================


Func RotateDraw()
    Local $aRotate, $F = 1
    if $f = 1 then
    $aRotate = ResourceInit( 400,300)
    ;DrawGraphic(          $hGraphic, $nX, $nY, $nAngle,    $iWidth,    $iHeight, $iARGB = 0xFF000000)
    ;Cross
     DrawGraphic($aRotate[$eGraphic], 120, 150,      45,        100,          20,          0xFFFF8000)
     DrawGraphic($aRotate[$eGraphic], 120, 150,     135,        100,          20,          0xFF00FF00)
     DrawGraphic($aRotate[$eGraphic], 120, 150,     225,        100,          20,          0xFF0505FB)
     DrawGraphic($aRotate[$eGraphic], 120, 150,     315,        100,          20,          0xFFFF00FF)
    
    ;Square
     DrawGraphic($aRotate[$eGraphic], 260, 200,       0,        100,          20,          0xFFFF8000)
     DrawGraphic($aRotate[$eGraphic], 260, 100,      90,        100,          20,          0xFF00FF00)
     DrawGraphic($aRotate[$eGraphic], 360, 100,     180,        100,          20,          0xFF0505FB)
     DrawGraphic($aRotate[$eGraphic], 360, 200,     270,        100,          20,          0xFFFF00FF)
     $f = 2
    endif
     ResourceSet ($hRotate, $aRotate, $iOpacity)
    ResourceDone($aRotate)
EndFunc 

Func DrawGraphic($hGraphic, $nX, $nY, $nAngle, $nWidth, $nHeight, $iARGB = 0xFF000000)
    Local $hMatrix, $nXt, $nYt, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
    ; $nXt     - The X coordinate of the upper left corner of the Graphics object before rotation 
    ; $nYt     - The Y coordinate of the upper left corner of the Graphics object before rotation
    
    ;Rotation Matrix
    $hMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixRotate($hMatrix, $nAngle, "False")   
    _GDIPlus_GraphicsSetTransform($hGraphic , $hMatrix) 
    
    ;Rotation of Coordinate Axes formulae
    $nXt = $nX*cos($nAngle*$nPI/180) + $nY*sin($nAngle*$nPI/180)  ; $nXt - X coordinate before translation 
    $nYt = -$nX*sin($nAngle*$nPI/180) + $nY*cos($nAngle*$nPI/180) ; $nYt - Y coordinate before translation
    
    $hBrush  = _GDIPlus_BrushCreateSolid ($iARGB)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    $hFont   = _GDIPlus_FontCreate ($hFamily, 12, 1)
    $tLayout = _GDIPlus_RectFCreate ( $nXt, $nYt, $nWidth, $nHeight )
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, "Autoit Sang", $hFont, $tLayout, $hFormat, $hBrush)
    Sleep(1000) 
    
    ; Clean up resources    
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose ($hBrush) 
    Return 1
EndFunc
; ====================================================================
; ==================>End of _GDIPlus_MatrixRotate() Example ==========


; ====================================================================
; Finalize drawing resources
; ====================================================================
Func ResourceDone(ByRef $aInfo)
  _GDIPlus_GraphicsDispose($aInfo[$eGraphic])
  _WinAPI_ReleaseDC   (0, $aInfo[$eScrDC])
  _WinAPI_DeleteObject($aInfo[$eBitmap])
  _WinAPI_DeleteDC    ($aInfo[$eMemDC ])
EndFunc

; ===================================================================
; Initialize bitmap resources
; ===================================================================
Func ResourceInit($iWidth, $iHeight)
  Local $aInfo[$eLast + 1]

  $aInfo[$eScrDC  ] = _WinAPI_GetDC(0)
  $aInfo[$eMemDC  ] = _WinAPI_CreateCompatibleDC($aInfo[$eScrDC])
  $aInfo[$eBitmap ] = _WinAPI_CreateCompatibleBitmap($aInfo[$eScrDC], $iWidth, $iHeight)
  _WinAPI_SelectObject($aInfo[$eMemDC], $aInfo[$eBitmap])
  $aInfo[$eWidth  ] = $iWidth
  $aInfo[$eHeight ] = $iHeight
  $aInfo[$eGraphic] = _GDIPlus_GraphicsCreateFromHDC($aInfo[$eMemDC])
  _GDIPlus_GraphicsFillRect($aInfo[$eGraphic], 0, 0, $iRadius * 2, $iRadius * 2)
  Return $aInfo
EndFunc

; ==================================================================
; Update layered window with resource information
; ==================================================================
Func ResourceSet($hGUI, ByRef $aInfo, $iAlpha=-1)
  Local $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  if $iAlpha = -1 then $iAlpha = $iOpacity
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", $aInfo[$eWidth ])
  DllStructSetData($tSize, "Y", $aInfo[$eHeight])
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend )
  DllStructSetData($tBlend, "Alpha" , $iAlpha      )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $aInfo[$eScrDC], 0, $pSize, $aInfo[$eMemDC], $pSource, 0, $pBlend, $ULW_ALPHA)
EndFunc

; ==================================================================
; Exit program
; ==================================================================
Func quitclk()
    $Msg = $GUI_EVENT_CLOSE 
EndFunc  

; ================================================================= 
; Drag Window 3 of 3 addin
; =================================================================
Func _WinMove($HWnd, $Command, $wParam, $lParam)    
     If BitAND(WinGetState($HWnd), 32) Then Return $GUI_RUNDEFMSG
    ;DllCall("user32.dll", "long", "SendMessage", "hwnd", $HWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
    dllcall("user32.dll","int","SendMessage","hWnd", $HWnd, "int",$WM_NCLBUTTONDOWN,"int", $HTCAPTION,"int", 0)     
EndFunc
A sleep() command in the Do - Until loop reduced the CPU usage of 100% to single figure usage.

An AutoIt Forum search for "CPU usage" gave me the answer I desperately needed.

Edited by Malkey

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi and thank you for sharing.

I'm almost trying your script, but....

Can you shorten these lines in your script please

; ====================================================================================================
===========================
If I direct copy and paste your code I then need to remove or comment out every single line that is like this.

Cheers

Edit: after doing the above (Search & Replace) on your script, it works well..

But CPU usage is always @ 100% unless disassembling or reassembling the clock in which case it sits @ 80% while the transition happens. (only tested it on my weak laptop 1.73Ghz centrino, 512mb ram, win xp sp2)

Edited by smashly

Share this post


Link to post
Share on other sites

Two very good observations.

Can you shorten these lines in your script please

Very annoying this. I've had this happen to me.

I would like to fix this, but I can't edit this post.

A minute after posting I noticed a spelling error. Could not edit then and I can not edit it now. The post will not appear in the edit box for editing. The weird thing is I can edit every other post I have ever made.

But CPU usage is always @ 100% unless disassembling or reassembling the clock in which case it sits @ 80% while the transition happens. ...

This world clock is a good example of what can be done, and a good example of what not to do. 100% CPU usage is totally unacceptable. To fix this would mean a rewrite correcting the logical flow. I have Draw() and Drawb2() in a loop. Each of these call another four functions. Most of the script is being used in every loop. It is lucky the CPU usage only goes up to 100.

It seemed like a good idea at the time.

Thanks smashly. I didn't see it.

Share this post


Link to post
Share on other sites

I`ve playing with your updated Clock example and tried to add a background to the text, but it does`nt work properly....

; ==================================================================================
; Draw Time background
; ==================================================================================
Func TimeFaceDraw ()
    Local $aFace
    $aFace = ResourceInit(200, 150)
    $aFace[$eBrush] = _GDIPlus_BrushCreateSolid (0xFFE0FFFF)
;  _GDIPlus_GraphicsFillEllipse($aFace[$eGraphic],  0, 100, 200, 50, $aFace[$eBrush] )   ;this works
      _GDIPlus_GraphicsFillRect($aFace[$eGraphic],  0, 100, 200, 50, $aFace[$eBrush] )   ;this not working properly. not moveable
   ResourceSet ($hTimeFace, $aFace, $iFaceOpacity)
    ResourceDone($aFace)
EndFunc
An Ellipse draws fine, but when I try to use a rectangle, its not movable and is "overwritten" by moving the other windows.

What am I missing?

Thanks for your help.


2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites

An Ellipse draws fine, but when I try to use a rectangle, its not movable and is "overwritten" by moving the other windows.

What am I missing?

I did some experimenting with the following script.

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <misc.au3>

Global Const $iOpacity = 220
Global Const $ULW_ALPHA = 2
Global $hGui, $hGraphic, $hBrush, $hPen, $hBrush
Global $dll = DllOpen("user32.dll")
Global $GuiSize = @DesktopWidth / 4  ; 200 ;
Global Const $WM_LBUTTONDOWN = 0x0201  ; Drag Window 1 of 3 addin

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Rectangles()

Func Rectangles()
    Local $hWnd, $hDC, $hBitmap, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend,$hPen
     
    $hGui = GUICreate("GDI Rectangles", 100, 200, -1, -1, 0, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUIRegisterMsg($WM_LBUTTONDOWN, "_WinMove")    ; Drag Window 2 of 3 addin
    ;GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
    GUISetState()
    _GDIPlus_Startup ()
    $hWnd = _WinAPI_GetDC (0)
    $hDC = _WinAPI_CreateCompatibleDC ($hWnd)
    $hBitmap = _WinAPI_CreateCompatibleBitmap ($hWnd, $GuiSize, $GuiSize)
    _WinAPI_SelectObject ($hDC, $hBitmap)
    $hGraphic = _GDIPlus_GraphicsCreateFromHDC ($hDC)
    $hBrush = _GDIPlus_BrushCreateSolid (Random(0xff000000, 0xffffff00, 1)) 
    
     _GDIPlus_GraphicsFillRect ($hGraphic, 0, 0,150, 200, $hBrush)  ;this not moveable
     
      $hPen = _GDIPlus_PenCreate(0xFF000000, 5)
     _GDIPlus_GraphicsDrawRect ($hGraphic, 0, 0,150, 200,$hPen) ; Border is moveable

    _GDIPlus_GraphicsFillEllipse ($hGraphic, 0, 0, 10, 10, $hBrush)  ;this  is moveable
    
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $GuiSize)
    DllStructSetData($tSize, "Y", $GuiSize)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow ($hGui, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _GDIPlus_PenDispose ($hPen)
    _GDIPlus_BrushDispose ($hBrush)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _WinAPI_ReleaseDC (0, $hWnd)
    _WinAPI_DeleteObject ($hBitmap)
    _WinAPI_DeleteDC ($hDC)
    
    Do
        Sleep(20)
    Until _IsPressed("1B")  ; ESC key
    DllClose($dll)
    _GDIPlus_Shutdown ()
EndFunc   ;==>Rectangles

#cs
    ; ============================================================================
    ; Handle the WM_NCHITTEST message so our window can be dragged
    ; ============================================================================
    Func WM_NCHITTEST($HWnd, $iMsg, $iwParam, $ilParam)
    if $HWnd = $hGui then Return $HTCAPTION
    EndFunc
#ce

; =================================================================
; Drag Window 3 of 3 addin
; =================================================================
Func _WinMove($hWnd, $Command, $wParam, $lParam)
    If BitAND(WinGetState($hWnd), 32) Then Return $GUI_RUNDEFMSG
    ;DllCall("user32.dll", "long", "SendMessage", "hwnd", $HWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
    DllCall("user32.dll", "int", "SendMessage", "hWnd", $hWnd, "int", $WM_NCLBUTTONDOWN, "int", $HTCAPTION, "int", 0)
EndFunc   ;==>_WinMove

The only way I could get the FillRect to move was to add a border or in the example, a small ellipse. Both act like drag handles.

Why the _GDIPlus_GraphicsFillRect function by itseft is not dragable, I have no idea.

Comparing the two functions, _GDIPlus_GraphicsFillRect and _GDIPlus_GraphicsFillEllipse in the GDIPlus.au3 include file, they are almost identical.

The WinMove function possibly could to be modified to recognize the _GDIPlus_GraphicsFillRect. I tried, couldn't do it.

Best of luck.

Share this post


Link to post
Share on other sites

I did some experimenting with the following script.

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <misc.au3>

Global Const $iOpacity = 220
Global Const $ULW_ALPHA = 2
Global $hGui, $hGraphic, $hBrush, $hPen, $hBrush
Global $dll = DllOpen("user32.dll")
Global $GuiSize = @DesktopWidth / 4  ; 200 ;
Global Const $WM_LBUTTONDOWN = 0x0201  ; Drag Window 1 of 3 addin

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Rectangles()

Func Rectangles()
    Local $hWnd, $hDC, $hBitmap, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend,$hPen
     
    $hGui = GUICreate("GDI Rectangles", 100, 200, -1, -1, 0, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUIRegisterMsg($WM_LBUTTONDOWN, "_WinMove")    ; Drag Window 2 of 3 addin
    ;GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
    GUISetState()
    _GDIPlus_Startup ()
    $hWnd = _WinAPI_GetDC (0)
    $hDC = _WinAPI_CreateCompatibleDC ($hWnd)
    $hBitmap = _WinAPI_CreateCompatibleBitmap ($hWnd, $GuiSize, $GuiSize)
    _WinAPI_SelectObject ($hDC, $hBitmap)
    $hGraphic = _GDIPlus_GraphicsCreateFromHDC ($hDC)
    $hBrush = _GDIPlus_BrushCreateSolid (Random(0xff000000, 0xffffff00, 1)) 
    
     _GDIPlus_GraphicsFillRect ($hGraphic, 0, 0,150, 200, $hBrush)  ;this not moveable
     
      $hPen = _GDIPlus_PenCreate(0xFF000000, 5)
     _GDIPlus_GraphicsDrawRect ($hGraphic, 0, 0,150, 200,$hPen) ; Border is moveable

    _GDIPlus_GraphicsFillEllipse ($hGraphic, 0, 0, 10, 10, $hBrush)  ;this  is moveable
    
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $GuiSize)
    DllStructSetData($tSize, "Y", $GuiSize)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow ($hGui, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _GDIPlus_PenDispose ($hPen)
    _GDIPlus_BrushDispose ($hBrush)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _WinAPI_ReleaseDC (0, $hWnd)
    _WinAPI_DeleteObject ($hBitmap)
    _WinAPI_DeleteDC ($hDC)
    
    Do
        Sleep(20)
    Until _IsPressed("1B")  ; ESC key
    DllClose($dll)
    _GDIPlus_Shutdown ()
EndFunc   ;==>Rectangles

#cs
    ; ============================================================================
    ; Handle the WM_NCHITTEST message so our window can be dragged
    ; ============================================================================
    Func WM_NCHITTEST($HWnd, $iMsg, $iwParam, $ilParam)
    if $HWnd = $hGui then Return $HTCAPTION
    EndFunc
#ce

; =================================================================
; Drag Window 3 of 3 addin
; =================================================================
Func _WinMove($hWnd, $Command, $wParam, $lParam)
    If BitAND(WinGetState($hWnd), 32) Then Return $GUI_RUNDEFMSG
    ;DllCall("user32.dll", "long", "SendMessage", "hwnd", $HWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
    DllCall("user32.dll", "int", "SendMessage", "hWnd", $hWnd, "int", $WM_NCLBUTTONDOWN, "int", $HTCAPTION, "int", 0)
EndFunc   ;==>_WinMove

The only way I could get the FillRect to move was to add a border or in the example, a small ellipse. Both act like drag handles.

Why the _GDIPlus_GraphicsFillRect function by itseft is not dragable, I have no idea.

Comparing the two functions, _GDIPlus_GraphicsFillRect and _GDIPlus_GraphicsFillEllipse in the GDIPlus.au3 include file, they are almost identical.

The WinMove function possibly could to be modified to recognize the _GDIPlus_GraphicsFillRect. I tried, couldn't do it.

Best of luck.

Thanks for taking the time anyway, maybe a way to spoof a filled rectangle using nested rectangles with a thick pen, I`ll give that a try.

2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

This works...

Update, Time text is now in front of the background.

Func TimeFaceDraw ()
    Local $aBack, $hPen
    Local $aDot, $Wdt = 30, $Pixel = 2, $hgt
   $aBack = ResourceInit($iRadius * 2, $iRadius * 2)
;$aBack[$eBrush] = _GDIPlus_BrushCreateSolid (0xFFE0FFFF)
    
    $hPen = _GDIPlus_PenCreate(0xFFE0FFFF, $Wdt, $Pixel); Ellipse/Circle  or Line width
    _GDIPlus_GraphicsDrawRect($aBack[$eGraphic], 0, 90, 220, $Wdt, $hPen)       ;works, spoofs a fill by increasing the line width
    _GDIPlus_PenDispose ($hPen)
    ResourceSet ($hTimeFace, $aBack, $iFaceOpacity) 
            $iRet = DllCall("User32.dll", "int", "SetWindowPos", "Hwnd", $hTime, "Hwnd", $hTimeFace, _
           "int", 100, "int", 100, "int", 100, "int", 100, "uint", $SWP_NOSIZE + $SWP_NOMOVE)   ; Z-order $hTimeFace sent to back.   
    ResourceDone($aBack)
EndFunc
Edited by Lakes

2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites

I`ve playing with your updated Clock example and tried to add a background to the text, but it does`nt work properly....

To add a background to the text, this works.

Around line 590 is the function that writes the text on screen. i've added a colour brush to the existing _GDIPlus_GraphicsFillRect function.

This FillRect can be dragged by the text on that gui.

; ============================================================================
; Draw the digital time
; ============================================================================
Func TimeDraw($hr,$min, $day,  $dayno,$Mth, $yr)
  Local $sString, $aSize,$hBrushBkGnd
  if ($aLast[0][0] = $aCurr[0][0]) and ($aLast[0][1] = $aCurr[0][1]) then Return
  $sString = StringFormat(" %02d:%02d:%02d %s, %02d %s %02d %s", $hr , $min, @SEC, $day,$dayno,$Mth, $yr, $locname)
  $aSize   = _GDIPlus_GraphicsMeasureString($aTime[$eGraphic], $sString, $aTime[$eFont], $aTime[$eLayout], $aTime[$eFormat])
  DllStructSetData($aTime[$eLayout], "X", $iRadius - (DllStructGetData($aSize[0], "Width") / 2))
  DllStructSetData($aTime[$eLayout], "Y", $iRadius*2/ 3)
  $hBrushBkGnd = _GDIPlus_BrushCreateSolid (0xFFE0FFFF) 
  _GDIPlus_GraphicsFillRect($aTime[$eGraphic], 0, 48, $iRadius * 2,40, $hBrushBkGnd)
  _GDIPlus_GraphicsDrawStringEx($aTime[$eGraphic], $sString, $aTime[$eFont], $aTime[$eLayout], $aTime[$eFormat], $aTime[$eBrush])
  ResourceSet($hTime, $aTime)
EndFunc

Share this post


Link to post
Share on other sites

To add a background to the text, this works.

Around line 590 is the function that writes the text on screen. i've added a colour brush to the existing _GDIPlus_GraphicsFillRect function.

This FillRect can be dragged by the text on that gui.

; ============================================================================
; Draw the digital time
; ============================================================================
Func TimeDraw($hr,$min, $day,  $dayno,$Mth, $yr)
  Local $sString, $aSize,$hBrushBkGnd
  if ($aLast[0][0] = $aCurr[0][0]) and ($aLast[0][1] = $aCurr[0][1]) then Return
  $sString = StringFormat(" %02d:%02d:%02d %s, %02d %s %02d %s", $hr , $min, @SEC, $day,$dayno,$Mth, $yr, $locname)
  $aSize   = _GDIPlus_GraphicsMeasureString($aTime[$eGraphic], $sString, $aTime[$eFont], $aTime[$eLayout], $aTime[$eFormat])
  DllStructSetData($aTime[$eLayout], "X", $iRadius - (DllStructGetData($aSize[0], "Width") / 2))
  DllStructSetData($aTime[$eLayout], "Y", $iRadius*2/ 3)
  $hBrushBkGnd = _GDIPlus_BrushCreateSolid (0xFFE0FFFF) 
  _GDIPlus_GraphicsFillRect($aTime[$eGraphic], 0, 48, $iRadius * 2,40, $hBrushBkGnd)
  _GDIPlus_GraphicsDrawStringEx($aTime[$eGraphic], $sString, $aTime[$eFont], $aTime[$eLayout], $aTime[$eFormat], $aTime[$eBrush])
  ResourceSet($hTime, $aTime)
EndFuncoÝ÷ Ûú®¢×©ä±»­¶¬²Ø¥Ê+®êm²Ø^)eü¨¹Úک趫rZÊ&¦ÞÚ/z¸­²=êYlµ¬°Øn²)තéèø¥çkyËZ   ^Â+ajØbrJ^«-+0¢¹,~)ÞjÆiÉ ®§v+­¨ i¹^o'%É"§Ë^­ê'Ö§v+'¢×(®»©µç[Ê)íz¶¶*'Â+a¢Ø^­ÉhrG('z{lêÞ÷«-ê-êéj»H÷«Þj[^­çl¢ØZ¶Ø^¶)µìmjÊË-k*'¶h~Ø^)$º.Ö®¶­scÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓУ²G&rFRFvFÂFÖRæB6VæBFòg&öç@£²ÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓÓФgVæ2FÖTG&rb33c¶"Âb33c¶ÖâÂb33c¶FÂb33c¶FæòÂb33c´×FÂb33c·"¢Æö6Âb33c·57G&ærÂb33c¶6¦R¢bb33c¶Æ7E³Õ³ÒÒb33c¶7W'%³Õ³ÒæBb33c¶Æ7E³Õ³ÒÒb33c¶7W'%³Õ³ÒFVâ&WGW&à¢b33c·57G&ærÒ7G&ætf÷&ÖBgV÷C²S&C¢S&C¢S&BW2ÂS&BW2S&BW2gV÷C²Âb33c¶"Âb33c¶ÖâÂ4T2Âb33c¶FÂb33c¶FæòÂb33c´×FÂb33c·"Âb33c¶Æö6æÖR¢b33c¶6¦RÒôtDÇW5ôw&74ÖV7W&U7G&ærb33c¶FÖU²b33c¶Tw&5ÒÂb33c·57G&ærÂb33c¶FÖU²b33c¶TföçEÒÂb33c¶FÖU²b33c¶TÆ÷WEÒÂb33c¶FÖU²b33c¶Tf÷&ÖEÒ¢FÆÅ7G'V7E6WDFFb33c¶FÖU²b33c¶TÆ÷WEÒÂgV÷CµgV÷C²Âb33c¶&FW2ÒFÆÅ7G'V7DvWDFFb33c¶6¦U³ÒÂgV÷CµvGFgV÷C²ò"¢FÆÅ7G'V7E6WDFFb33c¶FÖU²b33c¶TÆ÷WEÒÂgV÷CµgV÷C²Âb33c¶&FW2£"ò2¢ôtDÇW5ôw&74fÆÅ&V7Bb33c¶FÖU²b33c¶Tw&5ÒÂÂÂb33c¶&FW2¢"Âb33c¶&FW2¢"¢ôtDÇW5ôw&74G&u7G&ætWb33c¶FÖU²b33c¶Tw&5ÒÂb33c·57G&ærÂb33c¶FÖU²b33c¶TföçEÒÂb33c¶FÖU²b33c¶TÆ÷WEÒÂb33c¶FÖU²b33c¶Tf÷&ÖEÒÂb33c¶FÖU²b33c¶T''W6Ò¢&W6÷W&6U6WBb33c¶FÖRÂb33c¶FÖR b33c¶&WBÒFÆÄ6ÆÂgV÷CµW6W#3"æFÆÂgV÷C²ÂgV÷C¶çBgV÷C²ÂgV÷Cµ6WEvæF÷u÷2gV÷C²ÂgV÷C´væBgV÷C²Âb33c¶FÖTf6RÂgV÷C´væBgV÷C²Âb33c¶FÖRÂð gV÷C¶çBgV÷C²ÂÂgV÷C¶çBgV÷C²ÂÂgV÷C¶çBgV÷C²ÂÂgV÷C¶çBgV÷C²ÂÂgV÷C·VçBgV÷C²Âb33cµ5uôäõ4¤R²b33cµ5uôäôÔõdR²¢Ö÷&FW"b33c¶FÖTf6R6VçBFò&6²à¤VæDgVæ
I do appreciate your help though, I`m learning a lot tinkering with this.

2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites

#11 ·  Posted

I have reduced the above clock to its basics. And added a graphics which can be found at

http://www.autoitscript.com/forum/index.php?s=&showtopic=64569&view=findpost&p=483796

The script below is only a static example of what is possible. All the _GDIPlus_MatrixRotate()'s does slow things down. There would be a better way of producing the same effect.

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <GuiConstantsEx.au3>

; =================================================================
; Description ...: Modified script  of Clock.au3 
; Author ........: Paul Campbell (PaulIA)
; Notes .........:
; =================================================================

; ================================================================
; Global constants
; =================================================================
Global Const $iOpacity          = 128
Global Const $nPI               = 3.1415926535897932384626433832795
Global Const $WM_LBUTTONDOWN = 0x0201  ; Drag Window 1 of 3 addin
Global Const $AC_SRC_ALPHA      = 1
Global Const $ULW_ALPHA         = 2
Global Enum $eScrDC=0, $eMemDC, $eBitmap, $eWidth, $eHeight, $eGraphic, $ePen, $eCap, $eBrush, $eFormat, $eFamily, $eFont, $eLayout, $eLast
 
; =================================================================
; Global variables
; =================================================================
Global $MenuItemExit, $ContextMenu, $separator1, $hRotate, $Msg
Global $user32_dll = DllOpen ("user32.dll")
Global $iRadius    = 200, $f = 1

; =================================================================
; Main
; =================================================================
Opt("MustDeclareVars", 1)
Opt ("GUIOnEventMode", 1)

ClockInit()
RotateDraw()
ClockLoop()
ClockDone()

; ===============================================================
; Finalize clock
; ===============================================================
Func ClockDone()
     
  ; Finalize GDI+ library
  _GDIPlus_Shutdown()
EndFunc

; ==============================================================
; Initialize clock
; ==============================================================
Func ClockInit()
  Local $iX, $iY

  ; Calculate the dial frame caption size
  $iX = -(_WinAPI_GetSystemMetrics($SM_CXFRAME))
  $iY = -(_WinAPI_GetSystemMetrics($SM_CYCAPTION) + _WinAPI_GetSystemMetrics($SM_CYFRAME)) 
  
  $hRotate = GUICreate("Rotate", $iRadius * 2, $iRadius * 2,  -1,  -1, 0, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
  
  $ContextMenu = GUICtrlCreateContextMenu ()
    $separator1 = GUICtrlCreateMenuitem ("",$ContextMenu)   ; create a separator line   
    $MenuItemExit = GUICtrlCreateMenuitem ("Exit", $ContextMenu)
        GUICtrlSetOnEvent ($MenuItemExit, "quitclk")  
  
  GuiRegisterMsg($WM_LBUTTONDOWN, "_WinMove")    ; Drag Window 2 of 3 addin
  GUISetState()
  
  ; Initialize GDI+ library
  _GDIPlus_Startup()
EndFunc

; =============================================================
; Loop until user exits
; =============================================================
Func ClockLoop()    
  do
      sleep(250)
    ;RotateDraw()
  until $Msg = $GUI_EVENT_CLOSE
EndFunc


; ===========Start of  _GDIPlus_MatrixRotate() Example ==========
; ===============================================================
; Draw Rotated text from 
;http://www.autoitscript.com/forum/index.php?s=&showtopic=64569&view=findpost&p=483796
; ===============================================================


Func RotateDraw()
    Local $aRotate, $F = 1
    if $f = 1 then
    $aRotate = ResourceInit( 400,300)
    ;DrawGraphic(          $hGraphic, $nX, $nY, $nAngle,    $iWidth,    $iHeight, $iARGB = 0xFF000000)
    ;Cross
     DrawGraphic($aRotate[$eGraphic], 120, 150,      45,        100,          20,          0xFFFF8000)
     DrawGraphic($aRotate[$eGraphic], 120, 150,     135,        100,          20,          0xFF00FF00)
     DrawGraphic($aRotate[$eGraphic], 120, 150,     225,        100,          20,          0xFF0505FB)
     DrawGraphic($aRotate[$eGraphic], 120, 150,     315,        100,          20,          0xFFFF00FF)
    
    ;Square
     DrawGraphic($aRotate[$eGraphic], 260, 200,       0,        100,          20,          0xFFFF8000)
     DrawGraphic($aRotate[$eGraphic], 260, 100,      90,        100,          20,          0xFF00FF00)
     DrawGraphic($aRotate[$eGraphic], 360, 100,     180,        100,          20,          0xFF0505FB)
     DrawGraphic($aRotate[$eGraphic], 360, 200,     270,        100,          20,          0xFFFF00FF)
     $f = 2
    endif
     ResourceSet ($hRotate, $aRotate, $iOpacity)
    ResourceDone($aRotate)
EndFunc 

Func DrawGraphic($hGraphic, $nX, $nY, $nAngle, $nWidth, $nHeight, $iARGB = 0xFF000000)
    Local $hMatrix, $nXt, $nYt, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
    ; $nXt     - The X coordinate of the upper left corner of the Graphics object before rotation 
    ; $nYt     - The Y coordinate of the upper left corner of the Graphics object before rotation
    
    ;Rotation Matrix
    $hMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixRotate($hMatrix, $nAngle, "False")   
    _GDIPlus_GraphicsSetTransform($hGraphic , $hMatrix) 
    
    ;Rotation of Coordinate Axes formulae
    $nXt = $nX*cos($nAngle*$nPI/180) + $nY*sin($nAngle*$nPI/180)  ; $nXt - X coordinate before translation 
    $nYt = -$nX*sin($nAngle*$nPI/180) + $nY*cos($nAngle*$nPI/180) ; $nYt - Y coordinate before translation
    
    $hBrush  = _GDIPlus_BrushCreateSolid ($iARGB)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    $hFont   = _GDIPlus_FontCreate ($hFamily, 12, 1)
    $tLayout = _GDIPlus_RectFCreate ( $nXt, $nYt, $nWidth, $nHeight )
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, "Autoit Sang", $hFont, $tLayout, $hFormat, $hBrush)
    Sleep(1000) 
    
    ; Clean up resources    
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose ($hBrush) 
    Return 1
EndFunc
; ====================================================================
; ==================>End of _GDIPlus_MatrixRotate() Example ==========


; ====================================================================
; Finalize drawing resources
; ====================================================================
Func ResourceDone(ByRef $aInfo)
  _GDIPlus_GraphicsDispose($aInfo[$eGraphic])
  _WinAPI_ReleaseDC   (0, $aInfo[$eScrDC])
  _WinAPI_DeleteObject($aInfo[$eBitmap])
  _WinAPI_DeleteDC    ($aInfo[$eMemDC ])
EndFunc

; ===================================================================
; Initialize bitmap resources
; ===================================================================
Func ResourceInit($iWidth, $iHeight)
  Local $aInfo[$eLast + 1]

  $aInfo[$eScrDC  ] = _WinAPI_GetDC(0)
  $aInfo[$eMemDC  ] = _WinAPI_CreateCompatibleDC($aInfo[$eScrDC])
  $aInfo[$eBitmap ] = _WinAPI_CreateCompatibleBitmap($aInfo[$eScrDC], $iWidth, $iHeight)
  _WinAPI_SelectObject($aInfo[$eMemDC], $aInfo[$eBitmap])
  $aInfo[$eWidth  ] = $iWidth
  $aInfo[$eHeight ] = $iHeight
  $aInfo[$eGraphic] = _GDIPlus_GraphicsCreateFromHDC($aInfo[$eMemDC])
  _GDIPlus_GraphicsFillRect($aInfo[$eGraphic], 0, 0, $iRadius * 2, $iRadius * 2)
  Return $aInfo
EndFunc

; ==================================================================
; Update layered window with resource information
; ==================================================================
Func ResourceSet($hGUI, ByRef $aInfo, $iAlpha=-1)
  Local $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  if $iAlpha = -1 then $iAlpha = $iOpacity
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", $aInfo[$eWidth ])
  DllStructSetData($tSize, "Y", $aInfo[$eHeight])
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend )
  DllStructSetData($tBlend, "Alpha" , $iAlpha      )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $aInfo[$eScrDC], 0, $pSize, $aInfo[$eMemDC], $pSource, 0, $pBlend, $ULW_ALPHA)
EndFunc

; ==================================================================
; Exit program
; ==================================================================
Func quitclk()
    $Msg = $GUI_EVENT_CLOSE 
EndFunc  

; ================================================================= 
; Drag Window 3 of 3 addin
; =================================================================
Func _WinMove($HWnd, $Command, $wParam, $lParam)    
     If BitAND(WinGetState($HWnd), 32) Then Return $GUI_RUNDEFMSG
    ;DllCall("user32.dll", "long", "SendMessage", "hwnd", $HWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
    dllcall("user32.dll","int","SendMessage","hWnd", $HWnd, "int",$WM_NCLBUTTONDOWN,"int", $HTCAPTION,"int", 0)     
EndFunc
A sleep() command in the Do - Until loop reduced the CPU usage of 100% to single figure usage.

An AutoIt Forum search for "CPU usage" gave me the answer I desperately needed.

I`ve noticed that the value for the text colour has an extra pair, $iArgb, ( RGB I understand, 0xFFFFFF = White) is the first pair for Alfachannel or something?, its not explained in the help file...

Thanks.


2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I`ve noticed that the value for the text colour has an extra pair, $iArgb, ( RGB I understand, 0xFFFFFF = White) is the first pair for Alfachannel or something?, its not explained in the help file...

Thanks.

There are a few colour formats, Argb (Alpha Red Green Blue) is one of them. Most often use for transparency.

In the script, it is used in the $pBlend structure.

$pBlend = DllStructGetPtr($tBlend )

DllStructSetData($tBlend, "Alpha" , $iAlpha )

DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)

_WinAPI_UpdateLayeredWindow($hGUI, $aInfo[$eScrDC], 0, $pSize, $aInfo[$eMemDC], $pSource, 0, $pBlend, $ULW_ALPHA)

Here $iAlpha, $AC_SRC_ALPHA are declared Global Constants. A lot of scripts use $iOpacity variable instead these constants.

There is a lot of info out there on ARGB. Google search or

http://en.wikipedia.org/wiki/RGBA_color_space.

That's my understanding of Argb. Probably a lot more to to it. There always is.

Edit: If anyone is interested, I got the _GDIPlus_BitmapLockBits() function to work. It locks a portion of a bitmap for reading or writing.

I experimented with the Alpha in this script. I posted it here.

http://www.autoitscript.com/forum/index.ph...st&p=513443

It is an inefficient script. I kept adding to the write colour (pixel) section to see what resulted.

Edited by Malkey

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I`ve been trying to rotate a Picture the same as the Fonts example, without success...

Probably missing something simple, but my brain hurts from this GDI stuff...:):(

Here`s what I have,

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <GuiConstantsEx.au3>
#include <Math.au3>
#include <ScreenCapture.au3>

; =================================================================
; Description ...: Modified script  of Clock.au3 
; Author ........: Paul Campbell (PaulIA)
; Notes .........:
; =================================================================

; ================================================================
; Global constants
; =================================================================
Global Const $iOpacity          = 250
Global Const $nPI               = 3.1415926535897932384626433832795
Global Const $WM_LBUTTONDOWN = 0x0201  ; Drag Window 1 of 3 addin
Global Const $AC_SRC_ALPHA      = 1
Global Const $ULW_ALPHA         = 2
Global Enum $eScrDC=0, $eMemDC, $eBitmap, $eWidth, $eHeight, $eGraphic, $ePen, $eCap, $eBrush, $eFormat, $eFamily, $eFont, $eLayout, $eLast
 
Global $aPen, $aRect, $aPointer, $aPic, $WinWd, $WinHgt, $hRect,$hImage, $hDot, $aImage
Global $hGUI2, $hPic, $hMatrix, $nAngle, $iRet, $hCross, $aCross, $aDot, $iN, $hBitmap
; =================================================================
; Global variables
; =================================================================
Global $MenuItemExit, $ContextMenu, $separator1, $hFontRotate, $hPointer, $Msg
Global $user32_dll = DllOpen ("user32.dll")
Global $iRadius    = 200, $f = 1

HotKeySet("{ESC}", "quitclk")

Dim $Color[46]  =   [0, 0xff7E0000, 0xffBE0000, 0xffFE0000, 0xffFE8080, 0xffFFBFBF, _ 
                    0xff7E4F00, 0xffBF7700, 0xffFF9F00, 0xffFECF7F, 0xffFFE8BF, _
                    0xff7F8000, 0xffBFBF00, 0xffFFFF00, 0xffFFFF80, 0xffFFFFBF, _
                    0xff017F01, 0xff00BF00, 0xff00FF00, 0xff80FF80, 0xffBFFFC0, _
                    0xff007F7E, 0xff00C0BF, 0xff00FFFF, 0xff7FFFFE, 0xffBFFFFF, _
                    0xff002F7F, 0xff0048C0, 0xff0060FF, 0xff8180FF, 0xffBFD6FF, _
                    0xff5A007E, 0xff8F00BF, 0xffB400FF, 0xffDA7FFE, 0xffECC0FF, _
                    0xff7E007E, 0xffB700BF, 0xffFF00FF, 0xffFE80FE, 0xffFFBEFE, _
                    0xff000000, 0xff7D7D7D, 0xffA9A9A9, 0xffD4D4D4, 0xffFFFFFF]

; =================================================================
; Main
; =================================================================
Opt("MustDeclareVars", 1)
Opt ("GUIOnEventMode", 1)

ClockInit()
Rectinit()
RectDraw()
FontRotateDraw()

ClockLoop()
ClockDone()

; ===============================================================
; Finalize clock
; ===============================================================
Func ClockDone()
     
  ; Finalize GDI+ library
RectDone()
PicDone()

  _GDIPlus_Shutdown()
    DllClose($user32_dll)
EndFunc

; ==============================================================
; Initialize clock
; ==============================================================
Func ClockInit()
  Local $iX, $iY

  ; Calculate the dial frame caption size
  $iX = -(_WinAPI_GetSystemMetrics($SM_CXFRAME))
  $iY = -(_WinAPI_GetSystemMetrics($SM_CYCAPTION) + _WinAPI_GetSystemMetrics($SM_CYFRAME)) 
  $WinWd  = $iRadius * 2
  $WinHgt = $iRadius * 2

  $hRect   = GUICreate("Rectangle", $WinWd, $WinHgt, 200,  200, 0, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUISetCursor (9, 1, $hRect)
    GuiRegisterMsg($WM_LBUTTONDOWN, "_WinMove")    ; Drag Rectangle
    GUISetState() 
  $hFontRotate = GUICreate("FontRotate", $WinWd, $WinHgt, $iX,  $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hRect)
    GUISetState()
    
; Hook non client hit test message so we can move the clock
  ;GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

  $ContextMenu = GUICtrlCreateContextMenu ()
    $separator1 = GUICtrlCreateMenuitem ("",$ContextMenu)   ; create a separator line   
    $MenuItemExit = GUICtrlCreateMenuitem ("Exit", $ContextMenu)
        GUICtrlSetOnEvent ($MenuItemExit, "quitclk")  
  
  GuiRegisterMsg($WM_LBUTTONDOWN, "_WinMove")    ; Drag Window 2 of 3 addin
  
  ; Initialize GDI+ library
  _GDIPlus_Startup()
  
$hPic = GUICreate("Test", $WinWd, $WinHgt, -1, -1, -1, BitOr($WS_EX_LAYERED, $WS_EX_MDICHILD), $hRect)
;$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Images\Image.png") ; Image = Sm0ke N... http://www.autoitscript.com/forum/uploads/av-4813.png
GUISetState()

    ; Capture screen region
    $hBitmap = _ScreenCapture_Capture ("", 0, 0, 150, 150) 
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap)
   

;SetBitmap($hGUI, $hImage, $iOpacity)
;SetBitMap($hPic,  $hImage,  200)
;SetBitMap($hPic,  $hImage,  200)

PicInit()
PicRotate($hPic, $hImage, 200, 200, 30) 
SetBitMap($hPic,  $hImage,  200)

;GUISetState()
EndFunc

; =============================================================
; Loop until user exits
; =============================================================
Func ClockLoop()    
  do
      sleep(250)
  until $Msg = $GUI_EVENT_CLOSE
EndFunc


; ===========Start of  _GDIPlus_MatrixRotate() Example ==========
; ===============================================================
; Draw Rotated text from 
;http://www.autoitscript.com/forum/index.php?s=&showtopic=64569&view=findpost&p=483796
; ===============================================================
Func FontRotateDraw()
    Local $aRotate, $aDrawrect, $iARgb,  $F = 1, $DrawRect, $Rx = 200, $Ry = 200, $iWd = 190
;Font Rotate
    $aRotate = ResourceInit($WinWd,$WinHgt)
    ;DrawGraphic($hGraphic, $Rx, $Ry, $nAngle,  $iWidth,    $iHeight, $iARGB = 0xFF000000)
    For $iAng = 0 to 360 step 12
                $iN += 1
        ;tooltip ("Colour Number = " &$iN &" Colour = " &Hex ($Color[$iN]))
         FontRotate($aRotate[$eGraphic], $Rx, $Ry, $iAng,   $iWd,       20,       $Color[$iN])  
        sleep(10)
     Next    
     ResourceSet ($hFontRotate, $aRotate, $iOpacity)
    ResourceDone($aRotate)

EndFunc 

; =============================================================================
; Initialize resources for Picture
; =============================================================================
Func PicInit()
    $aPic = ResourceInit($iRadius * 2, $iRadius * 2)        ; Need to pass the image here.....
EndFunc

; =============================================================================
; Rotate Picture
; =============================================================================
    ;Rotation Matrix
Func PicRotate($hgraphic, $hImage, $nX, $nY, $nAngle)
    Local $nXt, $nYt
    $hMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixRotate($hMatrix, $nAngle, "False")   
    
    _GDIPlus_GraphicsSetTransform($hGraphic , $hMatrix) 
    _GDIPlus_GraphicsDrawImage ($hGraphic, $hImage, $nX, $nY)   
    ;Rotation of Coordinate Axes formulae
    $nXt = $nX*cos($nAngle*$nPI/180) + $nY*sin($nAngle*$nPI/180)  ; $nXt - X coordinate before translation 
    $nYt = -$nX*sin($nAngle*$nPI/180) + $nY*cos($nAngle*$nPI/180) ; $nYt - Y coordinate before translation
    ;ResourceSet ($hGraphic, $aPic, $iOpacity)  ;$aPic from resource init 
    _GDIPlus_ImageSaveToFile ($hImage, @ScriptDir & "\GDIPlus_Image.jpg")
EndFunc

Func PicDone()
      _GDIPlus_MatrixDispose($hMatrix)
      ResourceDone($aPic)
EndFunc   

; =============================================================================
; Initialize resources for Rectangle
; =============================================================================
Func RectInit()
  $aRect = ResourceInit($WinWd, $WinHgt )
  $aRect[$ePen] = _GDIPlus_PenCreate(0xFF000000 ,10, 2)   ;Colour, LineWidth, Pixels
EndFunc

; =============================================================================
; Draw Rectangle
; =============================================================================
Func RectDraw()
        _GDIPlus_GraphicsDrawRect($aRect[$eGraphic], 4, 4, $WinWd - 10, $WinHgt - 10, $aRect[$ePen])
        ResourceSet ($hRect, $aRect, $iOpacity)
#cs     
    $iRet = DllCall("User32.dll", "int", "SetWindowPos", "Hwnd", $hRotate, "Hwnd", $hRect, _
    "int", 100, "int", 100, "int", 100, "int", 100, "uint", $SWP_NOSIZE + $SWP_NOMOVE)                      ; Z-order sent to back.
#ce
EndFunc

; =============================================================================
; Finalize resources for the Rectangle
; ==============================================================================
Func RectDone()
  _GDIPlus_PenDispose($aRect[$ePen])
  ResourceDone($aRect)
EndFunc

; ============================================================================
; Handle the WM_NCHITTEST message so our window can be dragged
; ============================================================================
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    if $hWnd = $hRect then Return $HTCAPTION
EndFunc 

; ==============================================================================
;Rotate!
; ==============================================================================
Func FontRotate($hGraphic, $nX, $nY, $nAngle, $nWidth, $nHeight, $iARGB)
    Local $hMatrix, $nXt, $nYt, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
    ; $nXt     - The X coordinate of the upper left corner of the Graphics object before rotation 
    ; $nYt     - The Y coordinate of the upper left corner of the Graphics object before rotation
    
    ;Rotation Matrix
    $hMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixRotate($hMatrix, $nAngle, "False")   
    _GDIPlus_GraphicsSetTransform($hGraphic , $hMatrix) 
    
    ;Rotation of Coordinate Axes formulae
    $nXt = $nX*cos($nAngle*$nPI/180) + $nY*sin($nAngle*$nPI/180)  ; $nXt - X coordinate before translation 
    $nYt = -$nX*sin($nAngle*$nPI/180) + $nY*cos($nAngle*$nPI/180) ; $nYt - Y coordinate before translation
    
    $hBrush  = _GDIPlus_BrushCreateSolid ($iARGB)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    $hFont   = _GDIPlus_FontCreate ($hFamily, 14, 1)
    $tLayout = _GDIPlus_RectFCreate ( $nXt, $nYt, $nWidth, $nHeight )
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, "Autoit is Great! " &$iN, $hFont, $tLayout, $hFormat, $hBrush)
    Sleep(10)   
    
    ; Clean up resources    
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose ($hBrush) 
    _GDIPlus_PenDispose($aPen)
    Return 1
EndFunc

; ====================================================================
; ==================>End of _GDIPlus_MatrixRotate() Example ==========


; ====================================================================
; Finalize drawing resources
; ====================================================================
Func ResourceDone(ByRef $aInfo)
  _GDIPlus_GraphicsDispose($aInfo[$eGraphic])
  _WinAPI_ReleaseDC   (0, $aInfo[$eScrDC])
  _WinAPI_DeleteObject($aInfo[$eBitmap])
  _WinAPI_DeleteDC    ($aInfo[$eMemDC ])
EndFunc

; ===================================================================
; Initialize bitmap resources
; ===================================================================
Func ResourceInit($iWidth, $iHeight)
  Local $aInfo[$eLast + 1], $hBitmap

  $aInfo[$eScrDC  ] = _WinAPI_GetDC(0)
  $aInfo[$eMemDC  ] = _WinAPI_CreateCompatibleDC($aInfo[$eScrDC])
  $aInfo[$eBitmap ] = _WinAPI_CreateCompatibleBitmap($aInfo[$eScrDC], $iWidth, $iHeight)
  _WinAPI_SelectObject($aInfo[$eMemDC], $aInfo[$eBitmap])
  $aInfo[$eWidth  ] = $iWidth
  $aInfo[$eHeight ] = $iHeight
  $aInfo[$eGraphic] = _GDIPlus_GraphicsCreateFromHDC($aInfo[$eMemDC])
  _GDIPlus_GraphicsFillRect($aInfo[$eGraphic], 0, 0, $iRadius * 2, $iRadius * 2)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
  Return $aInfo
EndFunc

; ==================================================================
; Update layered window with resource information
; ==================================================================
Func ResourceSet($hGUI, ByRef $aInfo, $iAlpha=-1)
  Local $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  if $iAlpha = -1 then $iAlpha = $iOpacity
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", $aInfo[$eWidth ])
  DllStructSetData($tSize, "Y", $aInfo[$eHeight])
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend )
  DllStructSetData($tBlend, "Alpha" , $iAlpha      )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $aInfo[$eScrDC], 0, $pSize, $aInfo[$eMemDC], $pSource, 0, $pBlend, $ULW_ALPHA)
EndFunc

; ===============================================================================================================================
; SetBitMap
; ===============================================================================================================================
Func SetBitmap($hGUI, $hImage, $iOpacity)
  Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend, $hRotate, $hMatrix, $nXt, $nYt

;Resource Init
  $hScrDC  = _WinAPI_GetDC(0)
  $hMemDC  = _WinAPI_CreateCompatibleDC($hScrDC)
  $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
  $hOld    = _WinAPI_SelectObject($hMemDC, $hBitmap)
;ResourceSet  
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth ($hImage))
  DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend)
  DllStructSetData($tBlend, "Alpha" , $iOpacity    )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
;ResourceDone
  _WinAPI_ReleaseDC   (0, $hScrDC)
  _WinAPI_SelectObject($hMemDC, $hOld)
  _WinAPI_DeleteObject($hBitmap)
  _WinAPI_DeleteDC    ($hMemDC)
EndFunc

; ==================================================================
; Exit program
; ==================================================================
Func quitclk()
    $Msg = $GUI_EVENT_CLOSE 
EndFunc  

; ================================================================= 
; Drag Window 3 of 3 addin
; =================================================================
Func _WinMove($HWnd, $Command, $wParam, $lParam)    
     If BitAND(WinGetState($HWnd), 32) Then Return $GUI_RUNDEFMSG
    ;DllCall("user32.dll", "long", "SendMessage", "hwnd", $HWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
    dllcall("user32.dll","int","SendMessage","hWnd", $HWnd, "int",$WM_NCLBUTTONDOWN,"int", $HTCAPTION,"int", 0)     
EndFunc
Edited by Lakes

2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites

#14 ·  Posted

I`ve been trying to rotate a Picture the same as the Fonts example, without success...

I like your image of the rotated text.

I believe the function your require is _GDIPLus_GraphicsDrawImageRect( ) from the Beta version. I tried adding it to your posted script, but my brain started to hurt.

Here is an example to rotate an image using _GDIPlus_MatrixRotate( ). The _GDIPLus_GraphicsDrawImageRect( ) @ the bottom of script is from the beta version.

#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <StructureConstants.au3>

Global Const $iOpacity = 200
Global Const $ULW_ALPHA = 2
Global $GuiSize = 600
Global Const $nPI = 3.1415926535897932384626433832795
Global $dll = DllOpen("user32.dll")
Global Const $WM_LBUTTONDOWN = 0x0201  ; Drag Window 1 of 3 addin
Global $msg,$hGui
Global Const $tagPOINTF = "float X;float Y" 
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Global $iPath = "C:\Documents and Settings\My Pictures\matcalc.bmp" ;<= Enter your image here.
Global $angle                             ;$nAngle = 0  

GUIRegisterMsg($WM_LBUTTONDOWN, "_WinMove")    ; Drag Window 2 of 3 addin
RotatePiece()
    
Do
    If _IsPressed("20") Or _IsPressed("04") Then    ;   SpaceBar or middle mouse button
        GUIDelete ($hGui)
        $angle = Mod($angle + 10, 360) ; 10deg increments (plus clockwise)
        RotatePiece($angle)
    EndIf
        
    Sleep(100)
Until _IsPressed("1B")  ; ESC key
DllClose($dll)

Func RotatePiece($angle = 0)
    Local $hMatrix, $nX, $nY, $x, $y, $Pos, $radius,  $hGraphic,  $hImage
    Local $hWnd, $hDC, $hBitmap, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend, $nXt, $nYt
    $hGui = GUICreate("GDI+ Rotate", $GuiSize, $GuiSize, 300, 200, 0, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUISetState()
    
    _GDIPlus_Startup ()
    
    $hWnd = _WinAPI_GetDC (0)
    $hDC = _WinAPI_CreateCompatibleDC ($hWnd)
    $hBitmap = _WinAPI_CreateCompatibleBitmap ($hWnd, $GuiSize, $GuiSize)
    _WinAPI_SelectObject ($hDC, $hBitmap)
    $hGraphic = _GDIPlus_GraphicsCreateFromHDC ($hDC)
    $hImage = _GDIPlus_ImageLoadFromFile ($iPath)
    
    $Pos = WinGetPos($hGui)
    $nX = $Pos[0]
    $nY = $Pos[1] 
    
    ;Rotation Matrix
    $hMatrix = _GDIPlus_MatrixCreate ()
    _GDIPlus_MatrixRotate ($hMatrix, $angle, False)
    _GDIPlus_GraphicsSetTransform ($hGraphic, $hMatrix)
    
    $x = ($GuiSize / 2) * Cos($angle * $nPI / 180) - ($GuiSize / 2) + $nX - ($GuiSize / 2) * Sin($angle * $nPI / 180)
        ;Parametric equations for a circle
    $y = ($GuiSize / 2) * Sin($angle * $nPI / 180) - ($GuiSize / 2) + $nY + ($GuiSize / 2) * Cos($angle * $nPI / 180)
        ; and adjusts for center of text box
    
    ;Rotation of Coordinate Axes formulae
    ; $nXt - X coordinate before translation
    $nXt = ($nX - $x) * Cos($angle * $nPI / 180) + ($nY - $y) * Sin($angle * $nPI / 180)
    
    ; $nYt - Y coordinate before translation
    $nYt = -($nX - $x) * Sin($angle * $nPI / 180) + ($nY - $y) * Cos($angle * $nPI / 180)
    
    _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage, $nXt + ($GuiSize*0.2), $nYt + ($GuiSize*0.2) , $GuiSize*0.6, $GuiSize*0.6)
    
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $GuiSize)  ;$iWidth )
    DllStructSetData($tSize, "Y", $GuiSize)  ;$iHeight)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow ($hGui, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    Sleep(500)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_MatrixDispose ($hMatrix)
    _WinAPI_ReleaseDC (0, $hWnd)
    _WinAPI_DeleteObject ($hBitmap)
    _WinAPI_DeleteDC ($hDC)
    _GDIPlus_Shutdown ()
    Return 1
EndFunc   ;==>RotatePiece

; =================================================================
; Drag Window 3 of 3 addin (from AutoIt forum)
; =================================================================
Func _WinMove($hWnd, $Command, $wParam, $lParam)
    If BitAND(WinGetState($hWnd), 32) Then Return $GUI_RUNDEFMSG
    DllCall("user32.dll", "int", "SendMessage", "hWnd", $hWnd, "int", $WM_NCLBUTTONDOWN, "int", $HTCAPTION, "int", 0)
EndFunc   ;==>_WinMove

; This function from GDIPlus.au3 Beta version
Func _GDIPLus_GraphicsDrawImageRect($hGraphics, $hImage, $iX, $iY, $iW, $iH)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipDrawImageRectI", "hwnd", $hGraphics, "hwnd", $hImage, _
            "int", $iX, "int", $iY, "int", $iW, "int", $iH)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPLus_GraphicsDrawImageRect

If you want multiple images, comment out GUIDelete ($hGui).

Hope this helps.

If your look at some of smashly's scripts, example:-

http://www.autoitscript.com/forum/index.ph...st&p=514767

He has an efficient script format and a good handle on GDIPlus.

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Many Thanks!

Here`s my updated script for reference, I need to make some adjustments, when you scale the picture it rotates around a circle instead of in a circle. :)

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <GuiConstantsEx.au3>
#include <Math.au3>
#include <ScreenCapture.au3>

; ================================================================
; Global constants
; =================================================================
Global Const $iOpacity          = 200
Global Const $nPI               = 3.1415926535897932384626433832795
Global Const $WM_LBUTTONDOWN = 0x0201  ; Drag Window 1 of 3 addin
Global Const $AC_SRC_ALPHA      = 1
Global Const $ULW_ALPHA         = 2
Global Enum $eScrDC=0, $eMemDC, $eBitmap, $eWidth, $eHeight, $eGraphic, $ePen, $eCap, $eBrush, $eFormat, $eFamily, $eFont, $eLayout, $eLast
 
Global $aPen, $aRect, $aPointer, $aPic, $WinWd, $WinHgt, $hRect,$hImage, $hDot, $aImage, $aText
Global $hGUI2, $hPic, $hMatrix, $nAngle, $iRet, $hCross, $hText, $aCross, $aDot, $iN, $hBitmap, $iPath = @ScriptDir & "\Images\Image.png"
; =================================================================
; Global variables
; =================================================================
Global $MenuItemExit, $ContextMenu, $separator1, $hFontRotate, $hPointer, $Msg
Global $user32_dll = DllOpen ("user32.dll")
Global $iRadius    = 200, $f = 1

HotKeySet("{ESC}", "quitclk")

Dim $Color[46]  =   [0, 0xff7E0000, 0xffBE0000, 0xffFE0000, 0xffFE8080, 0xffFFBFBF, _ 
                    0xff7E4F00, 0xffBF7700, 0xffFF9F00, 0xffFECF7F, 0xffFFE8BF, _
                    0xff7F8000, 0xffBFBF00, 0xffFFFF00, 0xffFFFF80, 0xffFFFFBF, _
                    0xff017F01, 0xff00BF00, 0xff00FF00, 0xff80FF80, 0xffBFFFC0, _
                    0xff007F7E, 0xff00C0BF, 0xff00FFFF, 0xff7FFFFE, 0xffBFFFFF, _
                    0xff002F7F, 0xff0048C0, 0xff0060FF, 0xff8180FF, 0xffBFD6FF, _
                    0xff5A007E, 0xff8F00BF, 0xffB400FF, 0xffDA7FFE, 0xffECC0FF, _
                    0xff7E007E, 0xffB700BF, 0xffFF00FF, 0xffFE80FE, 0xffFFBEFE, _
                    0xff000000, 0xff7D7D7D, 0xffA9A9A9, 0xffD4D4D4, 0xffFFFFFF]

; =================================================================
; Main
; =================================================================
Opt("MustDeclareVars", 1)
Opt ("GUIOnEventMode", 1)

Init()
Rectinit()
RectDraw()
RotatePic()
FontRotateDraw()

TextInit()
TextDraw()
TextDone()

ClockLoop()
ClockDone()

; ===============================================================
; Finalize clock
; ===============================================================
Func ClockDone()
     
  ; Finalize GDI+ library
RectDone()

  _GDIPlus_Shutdown()
    DllClose($user32_dll)
EndFunc

; ==============================================================
; Initialize clock
; ==============================================================
Func Init()
  Local $iX, $iY

  ; Calculate the dial frame caption size
  $iX = -(_WinAPI_GetSystemMetrics($SM_CXFRAME))
  $iY = -(_WinAPI_GetSystemMetrics($SM_CYCAPTION) + _WinAPI_GetSystemMetrics($SM_CYFRAME)) 
  $WinWd  = $iRadius * 2
  $WinHgt = $iRadius * 2

  $hRect   = GUICreate("Rectangle", $WinWd, $WinHgt, 200,  200, 0, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUISetCursor (9, 1, $hRect)
    GuiRegisterMsg($WM_LBUTTONDOWN, "_WinMove")    ; Drag Rectangle
    GUISetState() 
  $hPic = GUICreate("Test",              $WinWd * 2, $WinHgt* 2, $iX, $iY, 0,   BitOr($WS_EX_LAYERED, $WS_EX_MDICHILD), $hRect)
    GUISetState()
  $hFontRotate = GUICreate("FontRotate", $WinWd, $WinHgt, $iX,  $iY, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hRect)
    GUISetState()
  $hText   = GUICreate("Text",           $WinWd, $WinHgt, -1,  -1, 0, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hRect)
    GUISetState()
    
; Hook non client hit test message so we can move the clock
  ;GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

  GuiRegisterMsg($WM_LBUTTONDOWN, "_WinMove")    ; Drag Window 2 of 3 addin
  
  ; Initialize GDI+ library
  _GDIPlus_Startup()

;$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Images\Image.png") ; Image = Sm0ke N... http://www.autoitscript.com/forum/uploads/av-4813.png
    ; Capture screen region
   $hBitmap = _ScreenCapture_Capture ("", 0, 0, 150, 150) 
   $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap)
EndFunc

; =============================================================
; Loop until user exits
; =============================================================
Func ClockLoop()    
  do
      sleep(250)
  until $Msg = $GUI_EVENT_CLOSE
EndFunc

; ===========Start of  _GDIPlus_MatrixRotate() Example ==========
; ===============================================================
; Draw Rotated text from 
;http://www.autoitscript.com/forum/index.php?s=&showtopic=64569&view=findpost&p=483796
; ===============================================================
Func FontRotateDraw()
    Local $aRotate, $aDrawrect, $iARgb,  $F = 1, $DrawRect, $Rx = 200, $Ry = 200, $iWd = 190
;Font Rotate
    $aRotate = ResourceInit($WinWd,$WinHgt)
    ;DrawGraphic($hGraphic, $Rx, $Ry, $nAngle,  $iWidth,    $iHeight, $iARGB = 0xFF000000)
    For $iAng = 0 to 360 step 12
                $iN += 1
        ;tooltip ("Colour Number = " &$iN &" Colour = " &Hex ($Color[$iN]))
         FontRotate($aRotate[$eGraphic], $Rx, $Ry, $iAng,   $iWd,       20,       $Color[$iN])  
        sleep(10)
     Next    
     ResourceSet ($hFontRotate, $aRotate, $iOpacity)
    ResourceDone($aRotate)
EndFunc 

; =============================================================================
; Rotate Picture
; =============================================================================
Func RotatePic()
    For $iAng = 0 to 360 * 2 step 5
         RotatePiece($iAng) 
        sleep(10)            
    Next
EndFunc 

Func RotatePiece($angle)
    Local $hMatrix, $nX, $nY, $x, $y, $Pos, $radius , $hGraphic ;,$hImage
    Local $hWnd, $hDC, $hBitmap, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend, $nXt, $nYt

    $hWnd = _WinAPI_GetDC (0)
    $hDC = _WinAPI_CreateCompatibleDC ($hWnd)
    $hBitmap = _WinAPI_CreateCompatibleBitmap ($hWnd, $WinWd, $Winhgt)
    _WinAPI_SelectObject ($hDC, $hBitmap)
    $hGraphic = _GDIPlus_GraphicsCreateFromHDC ($hDC)
   
    $Pos = WinGetPos($hPic)
    $nX = $Pos[0]
    $nY = $Pos[1]
   
    ;Rotation Matrix
    $hMatrix = _GDIPlus_MatrixCreate ()
    _GDIPlus_MatrixRotate ($hMatrix, $angle, False)
    _GDIPlus_GraphicsSetTransform ($hGraphic, $hMatrix)
   
    $x = ($WinWd / 2) * Cos($angle * $nPI / 180) - ($WinHgt / 2) + $nX - ($WinWd / 2) * Sin($angle * $nPI / 180)
        ;Parametric equations for a circle
    $y = ($WinWd  / 2) * Sin($angle * $nPI / 180) - ($WinHgt / 2) + $nY + ($WinWd / 2) * Cos($angle * $nPI / 180)
        ; and adjusts for center of text box
   
    ;Rotation of Coordinate Axes formulae
    ; $nXt - X coordinate before translation
    $nXt = ($nX - $x) * Cos($angle * $nPI / 180) + ($nY - $y) * Sin($angle * $nPI / 180)
   
    ; $nYt - Y coordinate before translation
    $nYt = -($nX - $x) * Sin($angle * $nPI / 180) + ($nY - $y) * Cos($angle * $nPI / 180)
   
    _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage, $nXt + ($WinWd*0.2), $nYt + ($WinHgt*0.2) , $WinWd*0.6, $WinHgt*0.6)
;    _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage, $nXt + ($WinWd*0.2), $nYt + ($WinHgt*0.2) , $WinWd*0.6, $WinHgt*0.6)   
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $WinWd )  ;$iWidth )
    DllStructSetData($tSize, "Y", $WinHgt)  ;$iHeight)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow ($hPic, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_MatrixDispose ($hMatrix)
    _WinAPI_ReleaseDC (0, $hWnd)
    _WinAPI_DeleteObject ($hBitmap)
    _WinAPI_DeleteDC ($hDC)
    Return 1
EndFunc   ;==>RotatePiece

; =============================================================================
; Initialize resources for Rectangle
; =============================================================================
Func RectInit()
  $aRect = ResourceInit($WinWd, $WinHgt )
  $aRect[$ePen] = _GDIPlus_PenCreate(0xFF000000 ,10, 2)   ;Colour, LineWidth, Pixels
EndFunc

; =============================================================================
; Draw Rectangle
; =============================================================================
Func RectDraw()
        _GDIPlus_GraphicsDrawRect($aRect[$eGraphic], 4, 4, $WinWd - 10, $WinHgt - 10, $aRect[$ePen])
        ResourceSet ($hRect, $aRect, $iOpacity)
#cs     
    $iRet = DllCall("User32.dll", "int", "SetWindowPos", "Hwnd", $hRotate, "Hwnd", $hRect, _
    "int", 100, "int", 100, "int", 100, "int", 100, "uint", $SWP_NOSIZE + $SWP_NOMOVE)                      ; Z-order sent to back.
#ce
EndFunc

; =============================================================================
; Finalize resources for the Rectangle
; ==============================================================================
Func RectDone()
  _GDIPlus_PenDispose($aRect[$ePen])
  ResourceDone($aRect)
EndFunc

; ============================================================================
; Handle the WM_NCHITTEST message so our window can be dragged
; ============================================================================
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    if $hWnd = $hRect then Return $HTCAPTION
EndFunc 

; ==============================================================================
;Rotate!
; ==============================================================================
Func FontRotate($hGraphic, $nX, $nY, $nAngle, $nWidth, $nHeight, $iARGB)
    Local $hMatrix, $nXt, $nYt, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
    ; $nXt     - The X coordinate of the upper left corner of the Graphics object before rotation 
    ; $nYt     - The Y coordinate of the upper left corner of the Graphics object before rotation
    
    ;Rotation Matrix
    $hMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixRotate($hMatrix, $nAngle, "False")   
    _GDIPlus_GraphicsSetTransform($hGraphic , $hMatrix) 
    
    ;Rotation of Coordinate Axes formulae
    $nXt = $nX*cos($nAngle*$nPI/180) + $nY*sin($nAngle*$nPI/180)  ; $nXt - X coordinate before translation 
    $nYt = -$nX*sin($nAngle*$nPI/180) + $nY*cos($nAngle*$nPI/180) ; $nYt - Y coordinate before translation
    
    $hBrush  = _GDIPlus_BrushCreateSolid ($iARGB)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    $hFont   = _GDIPlus_FontCreate ($hFamily, 14, 1)
    $tLayout = _GDIPlus_RectFCreate ( $nXt, $nYt, $nWidth, $nHeight )
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, "Autoit is Great! " &$iN, $hFont, $tLayout, $hFormat, $hBrush)
    Sleep(10)   
    
    ; Clean up resources    
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose ($hBrush) 
    _GDIPlus_PenDispose($aPen)
    Return 1
EndFunc

; ==========================================================================
; Initialize resources for the Text
; ==========================================================================
Func TextInit()
  $aText = ResourceInit($WinWd, $Winhgt)
  $aText[$eBrush ] = _GDIPlus_BrushCreateSolid(0xF0000000)
  $aText[$eFormat] = _GDIPlus_StringFormatCreate()
  $aText[$eFamily] = _GDIPlus_FontFamilyCreate("Arial")
  $aText[$eFont  ] = _GDIPlus_FontCreate($aText[$eFamily], Int(24)+1, 1)
  $aText[$eLayout] = _GDIPlus_RectFCreate(60, 330, 300, 100); X,Y, Width, Height

EndFunc

; ============================================================================
; Draw the Text
; ============================================================================
Func TextDraw()
  Local  $sString = "Press Esc to Exit",$aSize
  $aSize   = _GDIPlus_GraphicsMeasureString($aText[$eGraphic], $sString, $aText[$eFont], $aText[$eLayout], $aText[$eFormat])
  _GDIPlus_GraphicsDrawStringEx($aText[$eGraphic], $sString, $aText[$eFont], $aText[$eLayout], $aText[$eFormat], $aText[$eBrush])
  ResourceSet($hText, $aText)
EndFunc

; ===========================================================================
; Finalize resources for the Text
; ===========================================================================
Func TextDone()
  _GDIPlus_FontDispose        ($aText[$eFont  ])
  _GDIPlus_FontFamilyDispose  ($aText[$eFamily])
  _GDIPlus_StringFormatDispose($aText[$eFormat])
  _GDIPlus_BrushDispose       ($aText[$eBrush ])
  ResourceDone($aText)
EndFunc

; ====================================================================
; Finalize drawing resources
; ====================================================================
Func ResourceDone(ByRef $aInfo)
  _GDIPlus_GraphicsDispose($aInfo[$eGraphic])
  _WinAPI_ReleaseDC   (0, $aInfo[$eScrDC])
  _WinAPI_DeleteObject($aInfo[$eBitmap])
  _WinAPI_DeleteDC    ($aInfo[$eMemDC ])
EndFunc

; ===================================================================
; Initialize bitmap resources
; ===================================================================
Func ResourceInit($iWidth, $iHeight)
  Local $aInfo[$eLast + 1], $hBitmap

  $aInfo[$eScrDC  ] = _WinAPI_GetDC(0)
  $aInfo[$eMemDC  ] = _WinAPI_CreateCompatibleDC($aInfo[$eScrDC])
  $aInfo[$eBitmap ] = _WinAPI_CreateCompatibleBitmap($aInfo[$eScrDC], $iWidth, $iHeight)
  _WinAPI_SelectObject($aInfo[$eMemDC], $aInfo[$eBitmap])
  $aInfo[$eWidth  ] = $iWidth
  $aInfo[$eHeight ] = $iHeight
  $aInfo[$eGraphic] = _GDIPlus_GraphicsCreateFromHDC($aInfo[$eMemDC])
  _GDIPlus_GraphicsFillRect($aInfo[$eGraphic], 0, 0, $iRadius * 2, $iRadius * 2)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
  Return $aInfo
EndFunc

; ==================================================================
; Update layered window with resource information
; ==================================================================
Func ResourceSet($hGUI, ByRef $aInfo, $iAlpha=-1)
  Local $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  if $iAlpha = -1 then $iAlpha = $iOpacity
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", $aInfo[$eWidth ])
  DllStructSetData($tSize, "Y", $aInfo[$eHeight])
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend )
  DllStructSetData($tBlend, "Alpha" , $iAlpha      )
  DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
  _WinAPI_UpdateLayeredWindow($hGUI, $aInfo[$eScrDC], 0, $pSize, $aInfo[$eMemDC], $pSource, 0, $pBlend, $ULW_ALPHA)
EndFunc

; ==================================================================
; Exit program
; ==================================================================
Func quitclk()
    $Msg = $GUI_EVENT_CLOSE 
EndFunc  

; ================================================================= 
; Drag Window 3 of 3 addin
; =================================================================
Func _WinMove($HWnd, $Command, $wParam, $lParam)    
     If BitAND(WinGetState($HWnd), 32) Then Return $GUI_RUNDEFMSG
    ;DllCall("user32.dll", "long", "SendMessage", "hwnd", $HWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
    dllcall("user32.dll","int","SendMessage","hWnd", $HWnd, "int",$WM_NCLBUTTONDOWN,"int", $HTCAPTION,"int", 0)     
EndFunc 

; This function from GDIPlus.au3 Beta version
Func _GDIPLus_GraphicsDrawImageRect($hGraphics, $hImage, $iX, $iY, $iW, $iH)
    Local $aResult
    $aResult = DllCall($ghGDIPDll, "int", "GdipDrawImageRectI", "hwnd", $hGraphics, "hwnd", $hImage, _
            "int", $iX, "int", $iY, "int", $iW, "int", $iH)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPLus_GraphicsDrawImage
Should I split this off into seperate GDI Example thread?, or leave it here? Edited by Lakes

2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
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
Sign in to follow this  
Followers 0