Advertisement
name22

GDI+ Detect Mouseclick on String

Apr 12th, 2012
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.61 KB | None | 0 0
  1. #include <GDIPlus.au3>
  2. #include <GUIConstants.au3>
  3. #include <WindowsConstants.au3>
  4.  
  5. ;- Author: name22 (www.autoit.de)
  6.  
  7. $iX = 50
  8. $iY = 30
  9. $sFont = "Arial"
  10. $iFontSize = 20
  11. $sString = "AutoIt"
  12.  
  13. $hWnd = GUICreate("Beispiel", 200, 100)
  14. GUISetState()
  15.  
  16. _GDIPlus_Startup()
  17.  
  18. $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
  19. _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
  20.  
  21. $hBrush = _GDIPlus_BrushCreateSolid(0xFF0000FF)
  22.  
  23. $hStringFormat = _GDIPlus_StringFormatCreate()
  24. $hFamily = _GDIPlus_FontFamilyCreate($sFont)
  25. $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize)
  26. $tLayout = _GDIPlus_RectFCreate($iX, $iY) ;X und Y Koordinaten angeben, Breite und Höhe ist irrelevant und kann 0 bleiben
  27.  
  28. $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sString, $hFont, $tLayout, $hStringFormat) ;Misst die Breite/Höhe des angegebenen Strings mit der Schrift in $hFont
  29. ;Die gewollten Daten stecken in einem DLLStruct in $aInfo[0] die anderen Array Elemente enthalten weitere Daten die hier nicht benötigt werden.
  30. ;Wie das Struct aufgebaut ist, steht in der Hilfe zu $tagGDIPRECTF
  31. $iWidth = DllStructGetData($aInfo[0], "Width") ;Breite
  32. $iHeight = DllStructGetData($aInfo[0], "Height") ;Höhe
  33.  
  34. ;Hier wird das DLLStruct für PtInRect erstellt
  35. $tRect_AutoIt = DllStructCreate($tagRECT)
  36. DllStructSetData($tRect_AutoIt, "Left", $iX) ;Linke Kante des Rechtecks
  37. DllStructSetData($tRect_AutoIt, "Top", $iY) ;Obere Kante des Rechtecks
  38. DllStructSetData($tRect_AutoIt, "Right", $iX + $iWidth) ;Rechte Kante des Rechtecks
  39. DllStructSetData($tRect_AutoIt, "Bottom", $iY + $iHeight) ;Untere Kante des Rechtecks
  40.  
  41. _Paint()
  42. GUIRegisterMsg($WM_PAINT, "_Paint") ;Neuzeichnen, falls Fenster verdeckt wurde.
  43.  
  44. While True
  45.     Switch GUIGetMsg()
  46.         Case $GUI_EVENT_CLOSE
  47.             ExitLoop
  48.         Case $GUI_EVENT_PRIMARYDOWN ;Sobald die linke Maustaste innerhalb der Clientarea des Fensters geklickt wird, wird diese Nachricht gesendet.
  49.             $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.
  50.             If _WinAPI_PtInRect($tRect_AutoIt, $tPoint_MousePos) Then MsgBox(64, "Event", "Mausklick auf 'AutoIt' registriert.")
  51.     EndSwitch
  52. WEnd
  53.  
  54. Func _Paint()
  55.     _GDIPlus_GraphicsClear($hGraphics, 0xFFFFFFFF)
  56.     _GDIPlus_GraphicsDrawStringEx($hGraphics, $sString, $hFont, $tLayout, $hStringFormat, $hBrush) ;String zeichnen
  57. EndFunc
  58.  
  59. ;Aufräumen - Wichtig!
  60. _GDIPlus_GraphicsDispose($hGraphics)
  61. _GDIPlus_BrushDispose($hBrush)
  62. _GDIPlus_StringFormatDispose($hStringFormat)
  63. _GDIPlus_FontFamilyDispose($hFamily)
  64. _GDIPlus_FontDispose($hFont)
  65. _GDIPlus_Shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement