afan
发表于 2012-11-23 11:27:44
回复 14# xms77
我浅薄的源码都分散在其它版块,特别是提问交流区。偶尔也会弄个小作品展览一下,提升一点该版块的人气。该版块存在的意义,我想也存在鼓励他人创新、钻研的精神。一味的公开源码,也并非好事。有个不争的事实,现在有些Au3的用户已经(或准备)转学其它语言了,只因去年出了个傻瓜式的反编工具。当然这些都是题外话……
ajian55
发表于 2012-11-23 12:08:50
回复 17# afan
怀表很精美,收下了。如果A大超版可以分享下这个作品所做到的防那个“傻瓜式的反编工具”的方法,岂不更好~
afan
发表于 2012-11-23 12:19:07
回复afan
怀表很精美,收下了。如果A大超版可以分享下这个作品所做到的防那个“傻瓜式的反编工具”的 ...
ajian55 发表于 2012-11-23 12:08 http://www.autoitx.com/images/common/back.gif
**** Hidden Message *****
ajian55
发表于 2012-11-23 13:44:40
**** Hidden Message *****
tiger_47
发表于 2012-11-23 13:53:36
懷古思情+au3新技術!
{:1_496:}
boyhong
发表于 2012-11-23 15:29:05
A大的东东必须要支持!
xms77
发表于 2012-11-23 18:54:47
回复 17# afan
反编译也是有好有坏,反别人的程序那是道德问题,反自己的程序就不存在道德问题了,反自己的程序我发现可以帮助自己找到程序中出问题的行。
半芯竹
发表于 2012-11-23 22:24:59
真是长见识啊。AU3也能达到这种效果。。高境界。。赞。。
menfan1
发表于 2012-11-24 10:26:58
xp下运行不错,能开源更好哈,优化一下代码迷惑会更好。。
seniors
发表于 2012-11-24 12:21:00
本帖最后由 seniors 于 2012-11-24 15:21 编辑
回复 17# afan
分针有跳动现象,和图片是不是圆好像是没关系的。
开不开源,是各人想法,不能强求。
但我不同意您的“一味的公开源码,也并非好事”这句话。
“现在有些Au3的用户已经(或准备)转学其它语言了”,AU3的强项是类似于按键,但好像比按键处理网页类要强。
画个表盘,也来试试
#include <WindowsConstants.au3>
#include <WinAPIEx.au3>
#include <GDIPlusex.au3>
OnAutoItExitRegister("ExitFunc")
$hGui = GUICreate("怀表", 400, 400, -1, -1, 0x80000000)
GUISetBkColor(0xAAAAAA)
GUICtrlCreatePic('', 50, 50, 301, 301, -1, 0x00100000)
Global $hPic = GUICtrlGetHandle(-1)
_GDIPlus_Startup()
Draw_Watch()
Global $hCallback = DllCallbackRegister("My_winProc", "int", "hWnd;uint;wparam;lparam")
Global $tCallback = DllCallbackGetPtr($hCallback)
Global $CallProc = _WinAPI_SetWindowLong($hGui, -4, $tCallback)
GUISetState()
Do
Until GUIGetMsg() = -3
Func ExitFunc()
_WinAPI_SetWindowLong($hGui, -4, $CallProc)
_GDIPlus_Shutdown()
GUIDelete($hGui)
EndFunc ;==>ExitFunc
Func Draw_Watch()
Local $hPath
Local $hBitmap = _WinAPI_CreateBitmap(301, 301, 1, 32);建立背景位图
Local $hCDC = _WinAPI_CreateCompatibleDC(0);建立绘图DC
Local $hOld = _WinAPI_SelectObject($hCDC, $hBitmap);调入图片到DC
Local $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hCDC);从DC创建图形对象
_GDIPlus_GraphicsClear($hGraphics, 0x00000000);清空图形
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2);绘制质量 2 - 使用 8 X 8 矩形过滤器
_GDIPlus_GraphicsSetInterpolationMode($hGraphics, 7);插值法 7=High-quality, bicubic interpolation.
DllCall($ghGDIPDll, "uint", "GdipSetTextRenderingHint", "hwnd", $hGraphics, "int", 4)
Local $hPen = _GDIPlus_PenCreate(0xFF333333)
$hPath = circlePath(300, 5)
_GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen);这个函数里已经注销了$hPen
_GDIPlus_PathDispose($hPath)
Local $hBrush = _GDIPlus_BrushCreateSolid(0xFF333333)
$hPath = WatchPath(300, 5, 1, 6)
_GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush);这个函数里已经注销了$hBrush
_GDIPlus_PathDispose($hPath)
Local $hBrush = _GDIPlus_BrushCreateSolid(0xFF46A3FF)
$hPath = WatchPath(300, 8, 1, 30)
_GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush);这个函数里已经注销了$hBrush
_GDIPlus_PathDispose($hPath)
_GDIPlus_GraphicsDispose($hGraphics)
_WinAPI_SelectObject($hCDC, $hOld)
_WinAPI_DeleteDC($hCDC)
$oldObj = _SendMessage($hPic, 0x0172, 0, $hBitmap) ;$STM_SETIMAGE = 0x0172
_WinAPI_DeleteObject($oldObj)
Local $hObj = _SendMessage($hPic, 0x0173) ;$STM_GETIMAGE = 0x0173
If $hObj <> $hBitmap Then
_WinAPI_DeleteObject($hBitmap)
EndIf
DllCall('psapi.dll', 'int', 'EmptyWorkingSet', 'hWnd', -1) ;释放内存
EndFunc ;==>Draw_Watch
Func My_winProc($hWnd, $Msg, $wParam, $lParam)
Switch $Msg
Case 0x0084;WM_NCHITTEST
Return $HTCAPTION
Case 0x00A3;WM_NCLMOUSEDBCLK
Exit
EndSwitch
Return _WinAPI_CallWindowProc($CallProc, $hWnd, $Msg, $wParam, $lParam)
EndFunc ;==>My_winProc
Func ScalePath($R, $Height, $nStartAngle, $nSweepAngle)
Local $hPath = _GDIPlus_PathCreate()
_GDIPlus_PathAddArc($hPath, 0, 0, $R, $R, $nStartAngle, $nSweepAngle)
_GDIPlus_PathAddArc($hPath, $Height, $Height, $R - $Height * 2, $R - $Height * 2, $nStartAngle + $nSweepAngle, -$nSweepAngle)
_GDIPlus_PathCloseFigures($hPath)
Return $hPath
EndFunc ;==>ScalePath
Func circlePath($R, $Height)
Local $hPath = _GDIPlus_PathCreate()
_GDIPlus_PathAddEllipse($hPath, 0, 0, $R, $R)
_GDIPlus_PathAddEllipse($hPath, $Height, $Height, $R - $Height * 2, $R - $Height * 2)
Return $hPath
EndFunc ;==>circlePath
Func WatchPath($R, $Height, $sweepAng, $step)
Local $hPath1 = _GDIPlus_PathCreate()
Local $startAng = -$sweepAng / 2
For $Ang = $startAng To 360 - $sweepAng Step $step
$hPath = ScalePath($R, $Height, $Ang, $sweepAng)
_GDIPlus_PathAddPath($hPath1, $hPath, False)
_GDIPlus_PathDispose($hPath)
Next
Return $hPath1
EndFunc ;==>WatchPath
afan
发表于 2012-11-24 16:05:22
本帖最后由 afan 于 2012-11-24 16:06 编辑
回复 26# seniors
我的源码都是低层次的,公开只会误导他人的思维,本人也无法达到做出的东西必须公开的境界,总之无法与大师你相比的。
关于开源与否的问题我就不再讨论了。
这是我在网上找的原始图片。
我将其Ps成表体和指针各部分,然后再将指针旋转绘制到表体上。以下是旋转所用到的函数
_WinAPI_RotatePoints()
_GDIPlus_GraphicsTranslateTransform()
_GDIPlus_GraphicsRotateTransform()
因为表体并非正圆,而指针的长度固定不变,就有可能在旋转时因与圆周的边距离不等而产生抖动的错觉。
但后来觉得是指针旋转时的轴心不准而产生的抖动,而这却似乎不太好解决。
seniors
发表于 2012-11-24 16:10:42
回复 27# afan
不敢当,我看出的就是轴心不准,可能_GDIPlus_GraphicsRotateTransform()
旋转有误差吧
sky-sky
发表于 2012-11-24 17:55:32
看上去很不错的
seniors
发表于 2012-11-24 21:02:54
本帖最后由 seniors 于 2012-11-24 21:43 编辑
回复 27# afan
Afan版版,帮我看下为什么秒针有时会长出来,是不是我的电脑有问题
把尺寸改小看没问题了,看样子尺寸长了,计算量大,有时会出错。
#include <WindowsConstants.au3>
#include <WinAPIEx.au3>
#include <GDIPlusex.au3>
#include <APIConstants.au3>
OnAutoItExitRegister("ExitFunc")
Global $Timer_Second = 1
Global $SecondDelay = 50
Global $hGui = GUICreate("怀表", 201, 201, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
Global $hSecond = GUICreate("", 201, 201, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD, $WS_EX_TRANSPARENT), $hGui)
_GDIPlus_Startup()
Draw_Watch()
Global $hCallback = DllCallbackRegister("My_winProc", "int", "hWnd;uint;wparam;lparam")
Global $tCallback = DllCallbackGetPtr($hCallback)
Global $CallProc = _WinAPI_SetWindowLong($hGui, -4, $tCallback)
GUISetState(@SW_SHOW, $hGui)
GUISetState(@SW_SHOW, $hSecond)
_WinAPI_SetTimer($hGui, $Timer_Second, $SecondDelay, 0)
Do
Until GUIGetMsg() = -3
Func ExitFunc()
_WinAPI_KillTimer($hGui, $Timer_Second)
_WinAPI_SetWindowLong($hGui, -4, $CallProc)
_GDIPlus_Shutdown()
GUIDelete($hGui)
EndFunc ;==>ExitFunc
Func second()
Local $hPath
Local $hBitmap = _WinAPI_CreateBitmap(201, 201, 1, 32);建立背景位图
Local $hCDC = _WinAPI_CreateCompatibleDC(0);建立绘图DC
Local $hOld = _WinAPI_SelectObject($hCDC, $hBitmap);调入图片到DC
Local $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hCDC);从DC创建图形对象
_GDIPlus_GraphicsClear($hGraphics, 0x00000000);清空图形
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2);绘制质量 2 - 使用 8 X 8 矩形过滤器
_GDIPlus_GraphicsSetInterpolationMode($hGraphics, 7);插值法 7=High-quality, bicubic interpolation.
DllCall($ghGDIPDll, "uint", "GdipSetTextRenderingHint", "hwnd", $hGraphics, "int", 4)
;画时针
Local $hPath = _GDIPlus_PathCreate()
_GDIPlus_PathAddLine($hPath, 0, 0, 50, 0)
_GDIPlus_PathAddLine($hPath, 0, 0, -5, 0)
Local $hMatrix = _GDIPlus_MatrixCreate()
Local $hourAng = (@HOUR + @MIN / 60) * 30 - 90
_GDIPlus_MatrixTranslate($hMatrix, 101, 101)
_GDIPlus_MatrixRotate($hMatrix, $hourAng)
_GDIPlus_PathTransform($hPath, $hMatrix)
Local $hPen = _GDIPlus_PenCreate(0xFF0072E3, 3)
_GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen);这个函数里已经注销了$hPen
_GDIPlus_PathDispose($hPath)
;画分针
$hPath = _GDIPlus_PathCreate()
_GDIPlus_PathAddLine($hPath, 0, 0, 60, 0)
_GDIPlus_PathAddLine($hPath, 0, 0, -6, 0)
$hMatrix = _GDIPlus_MatrixCreate()
Local $miniuteAng = (@MIN + @SEC / 60) * 6 - 90
_GDIPlus_MatrixTranslate($hMatrix, 101, 101)
_GDIPlus_MatrixRotate($hMatrix, $miniuteAng)
_GDIPlus_PathTransform($hPath, $hMatrix)
$hPen = _GDIPlus_PenCreate(0xFF0066CC, 2)
_GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen);这个函数里已经注销了$hPen
_GDIPlus_PathDispose($hPath)
;画秒针
$hPath = _GDIPlus_PathCreate()
_GDIPlus_PathAddLine($hPath, 0, 0, 80, 0)
_GDIPlus_PathAddLine($hPath, 0, 0, -8, 0)
$hMatrix = _GDIPlus_MatrixCreate()
Local $secondAng = (@SEC + @MSEC / 1000) * 6 - 90
_GDIPlus_MatrixTranslate($hMatrix, 101, 101)
_GDIPlus_MatrixRotate($hMatrix, $secondAng)
_GDIPlus_PathTransform($hPath, $hMatrix)
$hPen = _GDIPlus_PenCreate(0xFF005AB5, 1)
_GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen);这个函数里已经注销了$hPen
_GDIPlus_PathDispose($hPath)
_GDIPlus_GraphicsDispose($hGraphics)
_WinAPI_SelectObject($hCDC, $hOld)
_WinAPI_DeleteDC($hCDC)
_WinAPI_UpdateLayeredWindowEx($hSecond, -1, -1, $hBitmap, 255, 1)
_WinAPI_DeleteObject($hBitmap)
DllCall('psapi.dll', 'int', 'EmptyWorkingSet', 'hWnd', -1) ;释放内存
EndFunc ;==>second
Func Draw_Watch()
Local $hBitmap = _WinAPI_CreateBitmap(201, 201, 1, 32);建立背景位图
Local $hCDC = _WinAPI_CreateCompatibleDC(0);建立绘图DC
Local $hOld = _WinAPI_SelectObject($hCDC, $hBitmap);调入图片到DC
Local $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hCDC);从DC创建图形对象
_GDIPlus_GraphicsClear($hGraphics, 0x00000000);清空图形
_GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2);绘制质量 2 - 使用 8 X 8 矩形过滤器
_GDIPlus_GraphicsSetInterpolationMode($hGraphics, 7);插值法 7=High-quality, bicubic interpolation.
DllCall($ghGDIPDll, "uint", "GdipSetTextRenderingHint", "hwnd", $hGraphics, "int", 4)
Local $hPath = _GDIPlus_PathCreate()
_GDIPlus_PathAddEllipse($hPath, 0, 0, 200, 200)
Local $hBrush = _GDIPlus_BrushCreateSolid(0x99FFFFFF)
_GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush);这个函数里已经注销了$hBrush
_GDIPlus_PathDispose($hPath)
Local $hPen = _GDIPlus_PenCreate(0xFF005AB5)
$hPath = circlePath(200, 5)
_GDIPlus_GraphicsDrawPath($hGraphics, $hPath, $hPen);这个函数里已经注销了$hPen
_GDIPlus_PathDispose($hPath)
$hBrush = _GDIPlus_BrushCreateSolid(0xFF005AB5)
$hPath = WatchPath(200, 5, 0.5, 6)
_GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush);这个函数里已经注销了$hBrush
_GDIPlus_PathDispose($hPath)
$hBrush = _GDIPlus_BrushCreateSolid(0xFF005AB5)
$hPath = WatchPath(200, 8, 1, 30)
_GDIPlus_GraphicsFillPath($hGraphics, $hPath, $hBrush);这个函数里已经注销了$hBrush
_GDIPlus_PathDispose($hPath)
Local $ColorArray = , $ZiArray =
Local $hImage
Local $pi = 3.14159265358979
For $i = 1 To 12
$hImage = _ImageString($i, $ColorArray, 24, 0x00000000)
$hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$tSIZE = _WinAPI_GetBitmapDimension($hBitmap2)
_WinAPI_DeleteObject($hBitmap2)
$SX = DllStructGetData($tSIZE, 'X') + 2
$SY = DllStructGetData($tSIZE, 'Y') + 2
$tSIZE = 0
$rad = $i * $pi / 6
$xx = 88 + Sin($rad) * 80
$yy = 86 - Cos($rad) * 80
If $i > 9 Then $xx -= 4
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, $xx, $yy, $SX, $SY)
_WinAPI_DeleteObject($hImage)
Next
$hImage = _ImageString("沙漏", $ZiArray, 16, 0xFFFFFFDF, "黑体")
$hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$tSIZE = _WinAPI_GetBitmapDimension($hBitmap2)
_WinAPI_DeleteObject($hBitmap2)
$SX = DllStructGetData($tSIZE, 'X') + 2
$SY = DllStructGetData($tSIZE, 'Y') + 2
$tSIZE = 0
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 82, 50, $SX, $SY)
_WinAPI_DeleteObject($hImage)
_GDIPlus_GraphicsDispose($hGraphics)
_WinAPI_SelectObject($hCDC, $hOld)
_WinAPI_DeleteDC($hCDC)
_WinAPI_UpdateLayeredWindowEx($hGui, -1, -1, $hBitmap, 255, 1)
_WinAPI_DeleteObject($hBitmap)
DllCall('psapi.dll', 'int', 'EmptyWorkingSet', 'hWnd', -1) ;释放内存
EndFunc ;==>Draw_Watch
Func My_winProc($hWnd, $Msg, $wParam, $lParam)
Switch $Msg
Case 0x0084;WM_NCHITTEST
Return $HTCAPTION
Case 0x00A3;WM_NCLMOUSEDBCLK
Exit
Case 0x0113;$WM_TIMER
Switch $wParam
Case $Timer_Second
second()
EndSwitch
EndSwitch
Return _WinAPI_CallWindowProc($CallProc, $hWnd, $Msg, $wParam, $lParam)
EndFunc ;==>My_winProc
Func ScalePath($R, $Height, $nStartAngle, $nSweepAngle)
Local $hPath = _GDIPlus_PathCreate()
_GDIPlus_PathAddArc($hPath, 0, 0, $R, $R, $nStartAngle, $nSweepAngle)
_GDIPlus_PathAddArc($hPath, $Height, $Height, $R - $Height * 2, $R - $Height * 2, $nStartAngle + $nSweepAngle, -$nSweepAngle)
_GDIPlus_PathCloseFigures($hPath)
Return $hPath
EndFunc ;==>ScalePath
Func circlePath($R, $Height)
Local $hPath = _GDIPlus_PathCreate()
_GDIPlus_PathAddEllipse($hPath, 0, 0, $R, $R)
_GDIPlus_PathAddEllipse($hPath, $Height, $Height, $R - $Height * 2, $R - $Height * 2)
Return $hPath
EndFunc ;==>circlePath
Func WatchPath($R, $Height, $sweepAng, $step)
Local $hPath1 = _GDIPlus_PathCreate()
Local $startAng = -$sweepAng / 2
For $Ang = $startAng To 360 - $sweepAng Step $step
$hPath = ScalePath($R, $Height, $Ang, $sweepAng)
_GDIPlus_PathAddPath($hPath1, $hPath, False)
_GDIPlus_PathDispose($hPath)
Next
Return $hPath1
EndFunc ;==>WatchPath
Func _ImageString($str, $ColorArray, $size = 38, $ColorSide = 0xFF333333, $font = "Arial")
Local $hPath = _GDIPlus_PathCreate()
Local $hFormat = _GDIPlus_StringFormatCreate(0x0004)
_GDIPlus_StringFormatSetAlign($hFormat, 0);0为左对齐,1为居中显示
Local $hFamily = _GDIPlus_FontFamilyCreate($font)
Local $tLayout = _GDIPlus_RectFCreate(0, 0)
_GDIPlus_PathAddString($hPath, $str, $tLayout, $hFamily, 0, $size, $hFormat);读取字符串外形为路径;0是正常字
Local $strXY = _GDIPlus_PathGetWorldBounds($hPath);字符串的区域范围
Local $hdisplayDC = _WinAPI_CreateCompatibleDC(0)
Local $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hdisplayDC)
Local $hImage = _GDIPlus_BitmapCreateFromGraphics($strXY + $strXY + 2, $strXY + $strXY + 2, $hGraphics)
Local $hContext = _GDIPlus_ImageGetGraphicsContext($hImage)
_GDIPlus_GraphicsClear($hContext, 0x00000000)
_GDIPlus_GraphicsSetSmoothingMode($hContext, 2);绘制质量 2 - 使用 8 X 8 矩形过滤器
_GDIPlus_GraphicsSetInterpolationMode($hContext, 7);插值法 7=High-quality, bicubic interpolation.
DllCall($ghGDIPDll, "uint", "GdipSetTextRenderingHint", "hwnd", $hContext, "int", 4)
Local $hPen = _PenInit($ColorSide)
_GDIPlus_PenSetLineJoin($hPen, 2);2 - Line join produces a smooth, circular arc between the lines.
DllCall($ghGDIPDll, "uint", "GdipDrawPath", "hwnd", $hContext, "hwnd", $hPen, "hwnd", $hPath);字体描边
_GDIPlus_PenDispose($hPen)
Local $hBrush = _PenInit($ColorArray, $size)
DllCall($ghGDIPDll, "uint", "GdipFillPath", "hwnd", $hContext, "hwnd", $hBrush, "hwnd", $hPath);填充
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_PathDispose($hPath)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_GraphicsDispose($hContext)
_GDIPlus_GraphicsDispose($hGraphics)
_WinAPI_DeleteDC($hdisplayDC)
Return $hImage
EndFunc ;==>_ImageString
Func _PenInit($ColorArray, $size = Default, $Angle = 90)
Switch UBound($ColorArray)
Case 0
If $size = Default Then $size = 2
Return _GDIPlus_PenCreate($ColorArray, $size, 0)
Case 1
If $size = Default Then $size = 2
Return _GDIPlus_PenCreate($ColorArray, $size, 0)
Case 2
If $size = Default Then $size = 38
Local $tRect = _GDIPlus_RectFCreate(0, 0, $size, $size);设置区域色块
Return _GDIPlus_LineBrushCreateFromRect($tRect, $ColorArray, $ColorArray, 1, 3);1为竖直方向渐变
Case Else
If $size = Default Then $size = 38
Local $tRect = _GDIPlus_RectFCreate(0, 0, $size, $size);设置区域色块
Local $hBrush = _GDIPlus_LineBrushCreateFromRectWithAngle($tRect, 0xFF000000, 0xFFFFFFFF, $Angle, True, 3)
;设置画刷多色渐变数组
Local $aInterpolations
Local $colorCount = UBound($ColorArray)
ReDim $aInterpolations[$colorCount + 1]
$aInterpolations = $colorCount;0,0保存颜色数
For $i = 1 To $colorCount
$aInterpolations[$i] = $ColorArray[$i - 1];设置颜色
$aInterpolations[$i] = Round(($i - 1) / ($colorCount - 1), 1);设置颜色位置,比如0.1即是离左边10%位置
Next
;设置画刷多色渐变
_GDIPlus_LineBrushSetPresetBlend($hBrush, $aInterpolations)
Return $hBrush
EndSwitch
EndFunc ;==>_PenInit
afan
发表于 2012-11-24 21:55:57
回复 30# seniors
我这测试也会变长,在“1”或“7”之后,似乎和角度有关…