Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GDIPlus.au3>
- #include <GUIConstants.au3>
- #include <WindowsConstants.au3>
- ;- Author: name22 (www.autoit.de)
- $iX = 50
- $iY = 30
- $sFont = "Arial"
- $iFontSize = 20
- $sString = "AutoIt"
- $hWnd = GUICreate("Beispiel", 200, 100)
- GUISetState()
- _GDIPlus_Startup()
- $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
- _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
- $hBrush = _GDIPlus_BrushCreateSolid(0xFF0000FF)
- $hStringFormat = _GDIPlus_StringFormatCreate()
- $hFamily = _GDIPlus_FontFamilyCreate($sFont)
- $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize)
- $tLayout = _GDIPlus_RectFCreate($iX, $iY) ;X und Y Koordinaten angeben, Breite und Höhe ist irrelevant und kann 0 bleiben
- $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sString, $hFont, $tLayout, $hStringFormat) ;Misst die Breite/Höhe des angegebenen Strings mit der Schrift in $hFont
- ;Die gewollten Daten stecken in einem DLLStruct in $aInfo[0] die anderen Array Elemente enthalten weitere Daten die hier nicht benötigt werden.
- ;Wie das Struct aufgebaut ist, steht in der Hilfe zu $tagGDIPRECTF
- $iWidth = DllStructGetData($aInfo[0], "Width") ;Breite
- $iHeight = DllStructGetData($aInfo[0], "Height") ;Höhe
- ;Hier wird das DLLStruct für PtInRect erstellt
- $tRect_AutoIt = DllStructCreate($tagRECT)
- DllStructSetData($tRect_AutoIt, "Left", $iX) ;Linke Kante des Rechtecks
- DllStructSetData($tRect_AutoIt, "Top", $iY) ;Obere Kante des Rechtecks
- DllStructSetData($tRect_AutoIt, "Right", $iX + $iWidth) ;Rechte Kante des Rechtecks
- DllStructSetData($tRect_AutoIt, "Bottom", $iY + $iHeight) ;Untere Kante des Rechtecks
- _Paint()
- GUIRegisterMsg($WM_PAINT, "_Paint") ;Neuzeichnen, falls Fenster verdeckt wurde.
- While True
- Switch GUIGetMsg()
- Case $GUI_EVENT_CLOSE
- ExitLoop
- Case $GUI_EVENT_PRIMARYDOWN ;Sobald die linke Maustaste innerhalb der Clientarea des Fensters geklickt wird, wird diese Nachricht gesendet.
- $tPoint_MousePos = _WinAPI_GetMousePos(True, $hWnd) ;Mausposition wird in einem DLLStruct zurückgegeben. Die Parameter geben an, dass die Koordinaten rel. zum Fenster sein sollen.
- If _WinAPI_PtInRect($tRect_AutoIt, $tPoint_MousePos) Then MsgBox(64, "Event", "Mausklick auf 'AutoIt' registriert.")
- EndSwitch
- WEnd
- Func _Paint()
- _GDIPlus_GraphicsClear($hGraphics, 0xFFFFFFFF)
- _GDIPlus_GraphicsDrawStringEx($hGraphics, $sString, $hFont, $tLayout, $hStringFormat, $hBrush) ;String zeichnen
- EndFunc
- ;Aufräumen - Wichtig!
- _GDIPlus_GraphicsDispose($hGraphics)
- _GDIPlus_BrushDispose($hBrush)
- _GDIPlus_StringFormatDispose($hStringFormat)
- _GDIPlus_FontFamilyDispose($hFamily)
- _GDIPlus_FontDispose($hFont)
- _GDIPlus_Shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement