GDI+ Auf Desktop/Bildschirm zeichnen.

  • BadBunny hat mich in der Shoutbox gefragt wie man Kreise auf ein transparentes Fenster malen könnte, um so wie bei Paint o.Ä. zu malen. (Ich hoffe ich hab das richtig verstanden :S ).
    Naja, hier ist das Script. Gezeichnet wird übrigens durch Gedrückthalten der Strg Taste, während ihr mit Entfernen alles löschen könnt. Viel Spaß :D!

    Edit: P.S: Mit Escape könnt ihr das Script beenden :whistling: ...

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    #include <GDIPlus.au3>
    #include <WinAPI.au3>
    #include <Misc.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ; - Author: name22 (http://www.autoit.de)

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)
    OnAutoItExitRegister("_Close")

    [/autoit] [autoit][/autoit] [autoit]

    $vUser32DLL = DllOpen("User32.dll")

    [/autoit] [autoit][/autoit] [autoit]

    $iGUIWidth = @DesktopWidth
    $iGUIHeight = @DesktopHeight

    [/autoit] [autoit][/autoit] [autoit]

    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $iGUIWidth)
    DllStructSetData($tSize, "Y", $iGUIHeight)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", 255)
    DllStructSetData($tBlend, "Format", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $hWnd = GUICreate("", $iGUIWidth, $iGUIHeight, 0, 0, BitOR(0x80000000, 0x08000000), BitOR(0x00080000, 0x00000008, 0x00000080))
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    $hDC_Window = _WinAPI_GetDC($hWnd)
    $hDC_Buffer = _WinAPI_CreateCompatibleDC($hDC_Window)
    $hBitmap_Buffer = _WinAPI_CreateCompatibleBitmap($hDC_Window, $iGUIWidth, $iGUIHeight)
    _WinAPI_SelectObject($hDC_Buffer, $hBitmap_Buffer)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC_Buffer)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)

    [/autoit] [autoit][/autoit] [autoit]

    $hPen_Draw = _GDIPlus_PenCreate(0xFF000000, 15)
    _GDIPlus_PenSetLineCap($hPen_Draw, 0x02, 0x02, 2)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Close", $hWnd)
    HotKeySet("{DELETE}", "_Erase")
    HotKeySet("{ESC}", "_Close")

    [/autoit] [autoit][/autoit] [autoit]

    $aMousePos = MouseGetPos()
    $aMousePos_Old = MouseGetPos()

    [/autoit] [autoit][/autoit] [autoit]

    While Sleep(15)
    $aMousePos = MouseGetPos()
    Switch True
    Case _IsPressed("11", $vUser32DLL)
    Switch True
    Case $aMousePos[0] <> $aMousePos_Old[0] Or $aMousePos[1] <> $aMousePos_Old[1]
    _GDIPlus_GraphicsDrawLine($hGraphics, $aMousePos_Old[0], $aMousePos_Old[1], $aMousePos[0], $aMousePos[1], $hPen_Draw)
    EndSwitch
    EndSwitch

    [/autoit] [autoit][/autoit] [autoit]

    $aMousePos_Old = $aMousePos

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_UpdateLayeredWindow($hWnd, $hDC_Window, 0, $pSize, $hDC_Buffer, $pSource, 0, $pBlend, 2)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Erase()
    _GDIPlus_GraphicsClear($hGraphics, 0x00000000)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Close()
    _WinAPI_ReleaseDC($hWnd, $hDC_Window)
    _WinAPI_DeleteDC($hDC_Buffer)
    _WinAPI_DeleteObject($hBitmap_Buffer)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_PenDispose($hPen_Draw)
    _GDIPlus_Shutdown()

    [/autoit] [autoit][/autoit] [autoit]

    DllClose($vUser32DLL)
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    #region "GDIP.au3 Functions"
    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GDIPlus_PenSetLineCap
    ; Description ...: Sets the cap styles for the start, end, and dashes in a line drawn with the pen
    ; Syntax.........: _GDIPlus_PenSetLineCap($hPen, $iStartCap, $iEndCap, $iDashCap)
    ; Parameters ....: $hPen - Pointer to a Pen object
    ; $iStartCap - Line cap style for the start cap:
    ; |0x00 - Line ends at the last point. The end is squared off
    ; |0x01 - Square cap. The center of the square is the last point in the line. The height
    ; +and width of the square are the line width.
    ; |0x02 - Circular cap. The center of the circle is the last point in the line. The diameter
    ; +of the circle is the line width.
    ; |0x03 - Triangular cap. The base of the triangle is the last point in the line. The base
    ; +of the triangle is the line width.
    ; |0x10 - Line ends are not anchored.
    ; |0x11 - Line ends are anchored with a square. The center of the square is the last point in
    ; +the line. The height and width of the square are the line width.
    ; |0x12 - Line ends are anchored with a circle. The center of the circle is at the last point
    ; +in the line. The circle is wider than the line.
    ; |0x13 - Line ends are anchored with a diamond (a square turned at 45 degrees). The center of the diamond is at
    ; +the last point in the line. The diamond is wider than the line.
    ; |0x14 - Line ends are anchored with arrowheads. The arrowhead point is located at the last
    ; +point in the line. The arrowhead is wider than the line.
    ; |0xff - Line ends are made from a CustomLineCap object
    ; $iEndCap - Line cap style for the end cap (same values as $iStartCap)
    ; $iDashCap - Start and end caps for a dashed line:
    ; |0 - A square cap that squares off both ends of each dash
    ; |2 - A circular cap that rounds off both ends of each dash
    ; |3 - A triangular cap that points both ends of each dash
    ; Return values .: Success - True
    ; Failure - False and either:
    ; |@error and @extended are set if DllCall failed
    ; |$GDIP_STATUS contains a non zero value specifying the error code
    ; Remarks .......: None
    ; Related .......: _GDIPlus_PenSetDashCap, _GDIPlus_PenSetEndCap, _GDIPlus_PenSetStartCap
    ; Link ..........; @@MsdnLink@@ GdipSetPenLineCap197819
    ; Example .......; No
    ; ===============================================================================================================================
    Func _GDIPlus_PenSetLineCap($hPen, $iStartCap, $iEndCap, $iDashCap)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetPenLineCap197819", "hwnd", $hPen, "int", $iStartCap, "int", $iEndCap, "int", $iDashCap)

    [/autoit] [autoit][/autoit] [autoit]

    If @error Then Return SetError(@error, @extended, False)
    $GDIP_STATUS = $aResult[0]
    Return $aResult[0] = 0
    EndFunc ;==>_GDIPlus_PenSetLineCap
    #endregion "GDIP.au3 Functions"

    [/autoit]
  • *hust*
    H2112 hat bereits eine UDF zu diesem Thema geschrieben, wo man auch Bilder usw rauf zeichnen kann, danke trotzdem ;)

    Es gibt sehr viele Leute, die glauben. Aber aus Aberglauben.
    - Blaise Pascal

  • Zitat

    H2112 hat bereits eine UDF zu diesem Thema geschrieben, wo man auch Bilder usw rauf zeichnen kann, danke trotzdem ;)


    ... Setze doch mal das was ich hier gepostet habe mit den Funktionen aus seiner UDF um...
    Außerdem verwendet er nicht die selbe Methode wie ich um auf den Bildschirm zu zeichnen.

  • Mein Problem wenn ich dein Script starte - Es kommt nichts, hat da seine richtigkeit ?

    Es gibt sehr viele Leute, die glauben. Aber aus Aberglauben.
    - Blaise Pascal

  • Schaut nice aus :)
    Nur 2Fehler, die Delete funktion klappt bei mir nicht.
    Win xp 32bit
    Und wenn ich das Programm starte ist unten so ein weißer balken 1/4 über der Leiste wo die Uhr & Icon's sind.

  • Zitat

    Und wenn ich das Programm starte ist unten so ein weißer balken 1/4 über der Leiste wo die Uhr & Icon's sind.


    :huh: Ich hab kein XP und ich kann dir da nicht wirklich weiterhelfen... Aber vielleicht hat ein XP Experte ja Ahnung woran das liegt.

    Zitat

    die Delete funktion klappt bei mir nicht.


    Hast du schon versucht es auf einen anderen HotKey zu legen, oder anders aufzurufen?