happytc 发表于 2011-6-26 07:56:07

怎么实现象‘画图’(Mspaint.exe)那样画椭圆?[已解决]

本帖最后由 happytc 于 2011-8-25 23:50 编辑

就是按住左键不放,移动鼠标,那个椭圆也跟着光标动

不行了,通宵了,下面的代码,我怎么也想不到实现那种效果了

#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 - 1, @DesktopHeight - 1, 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 = 8
        $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
        $MouseYOri = $MousePos
    Sleep(50)
    Do
      
      
      $MousePos = GUIGetCursorInfo($hGUI)
      If $MouseXOri <> $MousePos Or $MouseYOri <> $MousePos Then
            ;_GDIPlus_GraphicsDrawLine($hGraphicBg, $MousePos, $MousePos, $MouseXOri, $MouseYOri, $hPen)
                        _GDIPlus_GraphicsDrawEllipse($hGraphicBg, $MousePos, $MousePos,$MouseXOri, $MouseYOri, $hPen)
            ;$MouseXOri = $MousePos
            ;$MouseYOri = $MousePos
      EndIf
    Until Not $MousePos
EndFunc

Func _Exit()
    GUISetCursor($CursorID, 1, $hGUI)
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "")
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphicBg)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Exit
EndFunc

happytc 发表于 2011-6-26 07:59:22

还有就是上面的代码在画椭圆时,怎么有时背景图一下就没有了呢?而画直线时(注释掉画椭圆那行,反注释那三行),背景图就一直在,为什么?

gapkiller 发表于 2011-6-26 14:16:39

这个要请教GDI高手啊
页: [1]
查看完整版本: 怎么实现象‘画图’(Mspaint.exe)那样画椭圆?[已解决]