GDI+ Notitzzettel

  • Ich hatte die letzte Stunde Langeweile, und so ist ein Notitzzettel herausgekommen, der ausschließlich mit GDI+ gezeichnet wird.

    Ist zwar nichts besonderes, aber vieleicht hilft es jemandem, der sich noch nicht so gut mit GDI+ auskennt. :)

    Das ganze wird per Traymenü gesteuert.

    Kretik ist gerne gesehen. ;)

    Edit:
    - Rechtschreibfehler beseitigt. - Zacharja
    - Editfeld direkt über den Zettel gelegt. - Idee von UEZ
    - X zum schließen hinzugefügt.

    Wie ich die Fontauswahl einbinden könnte, weiß ich noch nicht so genau, bin aber am überlegen.

    GDI+ Notitzzettel
    [autoit]

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

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

    HotKeySet("{ESC}", "_Close")

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

    Opt("GUIOnEventMode", 1)

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

    Global $hWnd, $EditGUI, $Edit, $hGraphic, $hBitmap, $backbuffer, $brush1, $brush2, $pen1, $pen2, $pen3, $hFormat, $hFamily, $hFont, $tLayout, $aInfo
    Global $ScreenDc, $dc, $tSize, $pSize, $tSource, $pSource, $tBlend, $pBlend, $tPoint, $pPoint, $gdibitmap
    Global $title = "Notizzettel", _
    $user32 = DllOpen("user32.dll"), _
    $width = 150, _
    $height = 200

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

    Global $notice = "Durch drücken und ziehen des Eselohrs, können Sie die Fensterposition ändern. " & @CRLF & @CRLF & _
    "Wenn Sie die Notiz ändern wollen, klicken Sie auf die bereits vorhandene Notiz. " & @CRLF & @CRLF & _
    "Um den Notizzettel zu schließen, klicken Sie auf das rote X. "

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

    Global $WinPos[4], $MousePos[2]

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

    Global $points[6][2]

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

    $points[0][0] = 5
    $points[1][0] = 0
    $points[1][1] = 20
    $points[2][0] = 20
    $points[2][1] = 0
    $points[3][0] = 149
    $points[3][1] = 0
    $points[4][0] = 149
    $points[4][1] = 199
    $points[5][0] = 0
    $points[5][1] = 199

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

    $hWnd = GUICreate($title, $width, $height, -1, -1, 0x80000000, BitOR(0x00000080, 0x00080000, 0x00000008))

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

    _Startup()

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

    _DrawSheet()

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

    GUISetState(@SW_SHOW, $hWnd)

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

    $EditGUI = GuiCreate($title & " Edit", 110, 155, -1, -1, BitOr(0x80000000, 0x00000200), BitOR(0x00000080, 0x00000008))
    $Edit = GUICtrlCreateEdit($notice, 0, 0, 110, 155, BitOR(0x1000, 0x0004, 0x0040), 0x00000204)

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

    GUISetState(@SW_HIDE, $EditGUI)

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

    While 1
    If _IsPressed("01") And WinActive($hWnd) Then
    $WinPos = WinGetPos($hWnd)
    $MousePos = MouseGetPos()
    If $MousePos[0] >= $WinPos[0] And $MousePos[0] <= $WinPos[0] + 20 And $MousePos[1] >= $WinPos[1] And $MousePos[1] <= $WinPos[1] + 20 Then
    GUISetState(@SW_HIDE, $EditGUI)
    MouseMove($WinPos[0] + 10, $WinPos[1] + 10, 0)
    GUISetCursor(9, 1, $hWnd)
    While _IsPressed("01")
    $MousePos = MouseGetPos()
    WinMove($hWnd, "", $MousePos[0] - 10, $MousePos[1] - 10)
    WEnd
    GUISetCursor(2, 0, $hWnd)
    ElseIf $MousePos[0] >= $WinPos[0] + 20 And $MousePos[0] <= $WinPos[0] + 130 And $MousePos[1] >= $WinPos[1] + 25 And $MousePos[1] <= $WinPos[1] + 185 Then
    WinMove($EditGUI, "", $WinPos[0] + 20, $WinPos[1] + 25)
    GUISetState(@SW_SHOW, $EditGUI)
    ElseIf $MousePos[0] >= $WinPos[0] + 135 And $MousePos[0] <= $WinPos[0] + 145 And $MousePos[1] >= $WinPos[1] + 5 And $MousePos[1] <= $WinPos[1] + 15 Then
    _Close()
    Else
    GUISetState(@SW_HIDE, $EditGUI)
    EndIf
    EndIf
    If _IsPressed("0D") And _IsPressed("11") And WinActive($EditGUI) Then
    $notice = GUICtrlRead($Edit)
    GUISetState(@SW_HIDE, $EditGUI)
    _DrawSheet()
    EndIf
    Sleep(10)
    WEnd

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

    Func _Startup()
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
    $backbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($backbuffer, 4)

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

    $brush1 = _GDIPlus_BrushCreateSolid(0xFFF8F8FF)
    $brush2 = _GDIPlus_BrushCreateSolid()
    $pen1 = _GDIPlus_PenCreate(0xFF4169E1)
    $pen2 = _GDIPlus_PenCreate(0x224169E1)
    $pen3 = _GDIPlus_PenCreate(0xFFFF0000, 2)

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

    $ScreenDc = _WinAPI_GetDC($hWnd)
    $dc = _WinAPI_CreateCompatibleDC($ScreenDc)

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

    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $width)
    DllStructSetData($tSize, "Y", $height)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", 255)
    DllStructSetData($tBlend, "Format", 1)
    $tPoint = DllStructCreate($tagPOINT)
    $pPoint = DllStructGetPtr($tPoint)
    DllStructSetData($tPoint, "X", 0)
    DllStructSetData($tPoint, "Y", 0)

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

    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 9, 0, 2)
    $tLayout = _GDIPlus_RectFCreate(20, 25, 110, 155)
    EndFunc

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

    Func _Close()
    GUISetState(@SW_MINIMIZE, $hWnd)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    DllClose($user32)
    Exit
    EndFunc

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

    Func _DrawSheet()
    _GDIPlus_GraphicsFillPolygon($backbuffer, $points, $brush1)

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

    _GDIPlus_GraphicsDrawPolygon($backbuffer, $points, $pen1)

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

    _GDIPlus_GraphicsDrawLine($backbuffer, $points[1][0], $points[1][1], 20, 20, $pen1)
    _GDIPlus_GraphicsDrawLine($backbuffer, 20, 20, $points[2][0], $points[2][1], $pen1)

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

    _GDIPlus_GraphicsDrawLine($backbuffer, 4, 16, 4, 199, $pen2)
    _GDIPlus_GraphicsDrawLine($backbuffer, 9, 12, 9, 199, $pen2)
    _GDIPlus_GraphicsDrawLine($backbuffer, 14, 6, 14, 199, $pen2)

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

    For $i = 19 To $width Step +5
    _GDIPlus_GraphicsDrawLine($backbuffer, $i, 0, $i, 199, $pen2)
    Next

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

    _GDIPlus_GraphicsDrawLine($backbuffer, 16, 4, 149, 4, $pen2)
    _GDIPlus_GraphicsDrawLine($backbuffer, 12, 9, 149, 9, $pen2)
    _GDIPlus_GraphicsDrawLine($backbuffer, 5, 14, 149, 14, $pen2)

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

    For $i = 19 To $height Step +5
    _GDIPlus_GraphicsDrawLine($backbuffer, 0, $i, 149, $i, $pen2)
    Next

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

    _GDIPlus_GraphicsDrawLine($backbuffer, 135, 5, 145, 15, $pen3)
    _GDIPlus_GraphicsDrawLine($backbuffer, 135, 15, 145, 5, $pen3)

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

    $aInfo = _GDIPlus_GraphicsMeasureString($backbuffer, $notice, $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDrawStringEx($backbuffer, $notice, $hFont, $aInfo[0], $hFormat, $brush2)

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

    $gdibitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_SelectObject($dc, $gdibitmap)
    _WinAPI_UpdateLayeredWindow($hWnd, $ScreenDc, 0, $pSize, $dc, $pSource, 0, $pBlend, 2)
    _WinAPI_DeleteObject($gdibitmap)
    EndFunc

    [/autoit]
    Zitat

    [Heute, 11:39] Raupi: Soll ich es dir machen?
    [Heute, 11:47] BugFix: "Soll ich es dir machen? " - also Raupi !! bitte nicht so öffentlich :rofl:

    Zitat

    [Heute, 11:51] BugFix: und ich werde es mir jetzt machen - das Mittagessen :P

    AMsg UDF v1.00.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%
    OwnStyle UDF Version 1.10.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%

    2 Mal editiert, zuletzt von H2112 (25. Februar 2010 um 21:11)

  • Richtig toll :)
    Zum verbessern:
    - Es heißt "Notiz" nicht "Notitz"
    - Es wäre schön wenn man die Input-Box nicht manuell aufrufen muss

    Funktioniert prima ;D

  • Cool wäre es, wenn ich in den Notizzettel klicken könnte, so dass die Eingabe direkt auf den Zettel geschrieben werden könnte oder mit der Maus (vielleicht zu schwierig)!

    Fontauswahl wäre auch von Vorteil :D

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Toole Sache, die Idee von UEZ ist nicht schlecht, du könntest ein weiteres Gui mit einem Edit-Feld darüberlegen, das beim Text ändern erscheint. ;)

  • Danke für die Rückmeldungen, ich werd mich bemühen eure wünsche schnellstmöglich umzusetzen. :)

    Edit:
    - Rechtschreibfehler beseitigt. - Zacharja
    - Editfeld direkt über den Zettel gelegt. - Idee von UEZ
    - X zum schließen hinzugefügt.

    Zitat

    [Heute, 11:39] Raupi: Soll ich es dir machen?
    [Heute, 11:47] BugFix: "Soll ich es dir machen? " - also Raupi !! bitte nicht so öffentlich :rofl:

    Zitat

    [Heute, 11:51] BugFix: und ich werde es mir jetzt machen - das Mittagessen :P

    AMsg UDF v1.00.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%
    OwnStyle UDF Version 1.10.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%

    Einmal editiert, zuletzt von H2112 (25. Februar 2010 um 21:10)

  • Naja immerhin ein Anfang :rolleyes:

    Spoiler anzeigen
    [autoit]

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

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

    HotKeySet("{ESC}", "_Clear")

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

    Global $GUIColorBG = 0xFFFFFFFF
    Global $LineColor = 0xFF000000
    Global $LineWidth = 6

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

    $TestGUI = GUICreate("Test", 400, 400)
    GUISetState()

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

    _GDIPlus_Startup()

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

    Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($TestGUI)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
    _GDIPlus_GraphicsClear($hGraphics, $GUIColorBG)

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

    Global $hBrush = _GDIPlus_BrushCreateSolid($LineColor)

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

    While 1
    $nMsg = GUIGetMsg(1)
    Switch $nMsg[0]
    Case $GUI_EVENT_PRIMARYDOWN
    While _IsPressed("01") = 1
    $nMsg = GUIGetMsg(1)
    _DrawFreehand($nMsg[3], $nMsg[4])
    Sleep(50)
    WEnd
    Case $GUI_EVENT_CLOSE
    _GDIPlus_GraphicsDispose($hGraphics)
    Exit
    EndSwitch
    WEnd

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

    Func _DrawFreehand($MousePosX, $MousePosY)
    _GDIPlus_GraphicsFillEllipse($hGraphics, $MousePosX - $LineWidth / 2, $MousePosY - $LineWidth / 2, $LineWidth, $LineWidth, $hBrush)
    EndFunc

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

    Func _Clear()
    _GDIPlus_GraphicsClear($hGraphics, $GUIColorBG)
    EndFunc

    [/autoit]

    Edit: Und hier die bessere Version von Oscar

    Spoiler anzeigen
    [autoit]

    #include<Misc.au3>
    #include<GuiConstantsEx.au3>
    #include<GDIPlus.au3>
    Opt('MouseCoordMode', 2)
    _Main()

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

    Func _Main()
    Local $hGUI, $hWnd, $hGraphic, $hPen, $aPos[2], $aOldPos[2]
    Local $width = @DesktopWidth, $height = @DesktopHeight
    Local $dll = DllOpen('user32.dll')
    $hGUI = GUICreate('GDI+', $width, $height)
    $hWnd = WinGetHandle('GDI+')
    GUISetState()
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hPen = _GDIPlus_PenCreate(0xff00ff00, 2)
    $timer = TimerInit()
    Do
    $aPos = MouseGetPos()
    If _IsPressed('01', $dll) Then
    _GDIPlus_GraphicsDrawLine($hGraphic, $aOldPos[0], $aOldPos[1], $aPos[0], $aPos[1], $hPen)
    If TimerDiff($timer) > 500 Then
    _GDIPlus_PenSetColor($hPen, '0xFF' & StringRight(Hex(Random(0, 16777215, 1)), 6))
    $timer = TimerInit()
    EndIf
    EndIf
    $aOldPos[0] = $aPos[0]
    $aOldPos[1] = $aPos[1]
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    ; Clean up resources
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    DllClose($dll)
    EndFunc ;==>_Main

    [/autoit]
  • Ja der Befehl war mir auch klar, nur wusste ich nicht ob ich das mit einem Button oder sonstigem einbinden sollte.

    Trotzdem Danke. ;)

    Zitat

    [Heute, 11:39] Raupi: Soll ich es dir machen?
    [Heute, 11:47] BugFix: "Soll ich es dir machen? " - also Raupi !! bitte nicht so öffentlich :rofl:

    Zitat

    [Heute, 11:51] BugFix: und ich werde es mir jetzt machen - das Mittagessen :P

    AMsg UDF v1.00.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%
    OwnStyle UDF Version 1.10.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%