Ist in AutoIt schon enthalten:
#include <Excel.au3>
Hilfe findest du, wenn du in SciTE z.B. _Excel_BookOpen eingibst, auf die Funktion klickst und F1 drückst.
Ist in AutoIt schon enthalten:
#include <Excel.au3>
Hilfe findest du, wenn du in SciTE z.B. _Excel_BookOpen eingibst, auf die Funktion klickst und F1 drückst.
Zum auswählen in der ListBox: _GUICtrlListBox_SetCurSel($idList, 0)
Dabei wird auch automatisch zu dem ausgewähltem Item gescrollt.
Ich hab das ganze mal so umgebaut, wie ich das Error-Handling eher gestalten würde: Die Funktion gibt True/False zurück, je nach Erfolg, und setzt die entsprechenden Error-Codes, die nach dem Aufruf der Funktion behandelt werden.
Global $sFolderData = "data\"
; ... Gui code
Local $sFilesFolder = @ScriptDir
_fillListBox($QrCodeList, $sFilesFolder)
If @error Then
Local $sTitle = "Fehler beim befüllen der Liste"
If @error = 1 Then MsgBox($MB_SYSTEMMODAL, $sTitle, 'Fehler beim auslesen des Ordners "'&$sFilesFolder&'": '&@extended&@crlf)
If @error = 2 Then MsgBox($MB_SYSTEMMODAL, $sTitle, 'Fehler beim schreiben der Ini: '&@extended&@crlf)
If @error = 4 Then MsgBox($MB_SYSTEMMODAL, $sTitle, '_fillListBox error, contact the developer with the following information: '&@error&">>"&@extended&@crlf)
If @error = 3 Then
If @extended = 1 Then
MsgBox($MB_SYSTEMMODAL, $sTitle, 'Pfad ungültig.'&@crlf)
ElseIf @extended = 4 Then
MsgBox($MB_SYSTEMMODAL, $sTitle, 'Keine Dateien gefunden.'&@crlf)
Else
MsgBox(16, $sTitle, 'Die INI-Datei konnte nicht gelesen werden.'&@crlf)
EndIf
Exit
EndIf
EndIf
; Errors:
; 1: _FileListToArray failed (@extended contains _FileListToArray error code)
; 2: IniWrite failed (@extended contains IniWrite error code)
; 3: IniReadSection failed (@extended contains IniReadSection error code)
; 4: GUICtrlSetData failed (@extended contains GUICtrlSetData error code) => probably not a control for $idListBox
Func _fillListBox($idListBox, $sFilePath, $sIniFile = $sFolderData & "listbox.ini")
Local Static $sSection = "items", $sKeyPrefix = "item"
; Update ini with files
$aFileList = _FileListToArray($sFilePath, "QR_*")
If @error Then Return SetError(1, @error, False)
For $i = 1 To UBound($aFileList)-1
IniWrite($sIniFile, $sSection, $sKeyPrefix & $i, $aFileList[$i])
If @error Then Return SetError(2, @error, False)
Next
; Read ini and fill listbox
Local $arItems = IniReadSection($sIniFile, "items")
If @error Then Return SetError(3, @error, False)
Sleep(200) ; Why?
For $i = 1 To $arItems[0][0]
GUICtrlSetData($idListBox, $arItems[$i][1])
If @error Then Return SetError(4, @error, False)
Next
Return True
EndFunc ;==>CreateListBox
Alles anzeigen
Das ganze behebt aber nicht dein eigentliches Problem. Dazu ein paar Anmerkungen/Fragen:
1. Wieso liest du erst die Ini-Datei, dann befüllst du sie mit den aktuellen Dateien (und überschreibst dabei die alten Daten) und schreibst dann die alten Daten in die ListBox? Von dem was ich vom Code/deiner Fragenstellung vermute ergibt das keinen Sinn.
2. MsgBox(16, "Fehler", "Die INI-Datei konnte nicht gelesen werden.") wird ausgegeben, wenn irgendein Fehler bei Sleep(200) aufgetreten ist??? Bedenke: @error wird bei jeglichem Funktionsaufruf auf 0 zurückgesetzt. Die Zeile kann also nie erreicht werden, da Sleep keine Fehlercode geben kann. Ich habe für meine Code-Änderung angenommen, dass sich die ganzen If @error Zeilen auf IniReadSection beziehen.
3. Brauchst du die Ini überhaupt? Wenn ja, wofür? Du kannst eigentlich die Daten mit _FileListToArray einlesen und direkt in die ListBox schreiben.
4. Was für eine Sortierung stellst du dir vor? Weder _FileListToArray noch IniReadSection garantieren, dass irgendeine Reihenfolge der Daten vorliegt. Normalerweise lesen sie von oben nach unten/alphabetisch, aber das kann sich auch aus irgendwelchen Gründen ändern. Vermutlich brauchst du also so oder so ein _ArraySort, oder etwas ähnliches.
Auf den ersten BLick schaut es für mich richtig aus, du hast ja auch eig. nur bei CloneArea auf $GDIP_PXF32ARGB gewechselt und bei GraphicsClear auf 0x00FFFFFF.
Ich würde auf die schnelle 2 Mögliche Probleme sehen:
1. Unterstützt MPDF 32Bit ARGB Werte (Vielleicht musst du RGBA oder ähnliches verwenden (keine Ahnung ob das mit GDI-Plus geht))
2. Nutzt du eventuell PDF/A (die Archiv Version von PDF)? Dort sind keine Transparenten Bilder erlaubt, da für die Archivierung alles genau definiert sein soll, was für Probleme sorgen könnte.
Gern
Ja, der DLL Code ist in Rust geschrieben, wobei ich dabei das Interface programmiert habe und mir angeschaut hab, wie man mit Rust eine DLL erstellt.
Der Code zum generieren des QRCodes ist von der oben genannten Library.
Dieses Skript ermöglicht es QRCodes für den automatischen login von Wifi-Netzwerken zu generieren, wie ihn die aktuellen Smartphones unterstützen.
Dabei wird die Wifi-SSID und das Wifi-Passwort angegeben und ein entsprechender QRCode erstellt.
Das Passwort kann auch mit der gewünschten Länge automatisch generiert werden.
Die Wifi-SSID und das Wifi-Passwort werden auch unter den QRCode geschrieben, wobei eine Schriftart (Consolas) verwendet wird, die die Eindeutige unterscheidung zu anderen Zeichen ermöglicht (O/0,...).
Die Schriftart-, größe,... kann, ebenso wie anderen Einstellungen, nach dem ersten Ausführen in data\config.ini geändert werden.
Dieses Skript ermöglicht es die QRCode UDF (QRCode UDF) in der Konsole zu nutzen.
Es ermöglicht das Ausgeben eines QRCode in die Konsole oder als Bilddatei.
Dabei kann auch ein Bild angegeben werden, dass automatisch in die Mitte des QRCodes gezeichnet wird.
Die Größe wird dabei automatisch an das "error correction level" angepasst.
Die aktuellste Version ist 1.1
Hilfe:
================================ QRCode generator - cli ================================
The QRCode generator cli provides a command line interface to generate qrcodes.
It allows the user to print the qrcode to the console (if no destination path
is provided) or to output the qrcode as an image. It also allows the addition
of another image to be drawn ontop of the qrcode in the middle, with the size
automatically adjusted accordingly to the error correction level (ECL).
SYNOPSIS
qrcodegenerator-cli [OPTION]... [INPUT TEXT] [OPTION]... [DESTINATION] [OPTION]...
DESCRIPTION
Generate a qrcode for the given input text.
The qrcode is printed to the console, or if a DESTINATION is provided, the output is
saved as an image to that DESTINATION.
The INPUT TEXT is optional, but then it must be replaced with the flag -t/--text.
The DESTINATION can be replaced with the flag -d/--out.
-b, --background
provide the desired value for the background.
Image output: color as ARGB (Default "0xFFFFFFFF").
Console output: the desired character/string (Default " ").
-c, --color
provide the desired value for the foreground.
Image output: color as ARGB (Default "0xFF000000").
Console output: the desired character/string (Default "#").
-d, --delimeter
provide a character/string to seperate multiple lines.
This sequence is then replaced in the input text by \n (@LF)
This can be changed to \r\n (@CRLF) with the flsg -r.
-e, --ecl
provide the error correction level (ECL) (Default "4").
Possible values:
Low (up to ~7% loss): 1
Medium (up to ~15% loss): 2
Quartile (up to ~25% loss): 3
High (up to ~30% loss): 4
-h, --help, help, /?, ?
Show this help
-i, --icon
provide the path to an image. That image will then be drawn at the qrcode.
It will be scaled to not be larger then the allowed ECL (see argument
above). Image size in relation to the qrcode and with those ECLs:
low 5%, medium 13%, quartile 23%, high 28%.
Note: The icon will not be upscaled, if it is smaller.
Note: You can change -s/--size to make the qrcode larger => more imagespace.
-l, --linebreak
provide the desired character/string to insert after every qrcode line
(Default "\r\n" or "@CRLF"). This only works with console output.
-m, --margin
configure a border around the qrcode (Default "[0,0,0,0]").
Defined as integer values: [<Top>,<Right>,<Bottom>,<Left>]
With image output, it defines the border in pixels.
With console output, it defines the border above/below with "\r\n" (@CRLF) and
to the left/right with spaces (" ").
-r
Toggle from \n (@LF) to \r\n (@CRLF), when using the --delimeter command.
-s, --size
provide the desired size for the output.
Image output: Pixel per rectangle
Console output: Character/String per rectangle
NOTE (Image output): Increasing the size changes the output width/height. This
also influences the size of a possible icon (-i/--icon).
-t, --text
provides an alternative to define the input text. This allows the user to be
sure, the text is not misinterpreted as another argument.
-o, --out
provides an alternative to define the destination. This allows the user to be
sure the destination is not misinterpreted as another argument.
ERROR HANDLING
If an error occurres, the program prints an error and exits with an error code.
Exit codes:
1 - Missing arguments; at least the input text is required
2 - Parameter --ecl provided, but value is missing or not one of [1,2,3,4]
3 - Parameter --color provided, but value is missing
4 - Parameter --background provided, but value is missing
5 - Parameter --linebreak provided, but value is missing
6 - Parameter --icon provided, but value is missing or path does not exist
7 - Parameter --size provided, but value is missing or not an allowed value
8 - Parameter --margin provided, but value is missing or not an allowed value
9 - Parameter --out provided, but value is missing
10 - Parameter --delimeter provided, but value is missing
11 - Unknown parameter found
12 - QRCode generation failed.
13 - QRCode generation failed because of the input text being to large.
Maybe try a lower error correction level (ECL).
14 - QRCode image file could not be saved. There may be a problem with the path.
15 - Icon image file could not be loaded as an image
16 - Drawing (image)/showing (console) the qrcode failed
AUTHOR
Kanashius
Copyright ⌐ 2024 Kanashius (https://wwww.kanashius.com)
Alles anzeigen
Changelog:
Diese QRCode UDF ermöglicht es, QRCodes zu generieren und als Bild oder Ausgabe in der Konsole darzustellen.
Sie bietet Funktionen um ein 2D-Boolean-Array des QRCodes zu erhalten, dieses als Bitmap (_GDIPlus) zu erhalten, oder direkt auf eine GraphicsContext (_GDIPlus) zu zeichnen.
Dabei wird eine von mir mit Rust erstellte .dll genutzt, welche die "QR Code generator library (Rust)" von Project Nayuki (https://www.nayuki.io/page/qr-code-generator-library) verwendet.
Aktuell sind folgende Funktionen in der UDF erhalten:
_QRCode_StartUp - Startup needed before using most other functions (Includes _GDIPlus_Startup)
_QRCode_Shutdown - Shutdown should be called at the and to clean up (Includes _GDIPlus_Shutdown)
_QRCode_GetQRCode - Generate a QRCode as 2D-Boolean-Array, where the first index = lines, the second index=cols, normally False=White, True=Black
_QRCode_GetBitmap - Creates a GDIPlus-Bitmap with the QRCode
_QRCode_DrawQRCode - Draws a QRCode on a provides GDIPlus-GraphicsContext
_QRCode_DrawQRCodeFast - Same as _QRCode_DrawQRCode, but without error checks and requires brushes for the colors to be provided (=> higher FPS)
_QRCode_ConsoleWrite - Print the QRCode to the console
_QRCode_GetSize - Get the size of the generated QRCode
_QRCode_GetECLMaxLoss - Get the maximum allowed loss before the qrcode becomes unreadable (decimal multiplier)
Possible error correction levels:
$_QRCode_ECL_LOW = 1
$_QRCode_ECL_MEDIUM = 2
$_QRCode_ECL_QUARTILE = 3
$_QRCode_ECL_HIGH = 4 - Default
Alles anzeigen
Hier ist ein Beispiel, wie die UDF verwendet werden kann:
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.16.1
Author: Kanashius
Script Function:
Example script to show the usages of the QRCode UDF.
#ce ----------------------------------------------------------------------------
#include <Array.au3>
#include "QRCode.au3"
; Startup to initialize the dll and call _GDIPlus_Startup
_QRCode_StartUp()
If @error Then
ConsoleWrite("Error QRCode startup: "&@error&" >> "&@extended&@crlf)
Exit
EndIf
; Generate a 2D-Array with boolean values representing the QRCode
; The $_QRCode_ECL_HIGH provides a high error correction level. But a higher ECL also creates larger QRCodes and allows for less characters. So if any of that is an issue, try decreasing the ECL.
; The $_QRCode_ECL_HIGH is the default to be more robust and allow for images to be placed on top of the qrcode (like a logo in the middle) without making the qrcode unreadable.
;Local $arQRCode = _QRCode_GetQRCode("A very long String to test", $_QRCode_ECL_HIGH)
Local $arQRCode = _QRCode_GetQRCode(Binary("0xFEED1337"), $_QRCode_ECL_HIGH)
If @error Then
ConsoleWrite("Error creating QRCode: "&@error&" >> "&@extended&@crlf)
Exit
EndIf
; Print the QRCode to the console.
_QRCode_ConsoleWrite($arQrCode, "#", " ", @crlf)
; Create a Bitmap with the QRCode and a 50 pixel border.
Local $hBitmap = _QRCode_GetBitmap($arQRCode, 4, 50, 50, 50, 50)
; _GDIPlus_ImageSaveToFile($hBitmap, "qrcode.png")
_GDIPlus_BitmapDispose($hBitmap)
; ==> GuiExample drawing directly on the graphics context
_guiExample()
; Shutdown to close the dll, free memory of structs and call _GDIPlus_Shutdown
_QRCode_Shutdown()
If @error Then ConsoleWrite("Error QRCode shutdown: "&@error&" >> "&@extended&@crlf)
Func _guiExample()
Local $iWidth = 800, $iHeight = @DesktopHeight-100, $iSpace = 10, $iQRCodePixelSize = 4
Local $hGui = GUICreate("QRCode example", $iWidth, $iHeight)
Local $iInput = GUICtrlCreateInput("This is a text example", $iSpace, $iSpace, $iWidth-$iSpace*2, 25)
; create buffer image
Local $iQRCodeAreaLeft = $iSpace, $iQRCodeAreaTop = $iSpace*2+25, $iQRCodeAreaWidth = $iWidth-$iSpace*2, $iQRCodeAreaHeight = $iHeight-$iSpace*3-25
Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iQRCodeAreaWidth, $iQRCodeAreaHeight, $hGraphics)
Local $hBitmapGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsClear($hBitmapGraphics, 0xFFFFFFFF)
GUISetState(@SW_SHOW, $hGui)
; create brushes for the rectangles
Local $hBrushBlack = _GDIPlus_BrushCreateSolid(0xFF000000)
Local $hBrushWhite = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
Local $hPenBlack = _GDIPlus_PenCreate(0xFF000000, 2)
_GDIPlus_GraphicsSetSmoothingMode($hBitmapGraphics, 2)
; generate the first bottom qrcode
Local $arQRCodeFast = _QRCode_GetQRCode("Current date and time: "&@YEAR&"/"&@MON&"/"&@MDAY&" "&@HOUR&":"&@MIN&":"&@SEC, $_QRCode_ECL_HIGH)
If @error Then
MsgBox(16, "Error", "QRCode generation failed."&@crlf&"Most probable error is the qrcode.exe not being in the correct directory: "&@error&" >> "&@extended)
return false
EndIf
; save the size of the bottom qrcode
Local $arSizeQRCodeFast = _QRCode_GetSize($arQRCodeFast, $iQRCodePixelSize*2)
; initialize loop variables
Local $iMsg, $sQRCodeText = "", $arSizeQRCode = [0, 0], $PI = 3.141592653589793
While 1
$iMsg = GUIGetMsg()
If $iMsg = -3 Then ExitLoop
; ==> Top QRCode
; draw the top qrcode, if the input changes
If GUICtrlRead($iInput)<>$sQRCodeText Then
; clear the area of the old qrcode
_GDIPlus_GraphicsSetClipRect($hBitmapGraphics, ($iQRCodeAreaWidth-$arSizeQRCode[0])/2, 0, $arSizeQRCode[0], $arSizeQRCode[1])
_GDIPlus_GraphicsClear($hBitmapGraphics, 0xFFFFFFFF)
_GDIPlus_GraphicsResetClip($hBitmapGraphics)
; generate the new qrcode
$sQRCodeText = GUICtrlRead($iInput)
Local $arQRCode = _QRCode_GetQRCode($sQRCodeText, $_QRCode_ECL_HIGH)
if @error Then
Local $iErr = @error, $iExt = @extended
_GDIPlus_GraphicsClear($hBitmapGraphics, 0xFFFFFFFF)
If $iErr=5 Then
MsgBox(16, "Error", "QRCode generation failed."&@crlf&"The given Text is ~"&($iExt/8)&" characters to long")
Else
MsgBox(16, "Error", "QRCode generation failed."&@crlf&"Most probable errors are a to long text or the qrcode.exe not being in the correct directory: "&$iErr&" >> "&$iExt)
EndIf
Else
; save the size of the new qrcode
$arSizeQRCode = _QRCode_GetSize($arQRCode, $iQRCodePixelSize)
; draw the new qrcode
Local $iQRCodeLeft = ($iQRCodeAreaWidth-$arSizeQRCode[0])/2
_QRCode_DrawQRCode($hBitmapGraphics, $arQRCode, $iQRCodePixelSize, $iQRCodeLeft, 0)
If @error Then
MsgBox(16, "Error", "QRCode drawing failed: "&@error&" "&@extended)
_GDIPlus_GraphicsClear($hBitmapGraphics, 0xFFFFFFFF)
EndIf
EndIf
EndIf
; ==> Bottom QRCode
Local $sText = "Current date and time: "&@YEAR&"/"&@MON&"/"&@MDAY&" "&@HOUR&":"&@MIN&":"&@SEC&":"&@MSEC
Local $iTime = @SEC+@MSEC*0.001
; generate the qrcode for the new time
$arQRCodeFast = _QRCode_GetQRCode($sText, $_QRCode_ECL_HIGH)
If @error Then
MsgBox(16, "Error", "QRCode generation failed."&@crlf&"Most probable error is the qrcode.exe not being in the correct directory: "&@error&" >> "&@extended)
ExitLoop
EndIf
Local $iTextHeight = 20
; clear the area of the old qrcode
_GDIPlus_GraphicsSetClipRect($hBitmapGraphics, ($iQRCodeAreaWidth-$arSizeQRCodeFast[0])/2, $iQRCodeAreaHeight-$arSizeQRCodeFast[1]-$iTextHeight, $arSizeQRCodeFast[0], $arSizeQRCodeFast[1]+$iTextHeight)
_GDIPlus_GraphicsClear($hBitmapGraphics, 0xFFFFFFFF)
_GDIPlus_GraphicsResetClip($hBitmapGraphics)
; save the size of the new qrcode
$arSizeQRCodeFast = _QRCode_GetSize($arQRCodeFast, $iQRCodePixelSize*2)
; draw the time as string above the qrcode
_GDIPlus_GraphicsDrawString($hBitmapGraphics, $sText, ($iQRCodeAreaWidth-$arSizeQRCodeFast[0])/2+15, $iQRCodeAreaHeight-$arSizeQRCodeFast[1]-$iTextHeight)
; Draw the second qrcode
Local $iLeft = ($iQRCodeAreaWidth-$arSizeQRCodeFast[0])/2, $iTop = $iQRCodeAreaHeight-$arSizeQRCodeFast[1]
_QRCode_DrawQRCodeFast($hBitmapGraphics, $arQRCodeFast, $hBrushBlack, $hBrushWhite, $iQRCodePixelSize*2, $iLeft, $iTop)
; draw the white rectangle in the middle of the qrcode
Local $iRectSize = $arSizeQRCodeFast[0]*0.25, $iRectMidX = $iLeft+$arSizeQRCodeFast[0]/2, $iRectMidY = $iTop+$arSizeQRCodeFast[1]/2
_GDIPlus_GraphicsFillRect($hBitmapGraphics, $iRectMidX-$iRectSize/2, $iRectMidY-$iRectSize/2, $iRectSize, $iRectSize, $hBrushWhite)
; draw the line in the rectangle
Local $iTimeSec = Mod($iTime+45, 60)
Local $iRad = (360/60*$iTimeSec)*$PI/180
_GDIPlus_GraphicsDrawLine($hBitmapGraphics, $iRectMidX, $iRectMidY, $iRectMidX+$iRectSize/2*Cos($iRad), $iRectMidY+$iRectSize/2*Sin($iRad), $hPenBlack)
; draw bitmap to gui
_GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, $iQRCodeAreaLeft, $iQRCodeAreaTop, $iQRCodeAreaWidth, $iQRCodeAreaHeight)
WEnd
; cleanup time
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_PenDispose($hPenBlack)
_GDIPlus_BrushDispose($hBrushWhite)
_GDIPlus_BrushDispose($hBrushBlack)
GUIDelete($hGui)
EndFunc
Alles anzeigen
Und ein weiteres Beispiel findet sich in der QRCodeGenerator-CLI: QRCode generator cli
Das ist eine Konsolenanwendung mit umfangreichen Einstellungsmöglichkeiten zum generieren von QRCodes.
Ich habe während der Entwicklung in Rust erst eine .exe statt der .dll erstellt. Die war aber langsamer (String parsing in AutoIt,...), deshalb hab ich das verworfen.
Die in Rust entstandene .exe findet ihr aber bei den Dateien als Rust-Executable (QRCode-Wrapper-Console-Rust-Exe.zip).
Sie kann in der Konsole mit einem Text aufgerufen werden und gibt den QRCode als 0 (weiß), 1 (schwarz), 2(neue zeile) aus.
Mit --human wird der QRCode Menschenlesbar ausgegeben und mit --errorlvl low/medium/quartile/high kann das "error correction level" angegeben werden.
Aber diese Anwendung hat weniger Möglichkeiten, als die vorher erwähnte QRCodeGenerator-cli und ist nur zur Vollständigkeit hier.
Dateien:
Die UDF mit allen benötigten Dateien: qrcode.zip
Der Rust-Quellcode der .dll und .exe: QRCode-Dll-Exe-Rust-Src.zip
Die Rust-Executable: QRCode-Wrapper-Console-Rust.zip
Du erstellst eine ssh session. Um die zu schließen, musst du die Verbindung trennen. Dazu kannst du das Kommando "EXIT" am Ende deines Kommandoaufrufes aufrufe, oder vermutlich auch den STD_IN nutzen.
Das würde mit einem StdinWrite($iPid, "EXIT") funktionieren.
ProcessClose versucht einen Prozess auf nette Art zu beenden (Sendet ein Terminations Signal an die Anwendung, die diese vermutlich ignoriert).
Du könntest den Prozess also notfalls mit der Kommandozeile mit pskill beenden (kann auch mit AutoIt automatisiert werden).
Das "Unable to read from standard input: Das Handle ist ungültig." kommt vermutlich daher, dass du bei RUN nur angibst, dass $STDOUT_CHILD verwendet werden soll, aber nicht der $STDIN_CHILD.
Vielleicht will plink.exe aber beides und wirft einen Fehler, wenn kein StandardInputStream vorhanden ist.
Probier evtl. mal: Run(@ComSpec & " /c " & $sVar4 & " " & $sKonto & "@" & $sHost & " -pw " & $sPwd, @TempDir, @SW_HIDE, BitOr($STDIN_CHILD, $STDOUT_CHILD))
Evtl. wäre auch $STDERR_CHILD gut, ggf. merged mit dem Output, einfach damit du das auch sehen kannst:
Run(@ComSpec & " /c " & $sVar4 & " " & $sKonto & "@" & $sHost & " -pw " & $sPwd, @TempDir, @SW_HIDE, BitOr($STDIN_CHILD, $STDERR_MERGED))
Also ich habs mal durchlaufne lassen und hab in der Logdef mal eine IP auf 192.168.100.5 gesetzt, diese würde ich bei der IP Sortierung aufsteigend auch oben erwarten und nicht unten, denke wir haben uns da missverstanden;)
Die Sortierung hab ich auch gar nicht implementiert, ich hab nur die Daten aufbereitet.
Dafür brauchst du aber auch nur ein _ArraySort($arLogData) in Zeile 17 nach dem Local $arLogData = _parseLog($sLogData) einfügen. (Und das #include<Array.au3> natürlich)
MfG Kanashius
Ich werf noch mal eine andere Lösung in den Ring, die auch den Ansatz von AspirinJunkie verfolgt: Sortieren nach der IP als Zahl. Wobei ich den BinaryString nehme, weil die Zahl manchmal negativ wäre.
Local $sLogData = "2024/06/23 18:02:36 - Client connected"&@crlf& _
"2024/06/23 18:02:36 - action=login pcname=N210708_b mac=5C61994A3157 ip=192.168.178.22 time=18:02:36"&@crlf& _
"2024/06/23 18:06:55 - Client connected"&@crlf& _
"2024/06/23 18:06:55 - action=logout pcname=N210708_B mac=5C61994A3157 ip=192.168.178.22 time=18:06:55"&@crlf& _
"2024/06/23 18:10:30 - Client connected"&@crlf& _
"2024/06/23 18:10:30 - action=login pcname=N210708_B mac=5C61994A3157 ip=192.168.178.22 time=18:10:30"&@crlf& _
"2024/06/23 18:13:50 - Client connected"&@crlf& _
"2024/06/23 18:13:50 - action=logout pcname=N210708_B mac=5C61994A3157 ip=192.168.178.22 time=18:13:50"&@crlf& _
"2024/06/23 18:18:20 - Server started and listening on port 8085"
Local $arLogData = _parseLog($sLogData)
; Example for reading the data
For $i = 0 to UBound($arLogData)-1 Step 1
ConsoleWrite(($i+1)&". For sorting: "&$arLogData[$i][0]&@crlf)
ConsoleWrite(($i+1)&". LogDate: "&$arLogData[$i][1].logDate&@crlf)
ConsoleWrite(($i+1)&". LogTime: "&$arLogData[$i][1].logTime&@crlf)
ConsoleWrite(($i+1)&". Action: "&$arLogData[$i][1].action&@crlf)
ConsoleWrite(($i+1)&". PCName: "&$arLogData[$i][1].pcname&@crlf)
ConsoleWrite(($i+1)&". Mac: "&$arLogData[$i][1].mac&@crlf)
ConsoleWrite(($i+1)&". IP: "&$arLogData[$i][1].ip&@crlf)
ConsoleWrite(($i+1)&". Time: "&$arLogData[$i][1].time&@crlf)
Next
Func _parseLog($sLog)
Local $arData = StringRegExp($sLog, "(?<date>\d{4}\/\d{2}\/\d{2})\s(?<time>\d{2}:\d{2}:\d{2}\s)-\saction=(?<action>\S+)\spcname=(?<pcname>\S+)\smac=(?<mac>\S+)\sip=(?<ip>(?<ip1>\d+)\.(?<ip2>\d+)\.(?<ip3>\d+)\.(?<ip4>\d+))\stime=(?<time2>\d{2}:\d{2}:\d{2})", 3)
Local $arResult[UBound($arData)/11][2] ; intIp, dataMap
For $i=0 to UBound($arData)-1 Step 11
Local $mData[]
$mData.logDate = $arData[$i]
$mData.logTime = $arData[$i+1]
$mData.action = $arData[$i+2]
$mData.pcname = $arData[$i+3]
$mData.mac = $arData[$i+4]
$mData.ip = $arData[$i+5]
$mData.time = $arData[$i+10]
Local $iUnsignedIntIp = BitOR(BitShift(Int($arData[$i+6]), -24), BitShift(Int($arData[$i+7]), -16), BitShift(Int($arData[$i+8]), -8), Int($arData[$i+9]))
$arResult[$i/11][0] = _toBinaryString($iUnsignedIntIp)
$arResult[$i/11][1] = $mData
Next
return $arResult
EndFunc
Func _toBinaryString($iNumber)
Local $sBinaryNumber = ""
For $i=31 to 0 Step -1
$sBinaryNumber&=BitAND(BitShift($iNumber, $i), 1)
Next
return $sBinaryNumber
EndFunc
Alles anzeigen
Du bekommst also nach dem parsen ein Array mit 2 Werten, dem BinaryString der IP zum sortieren und eine Map mit allen Werten.
Da du spezifisch auf das BIOS eingehst:
Du könntest schauen, ob sich die BIOS-Version in der Zwischenzeit geändert hat.
Einfach in der CMD "systeminfo" eingeben und mal durchschauen, dort gibt es einen Eintrag dafür. Das kannst du dann mit AutoIt auch automaitisert auslesen.
Ich hab das Dokument mal überflogen. Es schaut nach recht einfachem XML aus. Also eigentlich nicht so das große Problem, ist halt fleißarbeit, alles zu berücksichigen/abzudecken.
Da ich selbst schon mit dem EPUB (Ebook)-Standard gearbeitet habe, erst mit AutoIt (improvisiert) und später mit Java ordentlich, sprech ich mal aus Erfahrung: Solche Umfangreichen Projekte würde ich nicht mit AutoIt machen...
Es ist um ein vielfaches einfacher und auch übersichtlicher, Objektorientiert zu arbeiten, wobei jedes Objekt einzelnen XML-Teilen entspricht und die dann eine Funktion haben, sich selbst in XML zu serializieren (umzuwandeln).
Dann kann man den Standard durchgehen und muss sich nur die einzelnen XML-Elemente anschauen, was sie beinhalten und dementsprechend Felder (Variablen im Objekt) anlegen, die jeweils dem gewollten entsprechen => Attribute, einzelne andere XML-Objekte oder ganze Listen von anderen Objekten. Dabei erstellt man dann einen Baum und kann am Ende dem obersten (root) Element serializieren und erhält das fertige Dokument. Dadurch ist jedes Element quasi gekapselt und man kann den Überblick behalten und auch ggf. Änderungen einfach und schnell umsetzen.
Ich hab das ganze auch noch so gemacht, dass alles Java-Observable Variablen sind, was dafür sorgt, dass sich alles automatisch aktualisert. Ich kann also in meiner GUI Elemente ändern und überall, wo das Element verwendet wird, steht automatisch immer der aktuellste Wert.
Das ganze kann dann auch ohne große Schwierigkeiten wieder deserialisiert (wieder von XML in unsere Objekte umgewandelt) werden, indem es eine Methode gibt, die das macht und jedes Parent-Objekt weiß ja, was für Elemente dort enthalten sein können und ruft dann an den anderen Objekte die passende deserialisierungs Methode auf.
Kann man das ganze auch in AutoIt mit z.B. Maps umsetzen? Ja. Würde ich es machen/empfehlen? Nein. Am vielversprechensten wäre dann der Ansatz, mit Maps zu arbeiten und für jedes Objekt eine Datei zu erstellen, die dann includiert wird,...
Das hier sollte machen was du möchtest:
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
Global $bInOneGui = False
Global $mGui = _guiCreate()
While True
If _handleGuiMessages() Then ExitLoop
WEnd
Func _guiCreate()
Local Const $arBtnDefs = [ _
["Pegasos 2", "pics/PegasosII.ico", "Pegasos_II.bat", true, Default], _
["AmigaOne", "pics/AmigaOne.ico", "AmigaOne.bat", true, "Example.txt"], _
["Sam460ex", "pics/Sam460ex.ico", "Sam460.bat", true, Default], _
["Other", "pics/Sam460ex.ico", "other.bat", false, Default] _
]
Local $mGui[], $arButtonCtrlIds[UBound($arBtnDefs)][3]
$mGui.btnDef = $arBtnDefs
Local $iWidth = 300, $iHeight = 130+UBound($arBtnDefs)*50
$mGui.hGui = GUICreate("AmigaNG Starter v0.1", $iWidth, $iHeight)
GuiSetIcon("pics/amigaos.ico", 0)
;BACKGROUND PIC
;GuiCtrlCreatePic("pics/boingball.jpg", -1, -1, 300, 280)
Local $sName = FileGetVersion( "qemu-system-ppc.exe", "ProductName")<>""?FileGetVersion( "qemu-system-ppc.exe", "ProductName"):"QEMU"
GUICtrlCreateLabel($sName, 112, 15, 71, 31)
Local $sVersion = FileGetVersion( "qemu-system-ppc.exe", "ProductVersion")
GUICtrlCreateLabel($sVersion<>""?$sVersion:"- Not installed", 149, 15, 71, 31)
; start create vm buttons
For $i=0 to UBound($arBtnDefs)-1 Step 1
Local $iTop = 50*($i+1)
$arButtonCtrlIds[$i][0] = GUICtrlCreateButton($arBtnDefs[$i][0], 15, $iTop, 164, 34, $BS_ICON)
GUICtrlSetImage($arButtonCtrlIds[$i][0], $arBtnDefs[$i][1])
If $arBtnDefs[$i][3] Then $arButtonCtrlIds[$i][1] = GUICtrlCreateButton ("Edit", 185, $iTop+2, 50, 30)
If $arBtnDefs[$i][4]<>Default Then $arButtonCtrlIds[$i][2] = GUICtrlCreateButton ("Example", 237, $iTop+2, 50, 30)
Next
$mGui.buttons = $arButtonCtrlIds
; end create vm buttons
;Start Create Image Buttons
If $bInOneGui Then
Local $iImageTop = $iHeight-50
GUICtrlCreateLabel("Create HDD Image:", 25, $iImageTop-20)
$mGui.inputRam = GUICtrlCreateInput('2048', 25, $iImageTop, 50, 20)
GUICtrlCreateLabel("MB", 80, $iImageTop+5)
$mGui.inputPathQemu = GUICtrlCreateInput('', 115, $iImageTop, 50, 20)
$mGui.buttonPath = GUICtrlCreateButton("...", 170, $iImageTop, 40, 20)
$mGui.buttonOk = GUICtrlCreateButton("OK", 215, $iImageTop, 40, 20)
Else
$mGui.buttonImageGui = GUICtrlCreateButton("Create Image", 10, $iHeight-55, $iWidth-20, 25)
Local $iGuiImageWidth = 400, $iGuiImageHeight = 80, $mImageGui[]
$mImageGui.hGui = GUICreate("Create HDD Image", $iGuiImageWidth, $iGuiImageHeight) ; create controls on the new gui now
Local $iTop = 10
$mImageGui.inputRam = GUICtrlCreateInput('2048', 10, $iTop, 50, 20)
GUICtrlCreateLabel("MB", 65, $iTop+5)
$iTop+=30
$mImageGui.inputPathQemu = GUICtrlCreateInput('', 10, $iTop, $iGuiImageWidth-120, 20)
$mImageGui.buttonPath = GUICtrlCreateButton("...", $iGuiImageWidth-100, $iTop, 40, 20)
$mImageGui.buttonOk = GUICtrlCreateButton("OK", $iGuiImageWidth-50, $iTop, 40, 20)
$mGui.imageGui = $mImageGui
GUISwitch($mGui.hGui) ; Create controls after this line on the main gui again
EndIf
;End Create Image Buttons
;start shell output gui
$mGui.buttonQemuHelp = GUICtrlCreateButton("Show "&$sName&" Help", 10, $iHeight-85, $iWidth-20, 25)
Local $mShellGui[], $iShellGuiWidth = 800, $iShellGuiHeight = 600
$mShellGui.hGui = GUICreate("Shell output", $iShellGuiWidth, $iShellGuiHeight, -1, -1, -1, -1, $mGui.hGui)
$mShellGui.editOutErr = GUICtrlCreateEdit("", 10, 10, $iShellGuiWidth-20, $iShellGuiHeight-20, _
BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY, $ES_MULTILINE))
$mGui.shellGui = $mShellGui
GUISwitch($mGui.hGui) ; Create controls after this line on the main gui again
;end shell output gui
$mGui.menuFile = GUICtrlCreateMenu("&QEmu")
$mGui.menuExit = GUICtrlCreateMenuItem("Exit", $mGui.menuFile)
$mGui.menuHelp = GUICtrlCreateMenu("?")
$mGui.menuInfo = GUICtrlCreateMenuItem("Info", $mGui.menuHelp)
GUISetState(@SW_SHOW, $mGui.hGui)
return $mGui
EndFunc
Func _handleGuiMessages()
Local $arMsg = GUIGetMsg(1)
; Handle input on the main gui
If $arMsg[1] = $mGui.hGui Then
Switch $arMsg[0]
Case $GUI_EVENT_CLOSE, $mGui.menuExit
return True
Case $mGui.menuInfo
MsgBox($MB_SYSTEMMODAL, "Info", "AmigaNG Starter v0.1" & @CRLF & @CRLF & "by Falke_34")
Case $mGui.buttonPath
GUICtrlSetData($mGui.imageGui.inputPathQemu, _imageSelectPath($mGui.hGui))
Case $mGui.buttonImageGui
GUISetState(@SW_SHOW, $mGui.imageGui.hGui)
Case $mGui.buttonOk
_imageCreate(Int(GUICtrlRead($mGui.inputRam)), GUICtrlRead($mGui.inputPathQemu))
If @error Then MsgBox(16, "Error creating image", "Error: "&@error&" Ext: "&@extended)
Case $mGui.buttonQemuHelp
GUISetState(@SW_SHOW, $mGui.shellGui.hGui)
Local $sCommand = "qemu-system-ppc.exe -machine help"
; Local $sCommand = @ComSpec & ' /c test.bat'
_runWait($sCommand, @ScriptDir, @SW_SHOW, "_handleGuiMessages", "_shellShowOutErr")
If @error=0 And @extended=1 Then return True ; Exit, when main gui was closed in callback
If @error Then
GUISetState(@SW_HIDE, $mGui.shellGui.hGui)
MsgBox(16, "Error running", "Error running: "&$sCommand&@crlf&"Error code: "&@error&" Ext: "&@extended)
EndIf
; Enable to remove gui, when done
; GUISetState(@SW_HIDE, $mGui.shellGui.hGui)
; GUICtrlSetData($mGui.shellGui.editOutErr, "")
EndSwitch
; Check if one of the buttons from our array was clicked and handle that
If $arMsg[0]<>0 Then
For $i=0 to UBound($mGui.buttons)-1 Step 1
For $j=0 to UBound($mGui.buttons, 2)-1 Step 1
If $arMsg[0]=$mGui.buttons[$i][$j] Then
Local $subIndex = ($j=0 or $j=1)?2:4
If $j=0 Then _run($mGui.btnDef[$i][$subIndex])
If $j=1 Then _edit($mGui.btnDef[$i][$subIndex])
If $j=2 Then _edit($mGui.btnDef[$i][$subIndex])
Local $iError = @error
Local $iExt = @extended
If $iError Then MsgBox(16, "Error executing code", "Error running/editing/showing """&$mGui.btnDef[$i][$subIndex]&""" Error: "&$iError&" Ext: "&$iExt)
return True
EndIf
Next
Next
EndIf
EndIf
; Handle input on the image gui
If $arMsg[1] = $mGui.imageGui.hGui Then
Switch $arMsg[0]
Case $GUI_EVENT_CLOSE
GUISetState(@SW_HIDE, $mGui.imageGui.hGui)
GUICtrlSetData($mGui.imageGui.inputPathQemu, "")
Case $mGui.imageGui.buttonPath
GUICtrlSetData($mGui.imageGui.inputPathQemu, _imageSelectPath($mGui.imageGui.hGui))
Case $mGui.imageGui.buttonOk
_imageCreate(Int(GUICtrlRead($mGui.imageGui.inputRam)), GUICtrlRead($mGui.imageGui.inputPathQemu))
If @error Then
MsgBox(16, "Error creating image", "Error: "&@error&" Ext: "&@extended)
Else
GUISetState(@SW_HIDE, $mGui.imageGui.hGui)
GUICtrlSetData($mGui.imageGui.inputPathQemu, "")
EndIf
EndSwitch
EndIf
If $arMsg[1] = $mGui.shellGui.hGui Then
Switch $arMsg[0]
Case $GUI_EVENT_CLOSE
GUISetState(@SW_HIDE, $mGui.shellGui.hGui)
GUICtrlSetData($mGui.shellGui.editOutErr, "")
EndSwitch
EndIf
return False
EndFunc
Func _shellShowOutErr($sData, $bError)
If $bError Then
GUICtrlSetData("Error: "&$mGui.shellGui.editOutErr, $sData, 1)
Else
GUICtrlSetData($mGui.shellGui.editOutErr, $sData, 1)
EndIf
EndFunc
Func _runWait($sCommand, $sWorkingDir=@ScriptDir, $iShowFlag=@SW_SHOW, $sCallbackHandler=Default, $sCallbackSTDOUT=Default, $bBinary=False)
Local $iFlag = 0
If $sCallbackSTDOUT<>Default Then $iFlag = BitOR($iFlag, 2, 4)
Local $iPID = Run($sCommand, $sWorkingDir, $iShowFlag, $iFlag)
If @error Then return SetError(1, @error, False)
While ProcessExists($iPID)
If $sCallbackSTDOUT<>Default Then
Local $sOut = StdoutRead($iPID, False, $bBinary)
If @error Then ExitLoop
If @extended>0 Then Call($sCallbackSTDOUT, $sOut, False)
EndIf
If $sCallbackSTDOUT<>Default Then
Local $sErr = StderrRead($iPID, False, $bBinary)
If @error Then ExitLoop
If @extended>0 Then Call($sCallbackSTDOUT, $sErr, True)
EndIf
If $sCallbackHandler<>Default Then
If Call($sCallbackHandler) Then return SetError(0, 1, True)
EndIf
WEnd
return True
EndFunc
Func _run($sFile)
Run($sFile)
If @error Then return SetError(1, @error, False)
return True
EndFunc
Func _edit($sFile)
Run("notepad.exe "&$sFile)
If @error Then return SetError(1, @error, False)
return True
EndFunc
Func _imageSelectPath($hGui = 0, $sStartFolder=@ScriptDir)
Local $sFolder = FileSelectFolder("Select folder", $sStartFolder, 0, "", $hGui)
If @error or $sFolder="" Then return SetError(1, 0, "")
return $sFolder
EndFunc
Func _imageCreate($iRam, $sPath)
If $iRam<1 Then return SetError(1, 0, False)
If $sPath="" Then return SetError(2, 0, False)
Local $sCommand = 'qemu-img.exe create -f raw "'&$sPath&'" '&$iRam&'M'
ConsoleWrite("Execute: "&$sCommand&@crlf)
Run($sCommand, @ScriptDir)
If @error Then Return SetError(3, @extended, False)
return True
EndFunc
Alles anzeigen
Du kannst dafür Run nutzen, musst nur den Pfad passend mit " escapen, falls dort Leerzeichen vorkommen. Mit GuiCtrlRead kannst du den Inhalt der controls auslesen. Siehe _imageCreate in Zeile 153. Dort kannst du auch weitere Abfragen hinzufügen, die die InputFelder erfüllen müssen.
(Sollte funktionieren, ich hab aber qemu nicht installiert => kanns nicht testen)
Hier das ganze einmal mit den Controls in der Main Gui und einmal in einem extra Fenster (kann mit $bInOneGui oben im Script geändert werden).
Ich hab dabei auch das ganze überarbeitet. Neue Buttons/VMs können in der $arBtnDefs in Zeile 11 hinzugefügt werden und funktionieren dann automatisch (mit Gui-Größen-Anpassung,... ). Dabei werden Arrays genutzt um die Infos zu speichern und später auch die Control-Ids zu speichern.
Ich hab dabei Maps verwendet um die GuiInfos zu speichern, weil ich das lieber mag => Man hat nicht so viele globale variablen, find ich übersichtlicher.
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
Global $bInOneGui = False
_main()
Func _guiCreate()
Local Const $arBtnDefs = [ _
["Pegasos 2", "pics/PegasosII.ico", "Pegasos_II.bat", true, Default], _
["AmigaOne", "pics/AmigaOne.ico", "AmigaOne.bat", true, "Example.txt"], _
["Sam460ex", "pics/Sam460ex.ico", "Sam460.bat", true, Default], _
["Other", "pics/Sam460ex.ico", "other.bat", false, Default] _
]
Local $mGui[], $arButtonCtrlIds[UBound($arBtnDefs)][3]
$mGui.btnDef = $arBtnDefs
Local $iWidth = 300, $iHeight = 130+UBound($arBtnDefs)*50
$mGui.hGui = GUICreate("AmigaNG Starter v0.1", $iWidth, $iHeight)
GuiSetIcon("pics/amigaos.ico", 0)
;BACKGROUND PIC
;GuiCtrlCreatePic("pics/boingball.jpg", -1, -1, 300, 280)
Local $sName = FileGetVersion( "qemu-system-ppc.exe", "ProductName")
GUICtrlCreateLabel($sName<>""?$sName:"QEMU", 112, 15, 71, 31)
Local $sVersion = FileGetVersion( "qemu-system-ppc.exe", "ProductVersion")
GUICtrlCreateLabel($sVersion<>""?$sVersion:"- Not installed", 149, 15, 71, 31)
; start create vm buttons
For $i=0 to UBound($arBtnDefs)-1 Step 1
Local $iTop = 50*($i+1)
$arButtonCtrlIds[$i][0] = GUICtrlCreateButton($arBtnDefs[$i][0], 15, $iTop, 164, 34, $BS_ICON)
GUICtrlSetImage($arButtonCtrlIds[$i][0], $arBtnDefs[$i][1])
If $arBtnDefs[$i][3] Then $arButtonCtrlIds[$i][1] = GUICtrlCreateButton ("Edit", 185, $iTop+2, 50, 30)
If $arBtnDefs[$i][4]<>Default Then $arButtonCtrlIds[$i][2] = GUICtrlCreateButton ("Example", 237, $iTop+2, 50, 30)
Next
$mGui.buttons = $arButtonCtrlIds
; end create vm buttons
;Start Create Image Buttons
If $bInOneGui Then
Local $iImageTop = $iHeight-50
GUICtrlCreateLabel("Create HDD Image:", 25, $iImageTop-20)
$mGui.inputRam = GUICtrlCreateInput('2048', 25, $iImageTop, 50, 20)
GUICtrlCreateLabel("MB", 80, $iImageTop+5)
$mGui.inputPathQemu = GUICtrlCreateInput('', 115, $iImageTop, 50, 20)
$mGui.buttonPath = GUICtrlCreateButton("...", 170, $iImageTop, 40, 20)
$mGui.buttonOk = GUICtrlCreateButton("OK", 215, $iImageTop, 40, 20)
Else
$mGui.buttonImageGui = GUICtrlCreateButton("Create Image", 10, $iHeight-55, $iWidth-20, 25)
Local $iGuiImageWidth = 400, $iGuiImageHeight = 80, $mImageGui[]
$mImageGui.hGui = GUICreate("Create HDD Image", $iGuiImageWidth, $iGuiImageHeight) ; create controls on the new gui now
Local $iTop = 10
$mImageGui.inputRam = GUICtrlCreateInput('2048', 10, $iTop, 50, 20)
GUICtrlCreateLabel("MB", 65, $iTop+5)
$iTop+=30
$mImageGui.inputPathQemu = GUICtrlCreateInput('', 10, $iTop, $iGuiImageWidth-120, 20)
$mImageGui.buttonPath = GUICtrlCreateButton("...", $iGuiImageWidth-100, $iTop, 40, 20)
$mImageGui.buttonOk = GUICtrlCreateButton("OK", $iGuiImageWidth-50, $iTop, 40, 20)
$mGui.imageGui = $mImageGui
GUISwitch($mGui.hGui) ; Create controls after this line on the main gui again
EndIf
;End Create Image Buttons
$mGui.menuFile = GUICtrlCreateMenu("&QEmu")
$mGui.menuExit = GUICtrlCreateMenuItem("Exit", $mGui.menuFile)
$mGui.menuHelp = GUICtrlCreateMenu("?")
$mGui.menuInfo = GUICtrlCreateMenuItem("Info", $mGui.menuHelp)
GUISetState(@SW_SHOW, $mGui.hGui)
return $mGui
EndFunc
Func _main()
Local $mGui = _guiCreate()
Local $iMsg = 0
While 1
$arMsg = GUIGetMsg(1)
; Handle input on the main gui
If $arMsg[1] = $mGui.hGui Then
Switch $arMsg[0]
Case $GUI_EVENT_CLOSE, $mGui.menuExit
ExitLoop
Case $mGui.menuInfo
MsgBox($MB_SYSTEMMODAL, "Info", "AmigaNG Starter v0.1" & @CRLF & @CRLF & "by Falke_34")
Case $mGui.buttonPath
GUICtrlSetData($mGui.imageGui.inputPathQemu, _imageSelectPath($mGui.hGui))
Case $mGui.buttonImageGui
GUISetState(@SW_SHOW, $mGui.imageGui.hGui)
Case $mGui.buttonOk
_imageCreate(Int(GUICtrlRead($mGui.inputRam)), GUICtrlRead($mGui.inputPathQemu))
If @error Then MsgBox(16, "Error creating image", "Error: "&@error&" Ext: "&@extended)
EndSwitch
; Check if one of the buttons from our array was clicked and handle that
If $arMsg[0]<>0 Then
For $i=0 to UBound($mGui.buttons)-1 Step 1
For $j=0 to UBound($mGui.buttons, 2)-1 Step 1
If $arMsg[0]=$mGui.buttons[$i][$j] Then
Local $subIndex = ($j=0 or $j=1)?2:4
If $j=0 Then _run($mGui.btnDef[$i][$subIndex])
If $j=1 Then _edit($mGui.btnDef[$i][$subIndex])
If $j=2 Then _edit($mGui.btnDef[$i][$subIndex])
Local $iError = @error
Local $iExt = @extended
If $iError Then MsgBox(16, "Error executing code", "Error running/editing/showing """&$mGui.btnDef[$i][$subIndex]&""" Error: "&$iError&" Ext: "&$iExt)
ExitLoop
EndIf
Next
Next
EndIf
EndIf
; Handle input on the image gui
If $arMsg[1] = $mGui.imageGui.hGui Then
Switch $arMsg[0]
Case $GUI_EVENT_CLOSE
GUISetState(@SW_HIDE, $mGui.imageGui.hGui)
GUICtrlSetData($mGui.imageGui.inputPathQemu, "")
Case $mGui.imageGui.buttonPath
GUICtrlSetData($mGui.imageGui.inputPathQemu, _imageSelectPath($mGui.imageGui.hGui))
Case $mGui.imageGui.buttonOk
_imageCreate(Int(GUICtrlRead($mGui.imageGui.inputRam)), GUICtrlRead($mGui.imageGui.inputPathQemu))
If @error Then
MsgBox(16, "Error creating image", "Error: "&@error&" Ext: "&@extended)
Else
GUISetState(@SW_HIDE, $mGui.imageGui.hGui)
GUICtrlSetData($mGui.imageGui.inputPathQemu, "")
EndIf
EndSwitch
EndIf
WEnd
EndFunc
Func _run($sFile)
Run($sFile)
If @error Then return SetError(1, @error, False)
return True
EndFunc
Func _edit($sFile)
Run("notepad.exe "&$sFile)
If @error Then return SetError(1, @error, False)
return True
EndFunc
Func _imageSelectPath($hGui = 0, $sStartFolder=@ScriptDir)
Local $sFolder = FileSelectFolder("Select folder", $sStartFolder, 0, "", $hGui)
If @error or $sFolder="" Then return SetError(1, 0, "")
return $sFolder
EndFunc
Func _imageCreate($iRam, $sPath)
If $iRam<1 Then return SetError(1, 0, False)
If $sPath="" Then return SetError(2, 0, False)
Local $sCommand = 'qemu-img.exe create -f raw "'&$sPath&'" '&$iRam&'MB'
ConsoleWrite("Execute: "&$sCommand&@crlf)
Run($sCommand, @ScriptDir)
If @error Then Return SetError(3, @extended, False)
return True
EndFunc
Alles anzeigen
Ich hoffe das hilft dir weiter und gibt dir noch mehr Ideen
MfG Kanashius.
Hi
Ich hatte mir das ganze auch mal angesehen, und ich muss sagen, dass ich das mit den vielen Werten im Array nicht so schön fand, weils unübersichtlich ist. Insbesondere, weil je nach control die Reihenfolge wechselt (icon/label),... . Ein weiterer Faktor für mich war dabei, dass du dann auch zusatzfunktionen zum ändern des controls genutzt hast (z.B. GuiCtrlSetFont beim Label).
Also hab ich mir mal alle möglichen GuiCtrlCreate... Funktionen und deren Parameter angeschaut, sowie alle möglichen GuiCtrlSet... funktionen.
Das hier war mein Ergebnis:
GUICtrlCreateGraphic ( left, top [, width [, height [, style]]] )
GUICtrlCreateProgress ( left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateSlider ( left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateTab ( left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateTreeView ( left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateButton ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateCheckbox ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateCombo ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateDate ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateEdit ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateGroup ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateInput ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateLabel ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateList ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateListView ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateMonthCal ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateObj ( ObjectVar, left, top [, width [, height]] )
GUICtrlCreatePic ( filename, left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateRadio ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateAvi ( filename, subfileid, left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
GUICtrlCreateIcon ( filename, iconName, left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
; special stuff
GUICtrlCreateDummy ( )
GUICtrlCreateTabItem ( "text" )
GUICtrlCreateTreeViewItem ( "text", treeviewID )
GUICtrlCreateListViewItem ( "text", listviewID )
GUICtrlCreateContextMenu ( [controlID] )
GUICtrlCreateMenu ( "submenutext" [, menuID = -1 [, menuentry = -1]] )
GUICtrlCreateMenuItem ( "text", menuID [, menuentry = -1 [, menuradioitem = 0]] )
GUICtrlCreateUpdown ( inputcontrolID [, style = -1] )
_CTRL_callback
_CTRL_color
_CTRL_cursor
_CTRL_font
_CTRL_image
_CTRL_limit
_CTRL_onEvent
_CTRL_resizing
_CTRL_size
_CTRL_state
_CTRL_style
_CTRL_tip
Alles anzeigen
Ich hab so eigentlich alle Controls dabei (vllt. noch für das "special stuff" was ändern).
Dabei ist die Funktion _CTRL_def(ByRef $mCtrlMap, $iType, $iLeft, $iTop, $opt1 = Default, $opt2 = Default, $opt3 = Default... entstanden. Man erstellt eine Map für alle Controls und fügt mit dieser Funktion die Controls hinzu.
Alle controls brauchen den Typ ($iCTRL_...) und die Position ($iLeft/$iTop). Danach kommen die "opt" parameter. Je nach funktion sind die unterschiedlich: Controls haben 0 bis 2 parameter vor der position, die sind bei mir hier gelandet und werden als $opt1 und $opt2 angegeben.
Sie können aber auch weggelassen werden. Danach kommen nurnoch die _CTRL_... Funktionen in beliebiger Reihenfolge.
Beispiel mit allen Möglichkeiten:
Global $iWidth = 800, $iHeight = 600
Global $mCtrls[]
_CTRL_def($mCtrls, $iCTRL_BUTTON, 10, 10, "Add column", _CTRL_onEvent("_buttonPressed"), _CTRL_style($BS_BOTTOM), _CTRL_tip("Some cool Tip"))
_CTRL_def($mCtrls, $iCTRL_BUTTON, 10, 40, "Button 2", _CTRL_color(0xFFFFFF, 0x000000), _CTRL_cursor(0))
_CTRL_def($mCtrls, $iCTRL_BUTTON, 10, 70, "Button 3", _CTRL_size(100, 50), _CTRL_font(10, 700, BitOr(2,8)), _CTRL_image("shell32.dll", 22))
_CTRL_def($mCtrls, $iCTRL_INPUT, 10, 130, "", _CTRL_size(Default, 25), _CTRL_limit(5, 1), _CTRL_resizing(BitOR(2, 32)))
_CTRL_def($mCtrls, $iCTRL_CHECKBOX, 10, 160, "Uncheck me", _CTRL_state($GUI_CHECKED))
$ctrlListview = _CTRL_def($mCtrls, $iCTRL_LISTVIEW, 0.02, 0.79, "TextColumn", _CTRL_size(0.96, 0.2), _CTRL_callback("_fillListview"))
GUICreate("Example", $iWidth, $iHeight)
_CTRL_gen($mCtrls, $iWidth, $iHeight)
GUISetState(@SW_SHOW)
; ...
Func _fillListview($iCtrlId)
GUICtrlCreateListViewItem("TestItem 1", $iCtrlId)
GUICtrlCreateListViewItem("TestItem 2", $iCtrlId)
GUICtrlCreateListViewItem("TestItem 3", $iCtrlId)
EndFunc
Alles anzeigen
Dabei hab ich auch die Möglichkeit eingebaut, die Position in Prozent anzugeben. Wenn die Position oder Size <=1 ist, wird das als Prozent der Breite/Höhe angenommen und entsprechend verarbeitet.
Deshalb hat die Methode _CTRL_gen(ByRef $mMap, $iWidth = Default, $iHeight = Default) zum generieren der Controls auch einen Width und Height Parameter, der dann angegeben werden muss.
Umd später noch bei speziellen Controls zu wissen, welches ein Event hatte, wird der Map key des Controls zurückgegeben.
Beispiel: Local $iCtrlButtonSave = _CTRL_def($mCtrlsA, $iCTRL_BUTTON, 10, 340, "Save List", _CTRL_size(100, 30), _CTRL_onEvent("_buttonPressedA"), _CTRL_tip("Liste speichern"))
Später kann dann mit Local Local $key = _CTRL_getKey($mCtrlsA, $iCtrlId) von der Autoit-CtrlID auf den Key gemapped werden um dann mit If $key = $iCtrlButtonSave Then eigene Aktionen auszuführen.
Mit $mCtrlsA[$iCtrlButtonSave].iCtrl kann auch von dem Key auf die AutoIt-CtrlID umgewandelt werden.
Hier einmal dein Code damit umgesetzt, sowie ein weiteres Beispiel:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <GuiListView.au3>
Global $iCTRL_AVI = 1, $iCTRL_BUTTON = 2, $iCTRL_CHECKBOX = 3, $iCTRL_COMBO = 4, $iCTRL_DATE = 5, $iCTRL_EDIT = 6, $iCTRL_GRAPHIC = 7, $iCTRL_GROUP = 8, $iCTRL_ICON = 9, $iCTRL_INPUT = 10
Global $iCTRL_INPUT = 11, $iCTRL_LABEL = 12, $iCTRL_LIST = 13, $iCTRL_LISTVIEW = 14, $iCTRL_MONTHCAL = 15, $iCTRL_OBJ = 16, $iCTRL_PIC = 17, $iCTRL_PROGRESS = 18, $iCTRL_RADIO = 19
Global $iCTRL_SLIDER = 20, $iCTRL_TAB = 21, $iCTRL_TREEVIEW = 22
; => Example A
Global $mCtrlsA[]
Local $iCtrlButtonSave = _CTRL_def($mCtrlsA, $iCTRL_BUTTON, 10, 340, "Save List", _CTRL_size(100, 30), _CTRL_onEvent("_buttonPressedA"), _CTRL_tip("Liste speichern"))
_CTRL_def($mCtrlsA, $iCTRL_BUTTON, 210, 30, "Host1", _CTRL_size(70, 30), _CTRL_onEvent("_buttonPressedA"), _CTRL_tip("nd"))
_CTRL_def($mCtrlsA, $iCTRL_BUTTON, 210, 70, "Host2", _CTRL_size(70, 30), _CTRL_onEvent("_buttonPressedA"), _CTRL_tip("nd"))
_CTRL_def($mCtrlsA, $iCTRL_BUTTON, 210, 110, "Workgroup", _CTRL_size(70, 30), _CTRL_onEvent("_buttonPressedA"), _CTRL_tip("nd"))
_CTRL_def($mCtrlsA, $iCTRL_BUTTON, 280, 30, "Fritz", _CTRL_size(70, 30), _CTRL_onEvent("_buttonPressedA"), _CTRL_tip("nd"))
_CTRL_def($mCtrlsA, $iCTRL_BUTTON, 280, 70, "IT-Service", _CTRL_size(70, 30), _CTRL_onEvent("_buttonPressedA"), _CTRL_tip("nd"))
_CTRL_def($mCtrlsA, $iCTRL_BUTTON, 280, 110, "Lesesaal", _CTRL_size(70, 30), _CTRL_onEvent("_buttonPressedA"), _CTRL_tip("nd"))
_CTRL_def($mCtrlsA, $iCTRL_BUTTON, 190, 340, "Save and choose file", _CTRL_size(160, 30), _CTRL_onEvent("_buttonPressedA"), _CTRL_tip("sdsds"))
_CTRL_def($mCtrlsA, $iCTRL_CHECKBOX, 10, 390, "AdminUser", _CTRL_size(90, 20), _CTRL_state($GUI_CHECKED))
_CTRL_def($mCtrlsA, $iCTRL_LABEL, 210, 10, "Freie Listen", _CTRL_size(100, 20), _CTRL_font(9, 800, 2))
_CTRL_def($mCtrlsA, $iCTRL_ICON, 320, 390, "shell32.dll", 168, _CTRL_size(50, 50), _CTRL_tip("Öffnet die Settings"))
Local $hParent = GUICreate("Button Example", 500, 500)
;Opt("GUIOnEventMode", 1)
;GUISetOnEvent($GUI_EVENT_CLOSE, "_end", $hParent)
_CTRL_gen($mCtrlsA)
GUISetState(@SW_SHOW, $hParent)
Local $bRun = True
; Hauptschleife
While $bRun
Local $iMsg = GUIGetMsg()
Switch $iMsg ; Ereignis abrufen
Case $GUI_EVENT_CLOSE
_end()
EndSwitch
If $iMsg<>0 Then
For $mCtrl in $mCtrlsA
If $mCtrl.iCtrl<>0 And $iMsg = $mCtrl.iCtrl And MapExists($mCtrl, "onEvent") Then Call($mCtrl.onEvent.sFunc, $mCtrl.iCtrl)
Next
EndIf
WEnd
Func _buttonPressedA($iCtrl = -1)
Local $iCtrlId = (IsDeclared("iCtrl")?$iCtrl:@GUI_CtrlId)
Local $key = _CTRL_getKey($mCtrlsA, $iCtrlId)
If $key = $iCtrlButtonSave Then
MsgBox($MB_OK, "Button Clicked", "Button clicked to save something")
Else
MsgBox($MB_OK, "Button Clicked", GUICtrlRead($iCtrlId))
EndIf
EndFunc
Func _end()
$bRun = False
EndFunc
; => Example
Global $iWidth = 800, $iHeight = 600
Global $mCtrls[]
_CTRL_def($mCtrls, $iCTRL_BUTTON, 10, 10, "Add column", _CTRL_onEvent("_buttonPressed"), _CTRL_style($BS_BOTTOM), _CTRL_tip("Some cool Tip"))
_CTRL_def($mCtrls, $iCTRL_BUTTON, 10, 40, "Button 2", _CTRL_color(0xFFFFFF, 0x000000), _CTRL_cursor(0))
_CTRL_def($mCtrls, $iCTRL_BUTTON, 10, 70, "Button 3", _CTRL_size(100, 50), _CTRL_font(10, 700, BitOr(2,8)), _CTRL_image("shell32.dll", 22))
_CTRL_def($mCtrls, $iCTRL_INPUT, 10, 130, "", _CTRL_size(Default, 25), _CTRL_limit(5, 1), _CTRL_resizing(BitOR(2, 32)))
_CTRL_def($mCtrls, $iCTRL_CHECKBOX, 10, 160, "Uncheck me", _CTRL_state($GUI_CHECKED))
$ctrlListview = _CTRL_def($mCtrls, $iCTRL_LISTVIEW, 0.02, 0.79, "TextColumn", _CTRL_size(0.96, 0.2), _CTRL_callback("_fillListview"))
GUICreate("Example", $iWidth, $iHeight)
_CTRL_gen($mCtrls, $iWidth, $iHeight)
GUISetState(@SW_SHOW)
ConsoleWrite("------------RESULT------------"&@crlf)
ConsoleWrite(_toString($mCtrls)&@crlf)
ConsoleWrite("----------END RESULT----------"&@crlf)
While True
Local $iMsg = GUIGetMsg()
If $iMsg = -3 Then Exit
If $iMsg<>0 Then
For $mCtrl in $mCtrls
If $mCtrl.iCtrl<>0 And $iMsg = $mCtrl.iCtrl And MapExists($mCtrl, "onEvent") Then Call($mCtrl.onEvent.sFunc)
Next
EndIf
WEnd
Func _buttonPressed()
ConsoleWrite("Button pressed"&@crlf)
_GUICtrlListView_AddColumn($mCtrls[$ctrlListview].iCtrl, "Added column")
EndFunc
Func _fillListview($iCtrlId)
GUICtrlCreateListViewItem("TestItem 1", $iCtrlId)
GUICtrlCreateListViewItem("TestItem 2", $iCtrlId)
GUICtrlCreateListViewItem("TestItem 3", $iCtrlId)
EndFunc
Func _CTRL_getKey(ByRef $mMap, $iCtrlId)
For $key in MapKeys($mMap)
If $mMap[$key].iCtrl = $iCtrlId Then return $key
Next
return -1
EndFunc
Func _CTRL_gen(ByRef $mMap, $iWidth = Default, $iHeight = Default)
For $key In MapKeys($mMap)
Local $mCtrl = $mMap[$key]
$mCtrl.iLeftCur = (($iWidth<>Default And $mCtrl.iLeft<=1)?$iWidth*$mCtrl.iLeft:$mCtrl.iLeft)
$mCtrl.iWidthCur = (($mCtrl.iWidth<>Default)?(($iWidth<>Default And $mCtrl.iWidth<=1)?$iWidth*$mCtrl.iWidth:$mCtrl.iWidth):(Default))
$mCtrl.iTopCur = (($iHeight<>Default And $mCtrl.iTop<=1)?$iHeight*$mCtrl.iTop:$mCtrl.iTop)
$mCtrl.iHeightCur = (($mCtrl.iHeight<>Default)?(($iHeight<>Default And $mCtrl.iHeight<=1)?$iHeight*$mCtrl.iHeight:$mCtrl.iHeight):(Default))
Switch $mCtrl.iType
Case $iCTRL_AVI
If $mCtrl.param1=Default Then
_errCheck("_CTRL_def with $iType $iCTRL_AVI needs the $opt1 parameter (filename)", False, -1, 1, 0, "_exit", $mCtrl.iLineNumber)
Else
If $mCtrl.param2=Default Then $mCtrl.param2=0
$mCtrl.iCtrl = GUICtrlCreateAvi($mCtrl.param1, $mCtrl.param2, $mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateAvi ($iLeft/$iTop/$opt1 (filename)/$opt2 (subfileid)/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
Case $iCTRL_BUTTON
If $mCtrl.param1=Default Then
_errCheck("_CTRL_def with $iType $iCTRL_BUTTON needs the $opt1 parameter (text)", False, -1, 1, 0, "_exit", $mCtrl.iLineNumber)
Else
$mCtrl.iCtrl = GUICtrlCreateButton($mCtrl.param1, $mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateButton ($iLeft/$iTop/$opt1 (text)/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
Case $iCTRL_CHECKBOX
If $mCtrl.param1=Default Then
_errCheck("_CTRL_def with $iType $iCTRL_CHECKBOX needs the $opt1 parameter (text)", False, -1, 1, 0, "_exit", $mCtrl.iLineNumber)
Else
$mCtrl.iCtrl = GUICtrlCreateCheckbox($mCtrl.param1, $mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateCheckbox ($iLeft/$iTop/$opt1 (text)/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
Case $iCTRL_COMBO
If $mCtrl.param1=Default Then
_errCheck("_CTRL_def with $iType $iCTRL_COMBO needs the $opt1 parameter (text)", False, -1, 1, 0, "_exit", $mCtrl.iLineNumber)
Else
$mCtrl.iCtrl = GUICtrlCreateCombo($mCtrl.param1, $mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateCombo ($iLeft/$iTop/$opt1 (text)/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
Case $iCTRL_DATE
If $mCtrl.param1=Default Then
_errCheck("_CTRL_def with $iType $iCTRL_DATE needs the $opt1 parameter (text)", False, -1, 1, 0, "_exit", $mCtrl.iLineNumber)
Else
$mCtrl.iCtrl = GUICtrlCreateDate($mCtrl.param1, $mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateDate ($iLeft/$iTop/$opt1 (text)/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
Case $iCTRL_EDIT
If $mCtrl.param1=Default Then
_errCheck("_CTRL_def with $iType $iCTRL_EDIT needs the $opt1 parameter (text)", False, -1, 1, 0, "_exit", $mCtrl.iLineNumber)
Else
$mCtrl.iCtrl = GUICtrlCreateEdit($mCtrl.param1, $mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateEdit ($iLeft/$iTop/$opt1 (text)/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
Case $iCTRL_GRAPHIC
$mCtrl.iCtrl = GUICtrlCreateGraphic($mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateGraphic ($iLeft/$iTop/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
Case $iCTRL_GROUP
If $mCtrl.param1=Default Then
_errCheck("_CTRL_def with $iType $iCTRL_GROUP needs the $opt1 parameter (text)", False, -1, 1, 0, "_exit", $mCtrl.iLineNumber)
Else
$mCtrl.iCtrl = GUICtrlCreateGroup($mCtrl.param1, $mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateGroup ($iLeft/$iTop/$opt1 (text)/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
Case $iCTRL_ICON
If $mCtrl.param1=Default Then
_errCheck("_CTRL_def with $iType $iCTRL_ICON needs the $opt1 parameter (filename)", False, -1, 1, 0, "_exit", $mCtrl.iLineNumber)
Else
If $mCtrl.param2=Default Then $mCtrl.param2=-1
$mCtrl.iCtrl = GUICtrlCreateIcon($mCtrl.param1, $mCtrl.param2, $mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateIcon ($iLeft/$iTop/$opt1 (filename)/$opt2 (iconName)/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
Case $iCTRL_INPUT
If $mCtrl.param1=Default Then
_errCheck("_CTRL_def with $iType $iCTRL_INPUT needs the $opt1 parameter (text)", False, -1, 1, 0, "_exit", $mCtrl.iLineNumber)
Else
$mCtrl.iCtrl = GUICtrlCreateInput($mCtrl.param1, $mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateInput ($iLeft/$iTop/$opt1 (text)/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
Case $iCTRL_LABEL
If $mCtrl.param1=Default Then
_errCheck("_CTRL_def with $iType $iCTRL_LABEL needs the $opt1 parameter (text)", False, -1, 1, 0, "_exit", $mCtrl.iLineNumber)
Else
$mCtrl.iCtrl = GUICtrlCreateLabel($mCtrl.param1, $mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateLabel ($iLeft/$iTop/$opt1 (text)/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
Case $iCTRL_LIST
If $mCtrl.param1=Default Then
_errCheck("_CTRL_def with $iType $iCTRL_LIST needs the $opt1 parameter (text)", False, -1, 1, 0, "_exit", $mCtrl.iLineNumber)
Else
$mCtrl.iCtrl = GUICtrlCreateList($mCtrl.param1, $mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateList ($iLeft/$iTop/$opt1 (text)/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
Case $iCTRL_LISTVIEW
If $mCtrl.param1=Default Then
_errCheck("_CTRL_def with $iType $iCTRL_LISTVIEW needs the $opt1 parameter (text)", False, -1, 1, 0, "_exit", $mCtrl.iLineNumber)
Else
$mCtrl.iCtrl = GUICtrlCreateListView($mCtrl.param1, $mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateListView ($iLeft/$iTop/$opt1 (text)/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
Case $iCTRL_MONTHCAL
If $mCtrl.param1=Default Then
_errCheck("_CTRL_def with $iType $iCTRL_MONTHCAL needs the $opt1 parameter (text)", False, -1, 1, 0, "_exit", $mCtrl.iLineNumber)
Else
$mCtrl.iCtrl = GUICtrlCreateMonthCal($mCtrl.param1, $mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateMonthCal ($iLeft/$iTop/$opt1 (text)/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
Case $iCTRL_OBJ
If $mCtrl.param1=Default Then
_errCheck("_CTRL_def with $iType $iCTRL_OBJ needs the $opt1 parameter (text)", False, -1, 1, 0, "_exit", $mCtrl.iLineNumber)
Else
$mCtrl.iCtrl = GUICtrlCreateObj($mCtrl.param1, $mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateObj ($iLeft/$iTop/$opt1 (ObjectVar)/_CTRL_size)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
Case $iCTRL_PIC
If $mCtrl.param1=Default Then
_errCheck("_CTRL_def with $iType $iCTRL_PIC needs the $opt1 parameter (filename)", False, -1, 1, 0, "_exit", $mCtrl.iLineNumber)
Else
$mCtrl.iCtrl = GUICtrlCreatePic($mCtrl.param1, $mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreatePic ($iLeft/$iTop/$opt1 (filename)/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
Case $iCTRL_PROGRESS
$mCtrl.iCtrl = GUICtrlCreateProgress($mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateProgress ($iLeft/$iTop/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
Case $iCTRL_RADIO
If $mCtrl.param1=Default Then
_errCheck("_CTRL_def with $iType $iCTRL_RADIO needs the $opt1 parameter (text)", False, -1, 1, 0, "_exit", $mCtrl.iLineNumber)
Else
$mCtrl.iCtrl = GUICtrlCreateRadio($mCtrl.param1, $mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateRadio ($iLeft/$iTop/$opt1 (text)/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
Case $iCTRL_SLIDER
$mCtrl.iCtrl = GUICtrlCreateSlider($mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateSlider ($iLeft/$iTop/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
Case $iCTRL_TAB
$mCtrl.iCtrl = GUICtrlCreateTab($mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateTab ($iLeft/$iTop/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
Case $iCTRL_TREEVIEW
$mCtrl.iCtrl = GUICtrlCreateTreeView($mCtrl.iLeftCur, $mCtrl.iTopCur, $mCtrl.iWidthCur, $mCtrl.iHeightCur, $mCtrl.iStyle, $mCtrl.iStyleEx)
_errCheck("Data provided by _CTRL_def caused an error calling GUICtrlCreateTreeView ($iLeft/$iTop/_CTRL_size/_CTRL_style)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndSwitch
If Not @error Then
If MapExists($mCtrl, "callback") Then Call($mCtrl.callback.sFunc, $mCtrl.iCtrl)
_errCheck("Data provided by _CTRL_callback for _CTRL_def caused an error calling Call. Check if the provided function exists and has exactly one parameter ($iCtrlId)", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
If MapExists($mCtrl, "color") Then
If $mCtrl.color.iTextColor<>Default Then GUICtrlSetColor($mCtrl.iCtrl, $mCtrl.color.iTextColor)
_errCheck("Data provided by _CTRL_color for _CTRL_def caused an error calling GUICtrlSetColor", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
If $mCtrl.color.iBGColor<>Default Then GUICtrlSetBkColor($mCtrl.iCtrl, $mCtrl.color.iBGColor)
_errCheck("Data provided by _CTRL_color for _CTRL_def caused an error calling GUICtrlSetBkColor", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
If MapExists($mCtrl, "cursor") Then GUICtrlSetCursor($mCtrl.iCtrl, $mCtrl.cursor.iCursor)
_errCheck("Data provided by _CTRL_cursor for _CTRL_def caused an error calling GuiCtrlSetCursor", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
If MapExists($mCtrl, "font") Then GUICtrlSetFont($mCtrl.iCtrl, $mCtrl.font.fSize, $mCtrl.font.iWeight, $mCtrl.font.iAttribute, $mCtrl.font.sFontName, $mCtrl.font.iQuality)
_errCheck("Data provided by _CTRL_font for _CTRL_def caused an error calling GUICtrlSetFont", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
If MapExists($mCtrl, "image") Then GUICtrlSetImage($mCtrl.iCtrl, $mCtrl.image.sFilename, $mCtrl.image.sIconName, $mCtrl.image.iIconType)
_errCheck("Data provided by _CTRL_image for _CTRL_def caused an error calling GUICtrlSetImage", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
If MapExists($mCtrl, "limit") Then GUICtrlSetLimit($mCtrl.iCtrl, $mCtrl.limit.iMax, $mCtrl.limit.iMin)
_errCheck("Data provided by _CTRL_limit for _CTRL_def caused an error calling GUICtrlSetLimit", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
If MapExists($mCtrl, "onEvent") Then GUICtrlSetOnEvent($mCtrl.iCtrl, $mCtrl.onEvent.sFunc)
_errCheck("Data provided by _CTRL_onEvent for _CTRL_def caused an error calling GUICtrlSetOnEvent", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
If MapExists($mCtrl, "resizing") Then GUICtrlSetResizing($mCtrl.iCtrl, $mCtrl.resizing.iResizing)
_errCheck("Data provided by _CTRL_resizing for _CTRL_def caused an error calling GUICtrlSetResizing", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
If MapExists($mCtrl, "state") Then GUICtrlSetState($mCtrl.iCtrl, $mCtrl.state.iState)
_errCheck("Data provided by _CTRL_state for _CTRL_def caused an error calling GUICtrlSetState", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
If MapExists($mCtrl, "tip") Then GUICtrlSetTip($mCtrl.iCtrl, $mCtrl.tip.sText, $mCtrl.tip.sTitle, $mCtrl.tip.iIcon, $mCtrl.tip.iOptions)
_errCheck("Data provided by _CTRL_tip for _CTRL_def caused an error calling GUICtrlSetTip", False, -1, @error, @extended, "_exit", $mCtrl.iLineNumber)
EndIf
$mMap[$key] = $mCtrl
Next
EndFunc
Func _CTRL_def(ByRef $mCtrlMap, $iType, $iLeft, $iTop, $opt1 = Default, $opt2 = Default, $opt3 = Default, $opt4 = Default, $opt5 = Default, $opt6 = Default, $opt7 = Default, $opt8 = Default, _
$opt9 = Default, $opt10 = Default, $opt11 = Default, $opt12 = Default, $opt13 = Default, $opt14 = Default, $iLineNumber = @ScriptLineNumber)
If Not IsMap($mCtrlMap) Then return SetError(1, 0, -1)
If Not IsInt($iType) And $iType>=$iCTRL_AVI And $iType<=$iCTRL_TREEVIEW Then return SetError(2, 0, -1)
Local $mEntry[]
$mEntry.iCtrl = 0
$mEntry.iType = $iType
$mEntry.iLeft = $iLeft
$mEntry.iTop = $iTop
$mEntry.param1 = Default
$mEntry.param2 = Default
$mEntry.iWidth = Default
$mEntry.iHeight = Default
$mEntry.iStyle = -1
$mEntry.iStyleEx = -1
$mEntry.iLineNumber = $iLineNumber
Local $iStart = 1
If $opt1<>Default And Not IsMap($opt1) Then
$iStart = 2
$mEntry.param1 = $opt1
EndIf
If $opt2<>Default And Not IsMap($opt2) Then
$iStart = 3
$mEntry.param2 = $opt2
EndIf
For $i=$iStart to @NumParams-4 Step 1
Local $param = Eval("opt"&$i)
If IsMap($param) Then
If $param["type"]="size" Then
$mEntry.iWidth = $param["iWidth"]
$mEntry.iHeight = $param["iHeight"]
ElseIf $param["type"]="style" Then
$mEntry.iStyle = $param["iStyle"]
$mEntry.iStyleEx = $param["iStyleEx"]
Else
Local $mExtra[]
For $key In MapKeys($param)
If $key<>"type" Then
$mExtra[$key] = $param[$key]
EndIf
Next
$mEntry[$param["type"]] = $mExtra
EndIf
ElseIf $param<>Default Then
ConsoleWrite("Error ("&$iLineNumber&"): The optional parameter 'opt"&$i&"' is not a Map/Default!"&@crlf)
EndIf
Next
return MapAppend($mCtrlMap, $mEntry)
EndFunc
Func _CTRL_callback($sFunc)
Local $mMap[]
$mMap.type = "callback"
$mMap.sFunc = $sFunc
return $mMap
EndFunc
Func _CTRL_color($iTextColor = Default, $iBackgroundColor = Default)
Local $mMap[]
$mMap.type = "color"
$mMap.iTextColor = $iTextColor
$mMap.iBGColor = $iBackgroundColor
return $mMap
EndFunc
Func _CTRL_cursor($iCursorID)
Local $mMap[]
$mMap.type = "cursor"
$mMap.iCursor = $iCursorID
return $mMap
EndFunc
Func _CTRL_font($fSize = 8.5, $iWeight = 0, $iAttribute = 0, $sFontName = "", $iQuality = 0)
Local $mMap[]
$mMap.type = "font"
$mMap.fSize = $fSize
$mMap.iWeight = $iWeight
$mMap.iAttribute = $iAttribute
$mMap.sFontName = $sFontName
$mMap.iQuality = $iQuality
return $mMap
EndFunc
Func _CTRL_image($sFilename, $sIconName = -1, $iIconType = 1)
Local $mMap[]
$mMap.type = "image"
$mMap.sFilename = $sFilename
$mMap.sIconName = $sIconName
$mMap.iIconType = $iIconType
return $mMap
EndFunc
Func _CTRL_limit($iMax, $iMin = 0)
Local $mMap[]
$mMap.type = "limit"
$mMap.iMax = $iMax
$mMap.iMin = $iMin
return $mMap
EndFunc
Func _CTRL_onEvent($sFunc)
Local $mMap[]
$mMap.type = "onEvent"
$mMap.sFunc = $sFunc
return $mMap
EndFunc
Func _CTRL_resizing($iResizing)
Local $mMap[]
$mMap.type = "resizing"
$mMap.iResizing = $iResizing
return $mMap
EndFunc
Func _CTRL_size($iWidth = Default, $iHeight = Default)
Local $mMap[]
$mMap.type = "size"
$mMap.iWidth = $iWidth
$mMap.iHeight = $iHeight
return $mMap
EndFunc
Func _CTRL_state($iState)
Local $mMap[]
$mMap.type = "state"
$mMap.iState = $iState
return $mMap
EndFunc
Func _CTRL_style($iStyle = -1, $iStyleEx = -1)
Local $mMap[]
$mMap.type = "style"
$mMap.iStyle = $iStyle
$mMap.iStyleEx = $iStyleEx
return $mMap
EndFunc
Func _CTRL_tip($sText, $sTitle = Default, $iIcon = 0, $iOptions = 0)
Local $mMap[]
$mMap.type = "tip"
$mMap.sText = $sText
$mMap.sTitle = $sTitle
$mMap.iIcon = $iIcon
$mMap.iOptions = $iOptions
return $mMap
EndFunc
; #FUNCTION# =======================================================================================
; Name ..........: _toString
; Description ...: Returns the content of a variable as String
; Syntax ........: _toString($data, $bInformative = True, $sPrefixSep = @TAB, $sSpaceOuter = @crlf, $sSpaceInner = @crlf, $iDepth = 0)
; Parameters ....: $data - The variable to be converted.
; $bInformative - The level of detail. When True, the type of all variables is returned and not only the content
; $sPrefixSep - The prefix value used for indentation
; $sSpaceOuter - The space between levels of dimensions (Array) or at the beginning of a Map/DllStruct
; $sSpaceInner - The space between items of an Array/Map/DllStruct
; $iDepth - INTERNAL: The depth level of the call. Used in recursive calls to indent items
; Return values .: String
; Author ........: Kanashius
; ==================================================================================================
Func _toString(ByRef $data, $bInformative = True, $sPrefixSep = @TAB, $sSpaceOuter = @crlf, $sSpaceInner = @crlf, $iDepth = 0)
Local $sPrefix = ""
For $i=0 to $iDepth-1
$sPrefix &= $sPrefixSep
Next
If IsArray($data) Then
Local $bPrefix = False
If StringInStr($sSpaceOuter, @crlf) or StringInStr($sSpaceInner, @crlf) Then
$bPrefix = True
Else
$sPrefixSep = ""
EndIf
Local $iDimensions = UBound($data, 0)
Local $sDim = ""
For $i = 1 to $iDimensions Step 1
$sDim &= "["&UBound($data, $i)&"]"
Next
Local $sOut = $sPrefix & ($bInformative ? "Array"&$sDim&" [" : "[") & $sSpaceOuter
For $i=0 To UBound($data, 1)-1 Step 1
If $iDimensions<2 Then
$sOut &= _toString($data[$i], $bInformative, $sPrefixSep, $sSpaceOuter, $sSpaceInner, $iDepth+1) & (($i<>UBound($data, 1)-1)?"," & $sSpaceInner:$sSpaceOuter)
Else
$sOut &= ($bPrefix?$sPrefix & $sPrefixSep:"") & "[" & $sSpaceOuter
For $j=0 To UBound($data, 2)-1 Step 1
If $iDimensions<3 Then
$sOut &= _toString($data[$i][$j], $bInformative, $sPrefixSep, $sSpaceOuter, $sSpaceInner, $iDepth+2) & (($j<>UBound($data, 2)-1)?"," & $sSpaceInner:$sSpaceOuter)
Else
$sOut &= ($bPrefix?$sPrefix & $sPrefixSep & $sPrefixSep:"") & "[" & $sSpaceOuter
For $k=0 To UBound($data, 3)-1 Step 1
$sOut &= _toString($data[$i][$j][$k], $bInformative, $sPrefixSep, $sSpaceOuter, $sSpaceInner, $iDepth+3) & (($k<>UBound($data, 3)-1)?"," & $sSpaceInner:$sSpaceOuter)
Next
$sOut &= ($bPrefix?$sPrefix & $sPrefixSep & $sPrefixSep:"") & "]" & (($j<>UBound($data, 2)-1)?"," & $sSpaceInner:"") & $sSpaceOuter
EndIf
Next
$sOut &= ($bPrefix?$sPrefix & $sPrefixSep:"") & "]" & (($i<>UBound($data, 1)-1)?"," & $sSpaceInner:$sSpaceOuter)
EndIf
Next
$sOut &= ($bPrefix?$sPrefix:"") & "]"
return $sOut
ElseIf IsBinary($data) Then
return $sPrefix & ($bInformative ? 'binary "'&String($data)&'"' : String($data))
ElseIf IsBool($data) Then
return $sPrefix & ($bInformative ? 'bool "'&StringLower(String($data))&'"' : StringLower(String($data)))
ElseIf IsDllStruct($data) Then
Local $bPrefix = StringInStr($sSpaceInner, @crlf)
Local $sOut = $sPrefix & ($bInformative ? "DllStruct[b"&DllStructGetSize($data)&"]{" : "{") & $sSpaceOuter
Local $iCount = 1
While True
Local $oTmp = DllStructGetData($data, $iCount)
If @error Then ExitLoop
$sOut &= _toString($oTmp, $bInformative, $sPrefixSep, $sSpaceOuter, $sSpaceInner, $iDepth+1)
$iCount += 1
$sOut &= "," & $sSpaceInner
WEnd
$sOut &= ($bPrefix?$sPrefix:"") & "}"
return $sOut
ElseIf IsFunc($data) Then
return $sPrefix & ($bInformative ? 'function "'&FuncName($data)&'"' : FuncName($data))
ElseIf IsFloat($data) Then
return $sPrefix & ($bInformative ? 'float "'&String($data)&'"' : String($data))
ElseIf IsHWnd($data) Then
return $sPrefix & ($bInformative ? 'hwnd "'&String($data)&'"' : String($data))
ElseIf IsInt($data) Then
return $sPrefix & ($bInformative ? 'int "'&String($data)&'"' : String($data))
ElseIf IsKeyword($data) Then
If $data=Default Then
return $sPrefix & ($bInformative ? 'keyword "Default"' : "default")
ElseIf $data=Null Then
return $sPrefix & ($bInformative ? 'keyword "Null"' : "null")
EndIf
ElseIf IsMap($data) Then
Local $sOut = $sPrefix & ($bInformative ? "Map["&UBound($data)&"] {" : "{") & $sSpaceOuter
For $key in MapKeys($data)
$sOut &= _toString($key, $bInformative, $sPrefixSep, $sSpaceOuter, $sSpaceInner, $iDepth+1) & ": " & $sSpaceOuter & _toString($data[$key], $bInformative, $sPrefixSep, $sSpaceOuter, $sSpaceInner, $iDepth+2)
$sOut &= "," & $sSpaceInner
Next
$sOut &= $sPrefix & "}"
return $sOut
ElseIf IsNumber($data) Then
return $sPrefix & ($bInformative ? 'number "'&String($data)&'"' : String($data))
ElseIf IsObj($data) Then
If ObjName($data, 1) = "Dictionary" Then
_hasErrorOccurred(False)
Local $oErrHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
Local $iCount = $data.count, $arKeys = $data.keys(), $test = $data.item("")
If Not _hasErrorOccurred() Then
Local $sOut = $sPrefix & ($bInformative ? 'Object "'&ObjName($data, 1)&""" Description: """&ObjName($data, 2)&'" ' : ObjName($data, 1)) & "["&$iCount&"]" & "{" &$sSpaceOuter
For $key in $arKeys
Local $item = $data.item($key)
$sOut &= _toString($key, $bInformative, $sPrefixSep, $sSpaceOuter, $sSpaceInner, $iDepth+1) & ": " & $sSpaceOuter & _toString($item, $bInformative, $sPrefixSep, $sSpaceOuter, $sSpaceInner, $iDepth+2)
$sOut &= "," & $sSpaceInner
Next
$sOut &= $sPrefix & "}"
return $sOut
EndIf
EndIf
return $sPrefix & ($bInformative ? 'Object "'&ObjName($data, 1)&""" Description: """&ObjName($data, 2)&'"' : ObjName($data, 1))
ElseIf IsPtr($data) Then
return $sPrefix & ($bInformative ? 'pointer "'&String($data)&'"' : String($data))
ElseIf IsString($data) Then
return $sPrefix & ($bInformative ? 'string "'&$data&'"' : '"'&$data&'"')
Else
return $sPrefix & ($bInformative ? 'unsupported ('&VarGetType($data)&') "'&String($data)&'"' : String($data))
EndIf
EndFunc
Func _ErrFunc($oError)
_hasErrorOccurred(True)
EndFunc
Func _hasErrorOccurred($bError = Default)
Local static $bCurrentError = False
If $bError<>Default Then
$bCurrentError = $bError
EndIf
return $bCurrentError
EndFunc
; #FUNCTION# =======================================================================================
; Name ..........: _errCheck
; Description ...: Checks if the @error is set (function call before this returned an error) and writes the error to the console.
; Syntax ........: _errCheck($sMsg = Default, $bFatal = False, $return = -1, $iError = @error, $iExtended = @extended, $sExitCallback = "_exit", $iLine = @ScriptLineNumber)
; Parameters ....: $sMsg - The message to show in case of an error
; $bFatal - If True, the $sExitCallback will be called to exit the application gracefully
; $return - The value to be returned by this function
; $iError - The @error code
; $iExtended - The @extended code
; $sExitCallback - The function to call on exit
; $iLine - The ScriptLineNumber, where the error occurred
; Return values .: The value specified as $return and it will throw the same @error and @extended codes, the function was called with.
; Author ........: Kanashius
; ==================================================================================================
Func _errCheck($sMsg = Default, $bFatal = False, $return = -1, $iError = @error, $iExtended = @extended, $sExitCallback = "_exit", $iLine = @ScriptLineNumber)
$sMsg = $sMsg<>Default ? " >> "&$sMsg:""
Local $sExtended = $iExtended<>0 ? ":"&$iExtended:""
If $iError<>0 Then ConsoleWrite("Error (line "&$iLine&"): "&$iError&$sExtended&$sMsg&@crlf)
If $bFatal Then
Call($sExitCallback)
If @error Then _errCheck("Error using the ""Call"" function, while handling another error: "&@crlf&@Tab&"Error (line "&$iLine&"): "&$iError&$sExtended&$sMsg&@crlf& _
"Check if the function """&$sExitCallback&""" (used for $bFatal errors) exists and has no parameters!"&@crlf)
EndIf
Return SetError(@error, @extended, $return)
EndFunc
Alles anzeigen
Mit dem Code kann auch beliebig zwischen OnEvent und GuiGetMsg Modus umgeschaltet werden.
Ich hoffe, das hilft dir weiter und gibt dir noch einen anderen (besseren) Ansatz.
MfG, Kanashius.
Ich würde mehrere Möglichkeiten sehen:
Ich muss zugeben, du hast mich dazu inspiriert, eine _toString Methode umzusetzen (die auch Maps ausgeben kann).
Das Errorhandling hatte ich schon vor länger da liegen und hab es mit dazu gepackt
Ausgabe einer Variable als String, rekursiv für Arrays/Maps/DllStructs/... mit der _toString Methode.
Es gibt zwei Modi, einmal wird nur der Inhalt der Variablen ausgegeben, im anderen auch Details wie der Typ. Die Einrückung/Formatierung kann ebenfalls mit Parametern angepasst werden.
Leichteres behandeln von Errorcodes mit der _errCheck Methode, sodass nur noch diese Funktion aufgerufen werden muss und der Fehler automatisch in die Konsole geschrieben wird, ohne ständiges If @error,... .
#include-once
; ==> Beispiel
ConsoleWrite("----------------- String Output -----------------"&@crlf)
Local $mData[]
Local $ar1D = [1, 2, 3, 4]
$mData.arr1D = $ar1D
Local $ar2D = [[1, 2], [3, 4]]
$mData.arr2D = $ar2D
Local $ar3D = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
$mData.arr3D = $ar3D
$mData.binary = Binary(0xFF2312302343221)
$mData.bool = True
Local $tStruct = DllStructCreate("struct;int var1;byte var2;uint var3;char var4[128];endstruct")
DllStructSetData($tStruct, "var1", -1)
DllStructSetData($tStruct, 2, 255)
DllStructSetData($tStruct, "var3", -1)
DllStructSetData($tStruct, "var4", "Hello")
$mData.dllStruct = $tStruct
$mData.func = _toString
$mData.float = 0.341234
$mData.hwnd = WinGetHandle("[ACTIVE]")
$mData.int = 3213
$mData.objDictionary = ObjCreate('Scripting.Dictionary')
$mData.objDictionary.add("1", "eins")
$mData.objDictionary.add(2, "zwei")
$mData.object = ObjCreate("MediaPlayer.MediaPlayer.1")
$mData.pointer = DllStructGetPtr($tStruct)
$mData.string = "Something"
ConsoleWrite(_toString($mData, True)&@crlf)
ConsoleWrite("----------------- Error Handling -----------------"&@crlf)
StringRegExp("error", "\d+", 2)
_errCheck()
StringRegExp("error", "\d+", 2)
_errCheck("Error using StringRegExp")
ConsoleWrite(_errorFunc()&@crlf)
StringRegExp("Fatal Error", "\d+", 2)
_errCheck("Fatal RegExp Error", True)
ConsoleWrite("Well, we will not be getting here :("&@crlf)
Func _errorFunc()
If True Then return _errCheck("Error to be forwarded", False, 10, 1, 5)
EndFunc
Func _exit()
ConsoleWrite("Exit"&@crlf)
Exit
EndFunc
; #FUNCTION# =======================================================================================
; Name ..........: _toString
; Description ...: Returns the content of a variable as String
; Syntax ........: _toString($data, $bInformative = True, $sPrefixSep = @TAB, $sSpaceOuter = @crlf, $sSpaceInner = @crlf, $iDepth = 0)
; Parameters ....: $data - The variable to be converted.
; $bInformative - The level of detail. When True, the type of all variables is returned and not only the content
; $sPrefixSep - The prefix value used for indentation
; $sSpaceOuter - The space between levels of dimensions (Array) or at the beginning of a Map/DllStruct
; $sSpaceInner - The space between items of an Array/Map/DllStruct
; $iDepth - INTERNAL: The depth level of the call. Used in recursive calls to indent items
; Return values .: String
; Author ........: Kanashius
; ==================================================================================================
Func _toString(ByRef $data, $bInformative = True, $sPrefixSep = @TAB, $sSpaceOuter = @crlf, $sSpaceInner = @crlf, $iDepth = 0)
Local $sPrefix = ""
For $i=0 to $iDepth-1
$sPrefix &= $sPrefixSep
Next
If IsArray($data) Then
Local $bPrefix = False
If StringInStr($sSpaceOuter, @crlf) or StringInStr($sSpaceInner, @crlf) Then
$bPrefix = True
Else
$sPrefixSep = ""
EndIf
Local $iDimensions = UBound($data, 0)
Local $sDim = ""
For $i = 1 to $iDimensions Step 1
$sDim &= "["&UBound($data, $i)&"]"
Next
Local $sOut = $sPrefix & ($bInformative ? "Array"&$sDim&" [" : "[") & $sSpaceOuter
For $i=0 To UBound($data, 1)-1 Step 1
If $iDimensions<2 Then
$sOut &= _toString($data[$i], $bInformative, $sPrefixSep, $sSpaceOuter, $sSpaceInner, $iDepth+1) & (($i<>UBound($data, 1)-1)?"," & $sSpaceInner:$sSpaceOuter)
Else
$sOut &= ($bPrefix?$sPrefix & $sPrefixSep:"") & "[" & $sSpaceOuter
For $j=0 To UBound($data, 2)-1 Step 1
If $iDimensions<3 Then
$sOut &= _toString($data[$i][$j], $bInformative, $sPrefixSep, $sSpaceOuter, $sSpaceInner, $iDepth+2) & (($j<>UBound($data, 2)-1)?"," & $sSpaceInner:$sSpaceOuter)
Else
$sOut &= ($bPrefix?$sPrefix & $sPrefixSep & $sPrefixSep:"") & "[" & $sSpaceOuter
For $k=0 To UBound($data, 3)-1 Step 1
$sOut &= _toString($data[$i][$j][$k], $bInformative, $sPrefixSep, $sSpaceOuter, $sSpaceInner, $iDepth+3) & (($k<>UBound($data, 3)-1)?"," & $sSpaceInner:$sSpaceOuter)
Next
$sOut &= ($bPrefix?$sPrefix & $sPrefixSep & $sPrefixSep:"") & "]" & (($j<>UBound($data, 2)-1)?"," & $sSpaceInner:"") & $sSpaceOuter
EndIf
Next
$sOut &= ($bPrefix?$sPrefix & $sPrefixSep:"") & "]" & (($i<>UBound($data, 1)-1)?"," & $sSpaceInner:$sSpaceOuter)
EndIf
Next
$sOut &= ($bPrefix?$sPrefix:"") & "]"
return $sOut
ElseIf IsBinary($data) Then
return $sPrefix & ($bInformative ? 'binary "'&String($data)&'"' : String($data))
ElseIf IsBool($data) Then
return $sPrefix & ($bInformative ? 'bool "'&StringLower(String($data))&'"' : StringLower(String($data)))
ElseIf IsDllStruct($data) Then
Local $bPrefix = StringInStr($sSpaceInner, @crlf)
Local $sOut = $sPrefix & ($bInformative ? "DllStruct[b"&DllStructGetSize($data)&"]{" : "{") & $sSpaceOuter
Local $iCount = 1
While True
Local $oTmp = DllStructGetData($data, $iCount)
If @error Then ExitLoop
$sOut &= _toString($oTmp, $bInformative, $sPrefixSep, $sSpaceOuter, $sSpaceInner, $iDepth+1)
$iCount += 1
$sOut &= "," & $sSpaceInner
WEnd
$sOut &= ($bPrefix?$sPrefix:"") & "}"
return $sOut
ElseIf IsFunc($data) Then
return $sPrefix & ($bInformative ? 'function "'&FuncName($data)&'"' : FuncName($data))
ElseIf IsFloat($data) Then
return $sPrefix & ($bInformative ? 'float "'&String($data)&'"' : String($data))
ElseIf IsHWnd($data) Then
return $sPrefix & ($bInformative ? 'hwnd "'&String($data)&'"' : String($data))
ElseIf IsInt($data) Then
return $sPrefix & ($bInformative ? 'int "'&String($data)&'"' : String($data))
ElseIf IsKeyword($data) Then
If $data=Default Then
return $sPrefix & ($bInformative ? 'keyword "Default"' : "default")
ElseIf $data=Null Then
return $sPrefix & ($bInformative ? 'keyword "Null"' : "null")
EndIf
ElseIf IsMap($data) Then
Local $sOut = $sPrefix & ($bInformative ? "Map["&UBound($data)&"] {" : "{") & $sSpaceOuter
For $key in MapKeys($data)
$sOut &= _toString($key, $bInformative, $sPrefixSep, $sSpaceOuter, $sSpaceInner, $iDepth+1) & ": " & $sSpaceOuter & _toString($data[$key], $bInformative, $sPrefixSep, $sSpaceOuter, $sSpaceInner, $iDepth+2)
$sOut &= "," & $sSpaceInner
Next
$sOut &= $sPrefix & "}"
return $sOut
ElseIf IsNumber($data) Then
return $sPrefix & ($bInformative ? 'number "'&String($data)&'"' : String($data))
ElseIf IsObj($data) Then
If ObjName($data, 1) = "Dictionary" Then
_hasErrorOccurred(False)
Local $oErrHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
Local $iCount = $data.count, $arKeys = $data.keys(), $test = $data.item("")
If Not _hasErrorOccurred() Then
Local $sOut = $sPrefix & ($bInformative ? 'Object "'&ObjName($data, 1)&""" Description: """&ObjName($data, 2)&'" ' : ObjName($data, 1)) & "["&$iCount&"]" & "{" &$sSpaceOuter
For $key in $arKeys
Local $item = $data.item($key)
$sOut &= _toString($key, $bInformative, $sPrefixSep, $sSpaceOuter, $sSpaceInner, $iDepth+1) & ": " & $sSpaceOuter & _toString($item, $bInformative, $sPrefixSep, $sSpaceOuter, $sSpaceInner, $iDepth+2)
$sOut &= "," & $sSpaceInner
Next
$sOut &= $sPrefix & "}"
return $sOut
EndIf
EndIf
return $sPrefix & ($bInformative ? 'Object "'&ObjName($data, 1)&""" Description: """&ObjName($data, 2)&'"' : ObjName($data, 1))
ElseIf IsPtr($data) Then
return $sPrefix & ($bInformative ? 'pointer "'&String($data)&'"' : String($data))
ElseIf IsString($data) Then
return $sPrefix & ($bInformative ? 'string "'&$data&'"' : '"'&$data&'"')
Else
return $sPrefix & ($bInformative ? 'unsupported ('&VarGetType($data)&') "'&String($data)&'"' : String($data))
EndIf
EndFunc
Func _ErrFunc($oError)
_hasErrorOccurred(True)
EndFunc
Func _hasErrorOccurred($bError = Default)
Local static $bCurrentError = False
If $bError<>Default Then
$bCurrentError = $bError
EndIf
return $bCurrentError
EndFunc
; #FUNCTION# =======================================================================================
; Name ..........: _errCheck
; Description ...: Checks if the @error is set (function call before this returned an error) and writes the error to the console.
; Syntax ........: _errCheck($sMsg = Default, $bFatal = False, $return = -1, $iError = @error, $iExtended = @extended, $sExitCallback = "_exit", $iLine = @ScriptLineNumber)
; Parameters ....: $sMsg - The message to show in case of an error
; $bFatal - If True, the $sExitCallback will be called to exit the application gracefully
; $return - The value to be returned by this function
; $iError - The @error code
; $iExtended - The @extended code
; $sExitCallback - The function to call on exit
; $iLine - The ScriptLineNumber, where the error occurred
; Return values .: The value specified as $return and it will throw the same @error and @extended codes, the function was called with.
; Author ........: Kanashius
; ==================================================================================================
Func _errCheck($sMsg = Default, $bFatal = False, $return = -1, $iError = @error, $iExtended = @extended, $sExitCallback = "_exit", $iLine = @ScriptLineNumber)
$sMsg = $sMsg<>Default ? " >> "&$sMsg:""
Local $sExtended = $iExtended<>0 ? ":"&$iExtended:""
If $iError<>0 Then ConsoleWrite("Error (line "&$iLine&"): "&$iError&$sExtended&$sMsg&@crlf)
If $bFatal Then
Call($sExitCallback)
If @error Then _errCheck("Error using the ""Call"" function, while handling another error: "&@crlf&@Tab&"Error (line "&$iLine&"): "&$iError&$sExtended&$sMsg&@crlf& _
"Check if the function """&$sExitCallback&""" (used for $bFatal errors) exists and has no parameters!"&@crlf)
EndIf
Return SetError(@error, @extended, $return)
EndFunc
Alles anzeigen
Ich hoffe, ihr könnt das (gerade zum Debuggen) gut gebrauchen
Output:
----------------- String Output -----------------
Map[14] {
string "arr1D":
Array[4] [
int "1",
int "2",
int "3",
int "4"
],
string "arr2D":
Array[2][2] [
[
int "1",
int "2"
],
[
int "3",
int "4"
]
],
string "arr3D":
Array[2][2][2] [
[
[
int "1",
int "2"
],
[
int "3",
int "4"
]
],
[
[
int "5",
int "6"
],
[
int "7",
int "8"
]
]
],
string "binary":
binary "0x213234022331F20F",
string "bool":
bool "true",
string "dllStruct":
DllStruct[b140]{
int "-1",
int "255",
int "4294967295",
string "Hello",
},
string "func":
function "_TOSTRING",
string "float":
float "0.341234",
string "hwnd":
hwnd "0x00562EC4",
string "int":
int "3213",
string "objDictionary":
Object "Dictionary" Description: "Scripting.Dictionary" [2]{
string "1":
string "eins",
int "2":
string "zwei",
},
string "object":
Object "MediaPlayer" Description: "Windows Media Player",
string "pointer":
pointer "0x015FDDA0",
string "string":
string "Something",
}
----------------- Error Handling -----------------
Error (line 34): 1
Error (line 37): 1 >> Error using StringRegExp
Error (line 47): 1:5 >> Error to be forwarded
10
Error (line 42): 1 >> Fatal RegExp Error
Exit
Alles anzeigen