Beiträge von eukalyptus
-
-
Na, welche Werte werden das wohl sein?...
-
Hier bitte:
Spoiler anzeigen
[autoit]#include <GDIPlus.au3>
[/autoit] [autoit][/autoit] [autoit]
#include <WinAPI.au3>_Create(@ScriptDir & "\Test.emf", 200, 30)
[/autoit] [autoit][/autoit] [autoit]Func _Create($sFileName, $fS, $fH)
[/autoit] [autoit][/autoit] [autoit]
Local Const $PI = ATan(1) * 4 ; Konstante PI = 3.14159265358979
Local Const $Deg2Rad = $PI / 180 ; zum Umrechnen von Grad zu Bogenmaß
Local Const $Rad2Deg = 180 / $PILocal $fTmp = Sqrt($fH ^ 2 + $fS ^ 2 / 4) ;siehe: http://www.arndt-bruenner.de/mathe/scripts/kreissehnen.htm
[/autoit] [autoit][/autoit] [autoit]
Local $fBeta = 2 * ASin($fS / (2 * $fTmp))
Local $fAlpha = 2 * ($PI - $fBeta) ; Öffnungswinkel des Kreisbogens
Local $fR = $fS / (2 * Sin($fAlpha / 2)) ; Radius
Local $fH2 = $fR - $fH ; Mittelpunkt zu Kreissehne_GDIPlus_Startup() ; Gdiplus DLL laden
[/autoit] [autoit][/autoit] [autoit]
Local $hDC = _WinAPI_GetDC(_WinAPI_GetDesktopWindow()) ;DeviceContext des Bildschirms bekommenLocal $tRectF = _GDIPlus_RectFCreate(0, 0, $fR * 2, $fR * 2) ;Rechteck erzeugen, welches den Kreis umschliesst; deshalb 0 - Radius * 2; das könnten auch A4-Masse sein...
[/autoit] [autoit][/autoit] [autoit];Metafile aus DeviceContext erzeugen, Typ = EMF+, Masse des Rechtecks = mm
[/autoit] [autoit][/autoit] [autoit]
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipRecordMetafileFileName", "wstr", $sFileName, "hwnd", $hDC, "int", 5, "ptr", DllStructGetPtr($tRectF), "int", 6, "wstr", "KreisSegment", "int*", 0)
Local $hImage = $aResult[7]Local $hContext = _GDIPlus_ImageGetGraphicsContext($hImage) ;GraphicContext vom Metafile bekommen (um darauf zu zeichnen)
[/autoit] [autoit][/autoit] [autoit]
DllCall($ghGDIPDll, "uint", "GdipSetPageUnit", "hwnd", $hContext, "int", 6) ; Einheit auf mm setzen;Speicher reservieren, um Headerinformationen auszulesen; wir benötigen später die DPI-Auflösung
[/autoit] [autoit][/autoit] [autoit]
Local $tHeader = DllStructCreate("int Type;" & _
"uint Size;" & _ ; Size of the metafile (in bytes)
"uint Version;" & _ ; EMF+, EMF, or WMF version
"uint EmfPlusFlags;" & _
"float DpiX;" & _
"float DpiY;" & _
"int X;" & _ ; Bounds in device units
"int Y;" & _
"int Width;" & _
"int Height;" & _
"uint Type;" & _ ; Record type EMR_HEADER
"uint Size;" & _ ; Record size in bytes. This may be greater than the sizeof $tagGDIPMETAHEADER
"int BoundLeft;" & _ ; Inclusive-inclusive bounds in device units
"int BoundTop;" & _
"int BoundRight;" & _
"int BoundBottom;" & _
"int FrameLeft;" & _ ; Inclusive-inclusive Picture Frame .01mm unit
"int FrameTop;" & _
"int FrameRight;" & _
"int FrameBottom;" & _
"uint Signature;" & _ ; Signature. Must be $GDIP_ENHMETA_SIGNATURE
"uint Version;" & _ ; Version number
"uint Bytes;" & _ ; Size of the metafile in bytes
"uint Records;" & _ ; Number of records in the metafile
"ushort Handles;" & _ ; Number of handles in the handle table. Handle index zero is reserved
"ushort Reserved;" & _ ; Reserved. Must be zero
"uint DescriptionChars;" & _ ; Number of chars in the unicode desc string This is 0 if there is no description string
"uint DescriptionOffset;" & _ ; Offset to the metafile description record. This is 0 if there is no description string
"uint PalEntries;" & _ ; Number of entries in the metafile palette
"int cxPixels;" & _ ; Size of the reference device in pixels
"int cyPixels;" & _
"int cxMillimeters;" & _; Size of the reference device in millimeters
"int cyMillimeters;" & _
"int EmfPlusHeaderSize;" & _ ; size of the EMF+ header in file
"int LogicalDpiX;" & _ ; Logical Dpi of reference Hdc
"int LogicalDpiY;") ; usually valid only for EMF+DllCall($ghGDIPDll, "uint", "GdipGetMetafileHeaderFromMetafile", "hwnd", $hImage, "ptr", DllStructGetPtr($tHeader)); Headerinformationen auslesen
[/autoit] [autoit][/autoit] [autoit]Local $fM_DpiX = DllStructGetData($tHeader, "DpiX") ; Auflösung in DPI horizontal vom Metafile
[/autoit] [autoit][/autoit] [autoit]
Local $fM_DpiY = DllStructGetData($tHeader, "DpiY") ; Auflösung in DPI vertikal vom Metafile$aResult = DllCall($ghGDIPDll, "uint", "GdipGetDpiX", "hwnd", $hContext, "float*", 0) ; Auflösung in DPI horizontal vom GraphicContext
[/autoit] [autoit][/autoit] [autoit]
Local $fG_DpiX = $aResult[2]
$aResult = DllCall($ghGDIPDll, "uint", "GdipGetDpiY", "hwnd", $hContext, "float*", 0) ; Auflösung in DPI vertikal vom GraphicContext
Local $fG_DpiY = $aResult[2];GraphicContext skalieren, damit die Grafik wirklich in mm ist - das sollte eigentlich nicht notwendig sein!?
[/autoit] [autoit][/autoit] [autoit]
;Jedoch hat das fertige EMF nur so die richtige Größe in IncScape...
DllCall($ghGDIPDll, "uint", "GdipScaleWorldTransform", "hwnd", $hContext, "float", $fM_DpiX / $fG_DpiX, "float", $fM_DpiY / $fG_DpiY, "int", 0)Local $hPen_1 = _GDIPlus_PenCreate(0xFFFF0000, 2) ; Pinsel Rot Stärke = 2
[/autoit] [autoit][/autoit] [autoit]
Local $hPen_2 = _GDIPlus_PenCreate(0xFF00FF00, 2) ; Pinsel Grün Stärke = 2
Local $hPen_3 = _GDIPlus_PenCreate(0xFF0000FF, 1) ; Pinsel Blau Stärke = 1DllCall($ghGDIPDll, "int", "GdipDrawArc", "handle", $hContext, "handle", $hPen_1, "float", 0, "float", 0, _
[/autoit] [autoit][/autoit] [autoit]
"float", $fR * 2, "float", $fR * 2, "float", 270 - ($fAlpha * $Rad2Deg) / 2, "float", $fAlpha * $Rad2Deg) ;Kreisbogen des Segments in Rot zeichnenDllCall($ghGDIPDll, "int", "GdipDrawLine", "handle", $hContext, "handle", $hPen_2, "float", $fR - $fS / 2, "float", $fH, _
[/autoit] [autoit][/autoit] [autoit]
"float", $fR + $fS / 2, "float", $fH) ;Kreissehne in Grün zeichnenDllCall($ghGDIPDll, "int", "GdipDrawArc", "handle", $hContext, "handle", $hPen_3, "float", 0, "float", 0, _
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
"float", $fR * 2, "float", $fR * 2, "float", 270 + ($fAlpha * $Rad2Deg) / 2, "float", 360 - ($fAlpha * $Rad2Deg)) ; restlicher Kreisbogen in Blau_GDIPlus_PenDispose($hPen_1) ; Pinsel im Speicher wieder freigeben
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_PenDispose($hPen_2)
_GDIPlus_PenDispose($hPen_3)
_GDIPlus_GraphicsDispose($hContext) ; Metafile abschliesen und speichern_GDIPlus_ImageDispose($hImage) ; Metafile aus Speicher löschen
[/autoit]
_WinAPI_ReleaseDC(_WinAPI_GetDesktopWindow(), $hDC) ;DeviceContext freigeben
_GDIPlus_Shutdown() ;GdiPlus DLL schließen
EndFunc ;==>_Create -
Oder erstelle mit GDI+ eine Metafile
EMF lassen sich sicher mit AI öffnenSpoiler anzeigen
[autoit]#include <GDIPlus.au3>
[/autoit] [autoit][/autoit] [autoit]
#include <WinAPI.au3>_Create(@ScriptDir & "\Test.emf", 200, 30)
[/autoit] [autoit][/autoit] [autoit]Func _Create($sFileName, $fS, $fH)
[/autoit] [autoit][/autoit] [autoit]
Local Const $PI = ATan(1) * 4
Local Const $Deg2Rad = $PI / 180
Local Const $Rad2Deg = 180 / $PILocal $fTmp = Sqrt($fH ^ 2 + $fS ^ 2 / 4)
[/autoit] [autoit][/autoit] [autoit]
Local $fBeta = 2 * ASin($fS / (2 * $fTmp))
Local $fAlpha = 2 * ($PI - $fBeta)
Local $fR = $fS / (2 * Sin($fAlpha / 2))
Local $fH2 = $fR - $fH_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit]
Local $hDC = _WinAPI_GetDC(_WinAPI_GetDesktopWindow())Local $tRectF = _GDIPlus_RectFCreate(0, 0, $fR * 2, $fR * 2)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipRecordMetafileFileName", "wstr", $sFileName, "hwnd", $hDC, "int", 5, "ptr", DllStructGetPtr($tRectF), "int", 6, "wstr", "KreisSegment", "int*", 0)
Local $hImage = $aResult[7]
Local $hContext = _GDIPlus_ImageGetGraphicsContext($hImage)
DllCall($ghGDIPDll, "uint", "GdipSetPageUnit", "hwnd", $hContext, "int", 6)Local $tHeader = DllStructCreate("int Type;" & _
[/autoit] [autoit][/autoit] [autoit]
"uint Size;" & _ ; Size of the metafile (in bytes)
"uint Version;" & _ ; EMF+, EMF, or WMF version
"uint EmfPlusFlags;" & _
"float DpiX;" & _
"float DpiY;" & _
"int X;" & _ ; Bounds in device units
"int Y;" & _
"int Width;" & _
"int Height;" & _
"uint Type;" & _ ; Record type EMR_HEADER
"uint Size;" & _ ; Record size in bytes. This may be greater than the sizeof $tagGDIPMETAHEADER
"int BoundLeft;" & _ ; Inclusive-inclusive bounds in device units
"int BoundTop;" & _
"int BoundRight;" & _
"int BoundBottom;" & _
"int FrameLeft;" & _ ; Inclusive-inclusive Picture Frame .01mm unit
"int FrameTop;" & _
"int FrameRight;" & _
"int FrameBottom;" & _
"uint Signature;" & _ ; Signature. Must be $GDIP_ENHMETA_SIGNATURE
"uint Version;" & _ ; Version number
"uint Bytes;" & _ ; Size of the metafile in bytes
"uint Records;" & _ ; Number of records in the metafile
"ushort Handles;" & _ ; Number of handles in the handle table. Handle index zero is reserved
"ushort Reserved;" & _ ; Reserved. Must be zero
"uint DescriptionChars;" & _ ; Number of chars in the unicode desc string This is 0 if there is no description string
"uint DescriptionOffset;" & _ ; Offset to the metafile description record. This is 0 if there is no description string
"uint PalEntries;" & _ ; Number of entries in the metafile palette
"int cxPixels;" & _ ; Size of the reference device in pixels
"int cyPixels;" & _
"int cxMillimeters;" & _; Size of the reference device in millimeters
"int cyMillimeters;" & _
"int EmfPlusHeaderSize;" & _ ; size of the EMF+ header in file
"int LogicalDpiX;" & _ ; Logical Dpi of reference Hdc
"int LogicalDpiY;") ; usually valid only for EMF+DllCall($ghGDIPDll, "uint", "GdipGetMetafileHeaderFromMetafile", "hwnd", $hImage, "ptr", DllStructGetPtr($tHeader))
[/autoit] [autoit][/autoit] [autoit]Local $fM_DpiX = DllStructGetData($tHeader, "DpiX")
[/autoit] [autoit][/autoit] [autoit]
Local $fM_DpiY = DllStructGetData($tHeader, "DpiY")$aResult = DllCall($ghGDIPDll, "uint", "GdipGetDpiX", "hwnd", $hContext, "float*", 0)
[/autoit] [autoit][/autoit] [autoit]
Local $fG_DpiX = $aResult[2]
$aResult = DllCall($ghGDIPDll, "uint", "GdipGetDpiY", "hwnd", $hContext, "float*", 0)
Local $fG_DpiY = $aResult[2]DllCall($ghGDIPDll, "uint", "GdipScaleWorldTransform", "hwnd", $hContext, "float", $fM_DpiX / $fG_DpiX, "float", $fM_DpiY / $fG_DpiY, "int", 0)
[/autoit] [autoit][/autoit] [autoit]Local $hPen_1 = _GDIPlus_PenCreate(0xFFFF0000, 2)
[/autoit] [autoit][/autoit] [autoit]
Local $hPen_2 = _GDIPlus_PenCreate(0xFF00FF00, 2)
Local $hPen_3 = _GDIPlus_PenCreate(0xFF0000FF, 1)DllCall($ghGDIPDll, "int", "GdipDrawArc", "handle", $hContext, "handle", $hPen_1, "float", 0, "float", 0, _
[/autoit] [autoit][/autoit] [autoit]
"float", $fR * 2, "float", $fR * 2, "float", 270 - ($fAlpha * $Rad2Deg) / 2, "float", $fAlpha * $Rad2Deg)DllCall($ghGDIPDll, "int", "GdipDrawLine", "handle", $hContext, "handle", $hPen_2, "float", $fR - $fS / 2, "float", $fH, _
[/autoit] [autoit][/autoit] [autoit]
"float", $fR + $fS / 2, "float", $fH)DllCall($ghGDIPDll, "int", "GdipDrawArc", "handle", $hContext, "handle", $hPen_3, "float", 0, "float", 0, _
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
"float", $fR * 2, "float", $fR * 2, "float", 270 + ($fAlpha * $Rad2Deg) / 2, "float", 360 - ($fAlpha * $Rad2Deg))_GDIPlus_PenDispose($hPen_1)
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_PenDispose($hPen_2)
_GDIPlus_PenDispose($hPen_3)
_GDIPlus_GraphicsDispose($hContext)_GDIPlus_ImageDispose($hImage)
[/autoit]
_WinAPI_ReleaseDC(_WinAPI_GetDesktopWindow(), $hDC)
_GDIPlus_Shutdown()
EndFunc ;==>_Create -
Welches Tool ist das?
bzw. hat das Tool selber eine %-Anzeige, welche man auslesen könnte? zB StdOut -
lösche mal die Zeilen 45 und 55 aus deinem Script...
-
OK ein sehr minimalistisches Beispiel:
Spoiler anzeigen
[autoit]#include <File.au3>
[/autoit] [autoit][/autoit] [autoit]
#include <GUIConstantsEx.au3>Opt("GUIOnEventMode", 1)
[/autoit] [autoit][/autoit] [autoit]$hGui = GUICreate("Test")
[/autoit] [autoit][/autoit] [autoit]
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState()$aFiles = _FileListToArray(@ScriptDir, "*.gif")
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
$cDummy1 = GUICtrlCreateDummy()
For $i = 1 To $aFiles[0]
GUICtrlCreatePic($aFiles[$i], 10, ($i - 1) * 40 + 10, 30, 30)
GUICtrlSetOnEvent(-1, "_Click")
Next
$cDummy2 = GUICtrlCreateDummy()While Sleep(100)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
WEndFunc _Click()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
If @GUI_CtrlId > $cDummy1 And @GUI_CtrlId < $cDummy2 Then
MsgBox(0, "", "Bild Nr.: " & @GUI_CtrlId - $cDummy1 & " wurde geklickt")
EndIf
EndFunc ;==>_ClickFunc _Exit()
[/autoit]
Exit
EndFunc ;==>_ExitUmsetzen musst du das nun schon selber
E
-
Du musst die innere While-Schleife ausklammern, also Zeile 45 u 55 löschen.
Schau dir aber mal die Beispiele zu TraySetOnEvent, TrayItemSetOnEvent, GUISetOnEvent und GUICtrlSetOnEvent an
E
-
Hi
Hab den Code schnell überflogen.
Ich würde es so machen:1 GuiOnEventModus verwenden
2 vor und nach der Schleife, in der die BilderControls erzeugt werden, ein Dummycontrol erstellen.
3 in der OnEventClick-Funktion überprüfen, ob der Wert von @GUI_CtrlId größer als das erste Dummy und kleiner als das zweite Dummy ist.
durch @GUI_CtrlId - Dummy1 kannst du ausrechnen, welches Bild geklickt wurde...ist das verständlich?
E
-
Hier ein Ansatz:
Spoiler anzeigen
[autoit]#include <GUIConstantsEx.au3>
[/autoit] [autoit][/autoit] [autoit]
#include "GUICtrlOnHover.au3"Opt("GUIOnEventMode", 1)
[/autoit] [autoit][/autoit] [autoit]$hGui = GUICreate("Test")
[/autoit] [autoit][/autoit] [autoit]
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")Global $aButtons[1] = [0]
[/autoit] [autoit][/autoit] [autoit]_CreateButton("Test 1", 10, 10, 80, 20)
[/autoit] [autoit][/autoit] [autoit]
_CreateButton("Test 2", 10, 40, 80, 20)GUISetState()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]While Sleep(100)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
WEndFunc _CreateButton($sText, $iX, $iY, $iW, $iH)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Local $iIndex = $aButtons[0] + 1
ReDim $aButtons[$iIndex + 1]
$aButtons[0] = $iIndex
$aButtons[$iIndex] = GUICtrlCreateButton($sText, $iX, $iY, $iW, $iH)
GUICtrlSetOnEvent($aButtons[$iIndex], "_Click")
_GUICtrl_OnHoverRegister($aButtons[$iIndex], "_MouseOver", "_MouseLeave")
GUICtrlCreateLabel("", $iX + $iW + 10, $iY, 20, 20)
GUICtrlSetBkColor(-1, 0xFF0000)
EndFunc ;==>_CreateButtonFunc _Click()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Switch @GUI_CtrlId
Case $aButtons[1]
MsgBox(0, "", "Button 1")
Case $aButtons[2]
MsgBox(0, "", "Button 2")
EndSwitch
EndFunc ;==>_ClickFunc _MouseOver($iCtrlID)
[/autoit] [autoit][/autoit] [autoit]
GUICtrlSetBkColor($iCtrlID + 1, 0x00FF00)
EndFunc ;==>_MouseOverFunc _MouseLeave($iCtrlID)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
GUICtrlSetBkColor($iCtrlID + 1, 0xFF0000)
EndFunc ;==>_MouseLeaveFunc _Exit()
[/autoit]
Exit
EndFunc ;==>_ExitUDF steht für "User defined functions" und ist eine AutoItScript-Datei, die zusätzliche Funktionen enthält.
[autoit]
Alles, was am Scriptanfang so eingebunden wird:#include "GUICtrlOnHover.au3"
[/autoit]nennt sich UDF
E
-
Ich nehme an, du hast GuiCtrlSetOnEvent bei ein paar Buttons vergessen.
Falls du den OnEvent-Modus verwenden möchtest, dann musst du auch die bisherigen GetMsg-Befehle rausnehmen.Wahrscheinlich hast du schon ein funktionierendes Script und willst nicht allzuviel ändern, deshalb probier doch mal diese UDF:
http://www.autoitscript.com/forum/topic/55…post__p__417780
Damit solltest du beim original Script mit wenigen Zeilen deine Wünsche umsetzen könnenschau dir am besten mal die Beispiele an, die im Ziparchiv dabei sind
E
-
Ich hab zwei Ansätze probiert.
1: Normale Mausbewegungen blockieren und Cursor auf neue Position setzen.
Das Problem ist, dass die Mausposition immer absolut ausgelesen wird und man dadurch an den Bildschirmrändern hängenbleibt, da esja keine negativen Koordinaten gibt.Spoiler anzeigen
[autoit]#include <WinAPI.au3>
[/autoit] [autoit][/autoit] [autoit]
#include <WindowsConstants.au3>HotKeySet("{ESC}", "_Exit")
[/autoit] [autoit][/autoit] [autoit]Global $hMouseProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam")
[/autoit] [autoit][/autoit] [autoit]
Global $hMouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hMouseProc), _WinAPI_GetModuleHandle(0))
Global $tMousePos = DllStructCreate("int X; int Y;")
DllCall("user32.dll", "bool", "GetCursorPos", "ptr", DllStructGetPtr($tMousePos))
Global $iMouseX = DllStructGetData($tMousePos, "X")
Global $iMouseY = DllStructGetData($tMousePos, "Y")
OnAutoItExitRegister("_OnExit")While Sleep(10)
[/autoit] [autoit][/autoit] [autoit]
WEndFunc _MouseProc($nCode, $wParam, $lParam)
[/autoit] [autoit][/autoit] [autoit]
If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam)Switch $wParam
[/autoit] [autoit][/autoit] [autoit]
Case $WM_MOUSEMOVE
Local $tStruct = DllStructCreate("int X;int Y;dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo", $lParam)
If DllStructGetData($tStruct, "flags") = 0 Then
$iMouseX += ($iMouseX - DllStructGetData($tStruct, 1))
$iMouseY += ($iMouseY - DllStructGetData($tStruct, 2))
DllCall("user32.dll", "bool", "SetCursorPos", "int", $iMouseX, "int", $iMouseY)
Return 1
EndIf
EndSwitchReturn _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam)
[/autoit] [autoit][/autoit] [autoit]
EndFunc ;==>_MouseProcFunc _Exit()
[/autoit] [autoit][/autoit] [autoit]
Exit
EndFunc ;==>_ExitFunc _OnExit()
[/autoit]
_WinAPI_UnhookWindowsHookEx($hMouseHook)
DllCallbackFree($hMouseProc)
EndFunc ;==>_OnExit2: direkte Mausbewegungen werden wieder geblockt, aber generierte Mausbewegungen zugelassen
Relative Mausbewegungen lassen sich via WM_INPUT auslesen und verändert generieren
Das Problem hier ist, dass man z.B. keine Fenster verschieben kann!
Man müsste in WM_INPUT alle Mausfunktionen erkennen und generieren, dann geht das evtl.
Weiters setzt WM_INPUT ein GUI voraus...Spoiler anzeigen
[autoit]#include <WinAPI.au3>
[/autoit] [autoit][/autoit] [autoit]
#include <WindowsConstants.au3>Opt("GUIOnEventMode", 1)
[/autoit] [autoit][/autoit] [autoit]Global $hGui = GUICreate("Test")
[/autoit] [autoit][/autoit] [autoit]
GUISetOnEvent(-3, "_Exit")
GUIRegisterMsg(0x00FF, "WM_INPUT")
GUISetState(@SW_SHOW, $hGui)Global $hMouseProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam")
[/autoit] [autoit][/autoit] [autoit]
Global $hMouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hMouseProc), _WinAPI_GetModuleHandle(0))Global $tMouse = DllStructCreate("dword dwType; dword dwSize; hwnd hDevice; uint_ptr wParam; ushort usFlags; ushort usButtonFlags; ushort usButtonData; ulong ulRawButtons; long lLastX; long lLastY; ulong ulExtraInformation;")
[/autoit] [autoit][/autoit] [autoit]
Global $pMouse = DllStructGetPtr($tMouse)
Global $iMouse = DllStructGetSize($tMouse)
Global $tHeader = DllStructCreate("dword dwType; dword dwSize; hwnd hDevice; uint_ptr wParam;")
Global $iHeader = DllStructGetSize($tHeader)
_RegisterRawInput()OnAutoItExitRegister("_OnExit")
[/autoit] [autoit][/autoit] [autoit]While Sleep(10)
[/autoit] [autoit][/autoit] [autoit]
WEndFunc _MouseProc($nCode, $wParam, $lParam)
[/autoit] [autoit][/autoit] [autoit]
If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam)Switch $wParam
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Case $WM_MOUSEMOVE
Local $tStruct = DllStructCreate("int X;int Y;dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo", $lParam)
If DllStructGetData($tStruct, "flags") = 0 Then
Return 1
EndIf
EndSwitchReturn _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
EndFunc ;==>_MouseProcFunc WM_INPUT($hWnd, $Msg, $wParam, $lParam)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Local $aResult = DllCall("user32.dll", "dword", "GetRawInputData", "hwnd", $lParam, "dword", 0x10000003, "ptr", $pMouse, "dword*", $iMouse, "uint", $iHeader)
If Not @error Then
If DllStructGetData($tMouse, "hDevice") <> 0 Then
DllCall("user32.dll", "none", "mouse_event", "DWORD", 0x0001, "DWORD", -DllStructGetData($tMouse, "lLastX"), "DWORD", -DllStructGetData($tMouse, "lLastY"), "DWORD", 0, "ULONG_PTR", 0)
EndIf
EndIf
Return 'GUI_RUNDEFMSG'
EndFunc ;==>WM_INPUTFunc _RegisterRawInput()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Local $tStruct = DllStructCreate("ushort usUsagePage; ushort usUsage; dword dwFlags; hwnd hwndTarget;")
DllStructSetData($tStruct, "usUsagePage", 0x01)
DllStructSetData($tStruct, "usUsage", 0x02)
DllStructSetData($tStruct, "dwFlags", 0)
DllStructSetData($tStruct, "hwndTarget", $hGui)
Local $aResult = DllCall("user32.dll", "int", "RegisterRawInputDevices", "ptr", DllStructGetPtr($tStruct), "dword", 1, "dword", DllStructGetSize($tStruct))
If @error Then Return SetError(1, 2, False)
Return $aResult[0]
EndFunc ;==>_RegisterRawInputFunc _Exit()
[/autoit] [autoit][/autoit] [autoit]
Exit
EndFunc ;==>_ExitFunc _OnExit()
[/autoit]
_WinAPI_UnhookWindowsHookEx($hMouseHook)
DllCallbackFree($hMouseProc)
EndFunc ;==>_OnExitDie zweite Variante würde ohne Probleme funktionieren, wenn Microsoft WM_INPUT vor WH_MOUSE_LL aufrufen würde!
Das wurmt mich etwas, denn das hätte ich nämlich schon öfters benötigt!E
-
Ich empfehle den OnEvent-Modus:
Spoiler anzeigen
[autoit]#include <GUIConstantsEx.au3>
[/autoit] [autoit][/autoit] [autoit]
Opt("GUIOnEventMode", 1)$hGui = GUICreate("Test")
[/autoit] [autoit][/autoit] [autoit]
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "_MouseMove")$cButton1 = GUICtrlCreateButton("Test 1", 10, 10, 80, 20)
[/autoit] [autoit][/autoit] [autoit]
GUICtrlSetOnEvent(-1, "_Click")
$cLabel1 = GUICtrlCreateLabel("", 100, 10, 20, 20)$cButton2 = GUICtrlCreateButton("Test 2", 10, 40, 80, 20)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
GUICtrlSetOnEvent(-1, "_Click")
$cLabel2 = GUICtrlCreateLabel("", 100, 40, 20, 20)
GUISetState()While Sleep(100)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
WEndFunc _Click()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Switch @GUI_CtrlId
Case $cButton1
MsgBox(0, "", "Button 1")
Case $cButton2
MsgBox(0, "", "Button 2")
EndSwitch
EndFunc ;==>_ClickFunc _MouseMove()
[/autoit] [autoit][/autoit] [autoit]
Local $aInfo = GUIGetCursorInfo($hGui)GUICtrlSetBkColor($cLabel1, 0xFF0000)
[/autoit] [autoit][/autoit] [autoit]
GUICtrlSetBkColor($cLabel2, 0xFF0000)Switch $aInfo[4]
[/autoit] [autoit][/autoit] [autoit]
Case $cButton1
GUICtrlSetBkColor($cLabel1, 0x00FF00)
Case $cButton2
GUICtrlSetBkColor($cLabel2, 0x00FF00)
EndSwitchEndFunc ;==>_MouseMove
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func _Exit()
[/autoit]
Exit
EndFunc ;==>_ExitUm das evtl. Flackern noch abzustellen, müsste man noch etwas in die Trickkiste greifen
Alternativ dazu findest du im Forum die UDF "GuiCtrlSetOnHover" oder so ähnlich, damit sollte das auch funktionieren...
E
-
Du benötigst ein Fenster auf das du das Bild zeichnen kannst.
Um das Bild "alleinstehend" zu bekommen, kannst du $WS_POPUP als Style angebenSpoiler anzeigen
[autoit]#include <GDIPlus.au3>
[/autoit] [autoit][/autoit] [autoit]
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>Opt("GUIOnEventMode", 1)
[/autoit] [autoit][/autoit] [autoit]_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit]
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\chat_main_body.png')
$iImgW = _GDIPlus_ImageGetWidth($hImage)
$iImgH = _GDIPlus_ImageGetHeight($hImage)$hGui = GUICreate("", $iImgW, $iImgH, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
[/autoit] [autoit][/autoit] [autoit]
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)GUIRegisterMsg($WM_PAINT, "WM_PAINT")
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
GUIRegisterMsg($WM_ERASEBKGND, "WM_PAINT")
GUISetState()While 1
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Sleep(100)
WEndFunc WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iImgW, $iImgH)
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_PAINTFunc _Exit()
[/autoit]
_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
Exit
EndFunc ;==>_ExitE
-
Alles Gute und Danke für deine großartige Arbeit!
-
Meinst du so was?
[ offen ] Programm.exe in einem AutoIt fenster ausführen -
Hi
Zunächst mal benötigst du GDIp.au3: http://www.autoitscript.com/forum/topic/106021-gdipau3/
Darin findest du die Funktion _GDIPlus_GraphicsSetPageUnit.Ich würde es in etwa so machen:
Ein Backbuffer in der Größe des Fensters in Pixel Units
Eine eigene Grafik in Milimeter Units zum zeichnenSpoiler anzeigen
[autoit]#include <GDIP.au3>
[/autoit] [autoit][/autoit] [autoit]
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>Opt("GUIOnEventMode", 1)
[/autoit] [autoit][/autoit] [autoit]_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit]$hGui = GUICreate("A4", 210, 297)
[/autoit] [autoit][/autoit] [autoit]
GUISetOnEvent(-3, "_Exit")_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit]
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics(210, 297, $hGraphics) ;Backbuffer verhindert flackern
$hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
_GDIPlus_GraphicsClear($hGfxBuffer, 0xFF000000)$aSize = _CalcBitmapSize(210, 297) ;Wie groß ist das in Pixel?
[/autoit] [autoit][/autoit] [autoit]
ConsoleWrite($aSize[0] & " " & $aSize[1] & @CRLF)
$hBmpMilimeter = _GDIPlus_BitmapCreateFromGraphics($aSize[0], $aSize[1], $hGraphics)
$hGfxMilimeter = _GDIPlus_ImageGetGraphicsContext($hBmpMilimeter)
_GDIPlus_GraphicsSetPageUnit($hGfxMilimeter, 6)
_GDIPlus_GraphicsClear($hGfxMilimeter, 0xFFFFFFFF)$hPen = _GDIPlus_PenCreate(0xFF000000, 4)
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_GraphicsDrawRect($hGfxMilimeter, 1, 1, 208, 295, $hPen) ;Zeichnen in Millimeter_GDIPlus_ImageSaveToFile($hBmpMilimeter, @ScriptDir & "\A4.bmp") ;Speichern - Zieldatei sollte A4 Größe haben
[/autoit] [autoit][/autoit] [autoit]_GDIPlus_GraphicsDrawImageRect($hGfxBuffer, $hBmpMilimeter, 0, 0, 210, 297) ;zeichne Milimetergrafik verkleinert auf Backbuffer
[/autoit] [autoit][/autoit] [autoit]GUIRegisterMsg($WM_PAINT, "WM_PAINT")
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
GUISetState()While 1
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Sleep(100)
WEndFunc _CalcBitmapSize($iW, $iH)
[/autoit] [autoit][/autoit] [autoit]
Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
Local $aPoints[2][2]
$aPoints[0][0] = 1
$aPoints[1][0] = $iW
$aPoints[1][1] = $iH_GDIPlus_GraphicsSetPageUnit($hGraphics, 6)
[/autoit] [autoit][/autoit] [autoit]
Local $aResult = _GDIPlus_GraphicsTransformPoints($hGraphics, $aPoints, 2, 1)_GDIPlus_GraphicsDispose($hGraphics)
[/autoit] [autoit][/autoit] [autoit]Local $aReturn[2]
[/autoit] [autoit][/autoit] [autoit]
$aReturn[0] = Ceiling($aResult[1][0])
$aReturn[1] = Ceiling($aResult[1][1])Return $aReturn
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
EndFunc ;==>_CalcBitmapSizeFunc WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
_GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_PAINTFunc _Exit()
[/autoit]
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGfxMilimeter)
_GDIPlus_BitmapDispose($hBmpMilimeter)
_GDIPlus_GraphicsDispose($hGfxBuffer)
_GDIPlus_BitmapDispose($hBmpBuffer)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
Exit
EndFunc ;==>_ExitE
-
-
Dann hast du bisher immer GuiGetMsg verwendet, welches intern ein Sleep macht, wenn die Maus nicht bewegt wird...
[autoit]
selbst dieses Script:While 1
[/autoit]
WEndhat etwa 50% bei mir
-
Das liegt nicht an GDI+, du brauchst nur ein Sleep(10) in der Schleife