一直在问个最简单的GDI+的问题,就是如画图里(mspaint.exe)那样,点了画“直线后,按下左键拖动鼠标,那条直线就跟着鼠标动,但始终只有一条直线,而不象下面的代码那样:鼠标一动,画了无数直线
#Include <ScreenCapture.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global Const $CursorID = MouseGetCursor()
Global $hGUI, $hpen, $hGraphicBg
WhiteBoard()
Func WhiteBoard()
Local $HBITMAP, $hBmp, $PenSize, $ColorValue
Opt("GUIOnEventMode", 1)
_GDIPlus_Startup()
$HBITMAP = _ScreenCapture_Capture("", 0, 0, @DesktopWidth - 2, @DesktopHeight - 2, 0)
$hGUI = GUICreate("WhiteBoard-LiveCapture", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
GUISetState(@SW_SHOW, $hGUI)
$hGraphicBg = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBmp = _GDIPlus_BitmapCreateFromHBITMAP($HBITMAP)
_GDIPlus_GraphicsDrawImage($hGraphicBg, $hBmp, 0, 0)
_WinAPI_DeleteObject($HBITMAP)
$PenSize = 1
$hPen = _GDIPlus_PenCreate(0xA0FFFF00, $PenSize)
GUISetOnEvent(-3, "_Exit")
OnAutoItExitRegister("_Exit")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Draw", $hGUI)
While True
Sleep(2000)
WEnd
EndFunc
Func Draw()
Local $MousePos, $MouseXOri, $MouseYOri
GUISetCursor(0, 1, $hGUI)
$MousePos = GUIGetCursorInfo($hGUI)
$MouseXOri = $MousePos[0]
$MouseYOri = $MousePos[1]
Sleep(50)
Do
$MousePos = GUIGetCursorInfo($hGUI)
If $MouseXOri <> $MousePos[0] Or $MouseYOri <> $MousePos[1] Then
_GDIPlus_GraphicsDrawLine($hGraphicBg, $MousePos[0], $MousePos[1], $MouseXOri, $MouseYOri, $hPen)
;这里该如何写?才能不会搞动如下图那样的“刷子”样的无数直线?
EndIf
Until Not $MousePos[2]
EndFunc
Func _Exit()
GUISetCursor($CursorID, 1, $hGUI)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "")
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphicBg)
_GDIPlus_Shutdown()
GUIDelete($hGUI)
Exit
EndFunc
|