7月102017
旋转动画AU3
别人的代码,我只是无耻的翻译成了AU3,翻译完了,还是发出来吧。有问题欢迎进我的群讨论(477266297)。
#RequireAdmin
#AU3QQ交流群:477266297
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)
Global $iSleepTime = 80
Global $hGUI = GUICreate("GDI+旋转动画", 400, 280)
Global $Pic_Animation = GUICtrlCreatePic('', 5, 5, 256, 256)
Global $Btn_Type1 = GUICtrlCreateButton('旋转方式一', 275, 35, 100, 30)
Global $Btn_Type2 = GUICtrlCreateButton('旋转方式二', 275, 85, 100, 30)
Global $Btn_Type3 = GUICtrlCreateButton('旋转方式三', 275, 135, 100, 30)
Global $Slider_Time = GUICtrlCreateSlider(275, 185, 100, 45)
GUICtrlSetLimit($Slider_Time, 500, 50)
GUISetState()
GUISetIcon('shell32.dll',322,$hGUI)
GUISetOnEvent(-3, '_GuiEvent')
GUICtrlSetOnEvent($Btn_Type1, '_GuiEvent')
GUICtrlSetOnEvent($Btn_Type2, '_GuiEvent')
GUICtrlSetOnEvent($Btn_Type3, '_GuiEvent')
GUICtrlSetOnEvent($Slider_Time, '_GuiEvent')
_AnimationInit(ControlGetHandle($hGUI, '', $Pic_Animation), 1)
_GDIPlus_Startup() ;
While 1
Sleep($iSleepTime)
_NextFlash()
WEnd
Func _GuiEvent()
Switch @GUI_CtrlId
Case -3
_DeleteCache()
Exit
Case $Btn_Type1
_ResetAniType(1, 2)
Case $Btn_Type2
_ResetAniType(2, 0)
Case $Btn_Type3
_ResetAniType(3, 0)
Case $Slider_Time
$iSleepTime=GUICtrlRead($Slider_Time)
EndSwitch
EndFunc ;==>_GuiEvent
Func _AnimationInit($hHwd, $SpaceSec)
Global $m_hWnd = $hHwd
Global $m_nWidth, $m_nHeight
Global $m_AnimationIndex = 0, $m_AnimationType = 0, $m_AnimationCount = 12
Global $m_ItemSize, $m_MarginAngle
Global $m_hCacheDC, $m_hCacheBitmap, $m_hCacheOldBitmap
Global $m_Rect = DllStructCreate($tagRECT)
Global $m_ColorBack = _WinAPI_GetSysColor($COLOR_BTNFACE)
Global $m_ColorBasic[2] = [0x808080, 0xC0C0C0]
Global $m_ColorFore1 = [0x1FF4FB, 0x07F98C, 0x91A804, 0xCC9302, 0xAF5801, 0x9C426B, 0x9744A7, 0x9841E4, 0x241BEE, 0x2472F5, 0x2190F4, 0x12C2FF]
Global $m_ColorFore2 = [0x34F5FF, 0x3CFDA3, 0xA5B833, 0xD8A733, 0xB67636, 0xAD6988, 0xAD68B9, 0xAC66E9, 0x514AEF, 0x4E8DF5, 0x4BA5FA, 0x3ECEFE]
Global $m_AnimationArray[$m_AnimationCount]
Local $i
For $i = 0 To $m_AnimationCount - 1
$m_AnimationArray[$i] = _AnimationItem()
DllStructSetData($m_AnimationArray[$i], 1, _RGB2ARGB($m_ColorBasic[0], 255))
DllStructSetData($m_AnimationArray[$i], 2, _RGB2ARGB($m_ColorBasic[1], 255))
Next
_Resize()
_ResetAniType($m_AnimationType, $SpaceSec)
EndFunc ;==>_AnimationInit
Func _RGB2ARGB($RGBColor, $Alpha)
Return BitOR(Binary('0x' & Hex($RGBColor, 6)), BitShift($Alpha, -24))
EndFunc ;==>_RGB2ARGB
Func _Resize()
_DeleteCache()
Local $rc = _WinAPI_GetClientRect($m_hWnd)
$m_nWidth = DllStructGetData($rc, 3) - DllStructGetData($rc, 1)
$m_nHeight = DllStructGetData($rc, 4) - DllStructGetData($rc, 2)
If $m_nWidth > $m_nHeight Then
DllStructSetData($m_Rect, 3, ($m_nHeight - 10))
Else
DllStructSetData($m_Rect, 3, ($m_nWidth - 10))
EndIf
;~ DllStructSetData($m_Rect, 3, ($m_nWidth > $m_nHeight) ? ($m_nHeight - 10) : ($m_nWidth - 10))
DllStructSetData($m_Rect, 4, DllStructGetData($m_Rect, 3))
DllStructSetData($m_Rect, 1, ($m_nWidth - DllStructGetData($m_Rect, 3)) / 2)
DllStructSetData($m_Rect, 2, ($m_nHeight - DllStructGetData($m_Rect, 4)) / 2)
$m_ItemSize = 20
EndFunc ;==>_Resize
Func _ResetAniType($AniType, $SpaceSec = 0)
Local $i
$m_AnimationIndex = 0
Switch $AniType
Case 0
$m_AnimationType = 0
Case 1
$m_AnimationType = 1
Case 2
$m_AnimationType = 2
For $i = 0 To $m_AnimationCount - 1
DllStructSetData($m_AnimationArray[$i], 1, _RGB2ARGB($m_ColorFore1[$i], 255))
DllStructSetData($m_AnimationArray[$i], 2, _RGB2ARGB($m_ColorFore2[$i], 255))
Next
Case 3
$m_AnimationType = 3
For $i = 0 To $m_AnimationCount - 1
DllStructSetData($m_AnimationArray[$i], 1, _RGB2ARGB($m_ColorFore1[$i], 255))
DllStructSetData($m_AnimationArray[$i], 2, _RGB2ARGB($m_ColorFore2[$i], 255))
Next
Case Else
_ResetAniType(0)
Return
EndSwitch
$m_MarginAngle = $SpaceSec
If $m_MarginAngle > 10 Then $m_MarginAngle = 10
If $m_MarginAngle < 0 Then $m_MarginAngle = 0
EndFunc ;==>_ResetAniType
Func _NextFlash()
Local $i
Switch $m_AnimationType
Case 0
$m_AnimationIndex += 1
If ($m_AnimationIndex > $m_AnimationCount) Then
$m_AnimationType = 1
$m_AnimationIndex = 0
EndIf
For $i = 0 To $m_AnimationIndex - 1
DllStructSetData($m_AnimationArray[$i], 1, _RGB2ARGB($m_ColorFore1[$i], 255))
DllStructSetData($m_AnimationArray[$i], 2, _RGB2ARGB($m_ColorFore2[$i], 255))
Next
Case 1
$m_AnimationIndex += 1
If ($m_AnimationIndex > $m_AnimationCount) Then
$m_AnimationType = 0
$m_AnimationIndex = 0
EndIf
For $i = 0 To $m_AnimationIndex - 1
DllStructSetData($m_AnimationArray[$i], 1, _RGB2ARGB($m_ColorBasic[0], 255))
DllStructSetData($m_AnimationArray[$i], 2, _RGB2ARGB($m_ColorBasic[1], 255))
Next
Case 2
Local $item=$m_AnimationArray[11]
For $i = 0 To $m_AnimationCount - 2
$m_AnimationArray[$m_AnimationCount - $i - 1] = $m_AnimationArray[$m_AnimationCount - $i - 2]
Next
$m_AnimationArray[0] = $item
Case 3
$m_AnimationIndex = $m_AnimationIndex + 1
If ($m_AnimationIndex > $m_AnimationCount) Then $m_AnimationIndex = 0
EndSwitch
_Draw()
EndFunc ;==>_NextFlash
Func _Draw()
Local $hDC = _WinAPI_GetDC($m_hWnd)
If $m_hCacheDC = 0 Then
$m_hCacheDC = _WinAPI_CreateCompatibleDC($hDC)
$m_hCacheBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $m_nWidth, $m_nHeight)
$m_hCacheOldBitmap = _WinAPI_SelectObject($m_hCacheDC, $m_hCacheBitmap)
EndIf
_FillSolidRect($m_hCacheDC, _CRect(0, 0, $m_nWidth, $m_nHeight), $m_ColorBack)
_DrawPie($m_hCacheDC)
_WinAPI_BitBlt($hDC, 0, 0, $m_nWidth, $m_nHeight, $m_hCacheDC, 0, 0, 0x00CC0020)
_WinAPI_ReleaseDC($m_hWnd, $hDC)
EndFunc ;==>_Draw
Func _CRect($Left, $Top, $Right, $Bottom)
Local $Rect = DllStructCreate($tagRECT)
DllStructSetData($Rect, 1, $Left)
DllStructSetData($Rect, 2, $Top)
DllStructSetData($Rect, 3, $Right)
DllStructSetData($Rect, 4, $Bottom)
Return $Rect
EndFunc ;==>_CRect
Func _FillSolidRect($hDC, $lpRect, $clr)
_WinAPI_SetBkColor($hDC, $clr)
_ExtTextOut($hDC, 0, 0, 2, $lpRect, Chr(0), 0, 0)
EndFunc ;==>_FillSolidRect
Func _DrawPie($hDC)
Local $i
Local $nStartAngle
Local $nSweepAngle
Local $pGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC)
_GDIPlus_GraphicsSetSmoothingMode($pGraphics, 4)
Local $pBrush = _GDIPlus_BrushCreateSolid(_RGB2ARGB(0, 255))
Local $rcOut = DllStructCreate($tagRECT)
DllStructSetData($rcOut, 1, DllStructGetData($m_Rect, 1))
DllStructSetData($rcOut, 2, DllStructGetData($m_Rect, 2))
DllStructSetData($rcOut, 3, DllStructGetData($m_Rect, 3))
DllStructSetData($rcOut, 4, DllStructGetData($m_Rect, 4))
Local $rcIn = DllStructCreate($tagRECT)
DllStructSetData($rcIn, 1, DllStructGetData($rcOut, 1))
DllStructSetData($rcIn, 2, DllStructGetData($rcOut, 2))
DllStructSetData($rcIn, 3, DllStructGetData($rcOut, 3))
DllStructSetData($rcIn, 4, DllStructGetData($rcOut, 4))
_InflateRectF($rcIn, -1 * $m_ItemSize)
$nSweepAngle = 360 / $m_AnimationCount
$nStartAngle = -90
For $i = 0 To $m_AnimationCount - 1
_GDIPlus_BrushSetSolidColor($pBrush, DllStructGetData($m_AnimationArray[$i], 1))
_GDIPlus_GraphicsFillPie($pGraphics, DllStructGetData($rcOut, 1), DllStructGetData($rcOut, 2), DllStructGetData($rcOut, 3), DllStructGetData($rcOut, 4), _
$nStartAngle, $nSweepAngle - $m_MarginAngle, $pBrush)
$nStartAngle += $nSweepAngle
Next
$nSweepAngle = 360 / $m_AnimationCount
$nStartAngle = -90
For $i = 0 To $m_AnimationCount - 1
_GDIPlus_BrushSetSolidColor($pBrush, DllStructGetData($m_AnimationArray[$i], 2))
_GDIPlus_GraphicsFillPie($pGraphics, DllStructGetData($rcIn, 1), DllStructGetData($rcIn, 2), DllStructGetData($rcIn, 3), DllStructGetData($rcIn, 4), _
$nStartAngle, $nSweepAngle - $m_MarginAngle, $pBrush)
$nStartAngle += $nSweepAngle
Next
If ($m_AnimationType = 3) Then
If $m_AnimationIndex > 0 Then
$nStartAngle = -90
$nStartAngle = $nStartAngle + $m_AnimationIndex * $nSweepAngle
_GDIPlus_BrushSetSolidColor($pBrush, _RGB2ARGB(0xFFFFFF, 150))
_GDIPlus_GraphicsFillPie($pGraphics, DllStructGetData($rcOut, 1), DllStructGetData($rcOut, 2), DllStructGetData($rcOut, 3), DllStructGetData($rcOut, 4), _
$nStartAngle, $nSweepAngle - $m_MarginAngle, $pBrush)
EndIf
EndIf
_InflateRectF($rcIn, -1 * $m_ItemSize)
_GDIPlus_BrushSetSolidColor($pBrush, _RGB2ARGB($m_ColorBack, 255))
_GDIPlus_GraphicsFillPie($pGraphics, DllStructGetData($rcIn, 1), DllStructGetData($rcIn, 2), DllStructGetData($rcIn, 3), DllStructGetData($rcIn, 4), 0, 360, $pBrush)
_GDIPlus_BrushDispose($pBrush)
_GDIPlus_GraphicsDispose($pGraphics)
EndFunc ;==>_DrawPie
Func _InflateRectF($rc, $dx, $dy = 0)
If $dy = 0 Then $dy = $dx
DllStructSetData($rc, 1, DllStructGetData($rc, 1) - $dx)
DllStructSetData($rc, 2, DllStructGetData($rc, 2) - $dy)
DllStructSetData($rc, 3, DllStructGetData($rc, 3) + $dx * 2)
DllStructSetData($rc, 4, DllStructGetData($rc, 4) + $dy * 2)
EndFunc ;==>_InflateRectF
Func _DeleteCache()
If $m_hCacheDC <> 0 Then
_WinAPI_SelectObject($m_hCacheDC, $m_hCacheOldBitmap)
_WinAPI_DeleteObject($m_hCacheBitmap)
_WinAPI_DeleteDC($m_hCacheDC)
_GDIPlus_Shutdown()
$m_hCacheDC = 0
$m_hCacheBitmap = 0
$m_hCacheOldBitmap = 0
EndIf
EndFunc ;==>_DeleteCache
Func _ExtTextOut($hDC, $x, $y, $wOptions, $lpRect, $lpString, $nCount, $lpDx)
If Not IsPtr($lpRect) Then $lpRect=DllStructGetPtr($lpRect)
Local $Ret = DllCall('GDI32.dll', 'BOOL', 'ExtTextOutW', 'HANDLE', $hDC, 'INT', $x, 'INT', $y, 'UINT', $wOptions, 'PTR', $lpRect, 'WSTR', $lpString, 'UINT', $nCount, 'INT', $lpDx)
If @error Then Return SetError(@error, 0, 0)
Return $Ret[0]
EndFunc ;==>_ExtTextOut
Func _AnimationItem()
Return DllStructCreate('INT;INT;')
EndFunc ;==>_AnimationItem```
<p>
<br />
</p>
扫描二维码,在手机上阅读
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!
看的我也想学学了,怎么入门,还有,你是不是要检查下评论了,验证码显示不出来,还特别容易让人误以为验证码的框是填算术的