• Ich hab mich mal an eine UDF gesetzt, die mehr Funktionen für die AutoIT-Konsole hinzufügt. Die Konsole und damit die Funktionen kann man nur benutzen, wenn die Skripte mit Konsole kompiliert sind (SciTE-Console geht nicht).

    Mit den Funktionen kann man die Größe der Konsole, Schrift und Hintergrundfarbe und Titel ändern, den Cursor an eine andere Stelle setzen und die Konsole minimieren, maximieren, etc.

    Im Anhang hab ich die UDF und ein Beispiel.


    UDF:

    Spoiler anzeigen
    [autoit]

    #include-once

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

    ; #INDEX# =======================================================================================================================
    ; Title .........: Console-UDF
    ; AutoIt Version : 3.3.6.0
    ; Language ......: English
    ; Description ...: Constants and Functions for the AutoIT-console
    ; Author(s) .....: Gunnar (Marthog)
    ; ===============================================================================================================================

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

    ; #CURRENT# ====================================================================
    ;_ConsoleGetFontSize
    ;_ConsoleGetHandle
    ;_ConsoleGetHWND
    ;_ConsoleSetColor
    ;_ConsoleSetCursor
    ;_ConsoleSetFontSize
    ;_ConsoleSetSize
    ;_ConsoleSetState
    ;_ConsoleSetTitle
    ; ==============================================================================

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

    ; #CONSTANTS# ==================================================================
    ; Colors:
    Global Enum _
    $_CONSOLE_BLACK, _
    $_CONSOLE_BLUE, _
    $_CONSOLE_GREEN, _
    $_CONSOLE_CYAN, _
    $_CONSOLE_RED, _
    $_CONSOLE_MAGENTA, _
    $_CONSOLE_BROWN, _
    $_CONSOLE_LIGHTGREY, _
    $_CONSOLE_DARKGREY, _
    $_CONSOLE_LIGHTBLUE, _
    $_CONSOLE_LIGHTGREEN, _
    $_CONSOLE_LIGHTCYAN, _
    $_CONSOLE_LIGHTRED, _
    $_CONSOLE_LIGHTMAGENTA, _
    $_CONSOLE_YELLOW, _
    $_CONSOLE_WHITE

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

    ; #FUNCTION# ======================================================================================
    ; Name ..........: _ConsoleGetFontSize()
    ; Description ...: Gets the size of the font
    ; Syntax ........: _ConsoleGetFontSize([$maximumwindow=False])
    ; Parameters ....: $maximumwindow - [optional] If this parameter is TRUE, font information is retrieved for the maximum window size. If this parameter is FALSE, font information is retrieved for the current window size. (default:False)
    ; Return values .: Success - returns an array with the height and width of the font
    ; Failure - returns 0 is an error occures or [0, 0] if the application has no console
    ; Author ........: Gunnar
    ; Modified ......:
    ; Remarks .......: valid font-sizes are: 4x6, 6x8, 8x8, 16x8, 5x12, 7x12, 8x12, 16x12, 12x16, 10x18
    ; Related .......: _ConsoleSetFontSize
    ; Link ..........: http://msdn.microsoft.com/en-us/library/ms683176(VS.85).aspx
    ; =================================================================================================

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

    Func _ConsoleGetFontSize($maximumwindow=False) ; 4x6 6x8 8x8 16x8 5x12 7x12 8x12 16x12 12x16 10x18

    Local $console = DllCall("Kernel32.dll", "BOOL", "GetStdHandle", "DWORD", 4294967285)
    If @error Then Return 0

    Local $struct = DllStructCreate("DWORD nFont; SHORT X; SHORT Y;")

    Local $var=DllCall("Kernel32.dll", "BOOL", "GetCurrentConsoleFont", "HANDLE", $console[0], "BOOL", $maximumwindow, "Ptr", DllStructGetPtr($struct))
    If @error Then Return 0

    Local $result[2] = [ DllStructGetData($struct, "X"), DllStructGetData($struct, "Y")]
    Return $result
    EndFunc

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

    ; #FUNCTION# ======================================================================================
    ; Name ..........: _ConsoleGetHandle()
    ; Description ...: returns the handle of the console, it can be used in DLL-calls with the type "HANDLE"
    ; Syntax ........: _ConsoleGetHandle()
    ; Return values .: Success - return the handle
    ; Failure - returns 0
    ; Author ........: Gunnar
    ; Remarks .......: It does not return the handle of the window (HWND)
    ; Link ..........: http://msdn.microsoft.com/en-us/library/…1(v=VS.85).aspx
    ; =================================================================================================

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

    Func _ConsoleGetHandle()
    Local $var = DllCall("Kernel32.dll", "HANDLE", "GetStdHandle", "DWORD", 4294967285)
    If @error Then Return 0
    Return $var[0]
    EndFunc

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

    ; #FUNCTION# ======================================================================================
    ; Name ..........: _ConsoleGetHWND()
    ; Description ...: Returns the handle of the consolewindow (HWND)
    ; Syntax ........: _ConsoleGetHWND()
    ; Return values .: Success - returns the handle
    ; Failure - returns 0
    ; Author ........: Gunnar
    ; Link ..........: http://msdn.microsoft.com/en-us/library/ms683175(VS.85).aspx
    ; =================================================================================================

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

    Func _ConsoleGetHWND()
    Local $var = DllCall("Kernel32.dll", "HWND", "GetConsoleWindow")
    If @error Then Return 0
    Return $var[0]
    EndFunc

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

    ; #FUNCTION# ======================================================================================
    ; Name ..........: _ConsoleSetColor()
    ; Description ...: Description
    ; Syntax ........: _ConsoleSetColor([$fontcolor=$_CONSOLE_LIGHTGREY[, $backgroundcolor=$_CONSOLE_BLACK]])
    ; Return values .: Success - returns 1
    ; Failure - returns 0
    ; Author ........: Gunnar
    ; Remarks .......: There are only 16 different colors (0 to 15). You can use the constants (_$CONSOLE_WHITE, _$CONSOLE_DARKRED, etc)
    ; Link ..........: http://msdn.microsoft.com/en-us/library/ms686047(VS.85).aspx
    ; =================================================================================================

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

    Func _ConsoleSetColor($fontcolor=$_CONSOLE_LIGHTGREY, $backgroundcolor=$_CONSOLE_BLACK)
    Local $console = DllCall("Kernel32.dll", "HANDLE", "GetStdHandle", "DWORD", 4294967285)
    If @error Then Return 0

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


    DllCall("Kernel32.dll", "BOOL", "SetConsoleTextAttribute", "HANDLE", $console[0], "WORD", BitOR(BitShift($backgroundcolor, -4), $fontcolor))
    If @error Then Return 0
    Return 1
    EndFunc

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

    ; #FUNCTION# ======================================================================================
    ; Name ..........: _ConsoleSetCursor()
    ; Description ...: Sets the cursor to the position
    ; Syntax ........: _ConsoleSetCursor($X, $Y)
    ; Return values .: Success - Returns not 0
    ; Failure - Returns 0
    ; Author ........: Gunnar
    ; Link ..........: http://msdn.microsoft.com/en-us/library/ms686025(VS.85).aspx
    ; =================================================================================================

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

    Func _ConsoleSetCursor($X, $Y)
    Local $console = DllCall("Kernel32.dll", "BOOL", "GetStdHandle", "DWORD", 4294967285)
    If @error Then Return 0

    Local $var=DllCall("Kernel32.dll", "BOOL", "SetConsoleCursorPosition", "HANDLE", $console[0], "INT", BitOR(BitShift($X, -16), $Y))
    If @error Then Return 0
    Return $var[0]
    EndFunc

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

    ; #FUNCTION# ======================================================================================
    ; Name ..........: _ConsoleSetFontSize()
    ; Description ...: Changes the font-size of the whole console
    ; Syntax ........: _ConsoleSetFontSize($X, $Y[, $maximumwindow=False])
    ; Return values .: Success - returns 1
    ; Failure - returns 0
    ; Author ........: Gunnar
    ; Remarks .......: valid font-sizes are: 4x6, 6x8, 8x8, 16x8, 5x12, 7x12, 8x12, 16x12, 12x16, 10x18
    ; Related .......: _ConsoleGetFontSize
    ; Link ..........: http://msdn.microsoft.com/en-us/library/ms686200(VS.85).aspx
    ; =================================================================================================

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

    Func _ConsoleSetFontSize($X, $Y, $maximumwindow=False) ; 4x6 6x8 8x8 16x8 5x12 7x12 8x12 16x12 12x16 10x18

    Local $console = DllCall("Kernel32.dll", "HANDLE", "GetStdHandle", "DWORD", 4294967285)
    If @error Then Return 0

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

    Local $lpConsoleCurrentFontEx = DllStructCreate("ULONG cbSize; DWORD nFont; SHORT X; SHORT Y; UINT FontFamily; UINT FontWeight; WCHAR FaceName[32]")
    DllStructSetData($lpConsoleCurrentFontEx, "cbSize", 84)
    DllStructSetData($lpConsoleCurrentFontEx, "nFont", 1)
    DllStructSetData($lpConsoleCurrentFontEx, "X", $X)
    DllStructSetData($lpConsoleCurrentFontEx, "Y", $Y)
    DllStructSetData($lpConsoleCurrentFontEx, "FontFamily", 48)
    DllStructSetData($lpConsoleCurrentFontEx, "FontWeeight", 700)

    DllCall("Kernel32.dll", "BOOL", "SetCurrentConsoleFontEx", "HANDLE", $console[0], "BOOL", False, "ptr", DllStructGetPtr($lpConsoleCurrentFontEx))
    If @error Then Return 0
    Return 1
    EndFunc

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

    ; #FUNCTION# ======================================================================================
    ; Name ..........: _ConsoleSetSize()
    ; Description ...: Sets the width, height and the positon of the scrollbars
    ; Syntax ........: _ConsoleSetSize([$width=79[, $heigth=24[, $X=0[, $Y=0]]]])
    ; Author ........: Gunnar
    ; Link ..........: http://msdn.microsoft.com/en-us/library/ms686125(VS.85).aspx
    ; =================================================================================================

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

    Func _ConsoleSetSize($width=79, $heigth=24, $X=0, $Y=0) ; bei mir: Breite max. 79, Höhe max. 85, sonst bleibt alles so
    Local $console = DllCall("Kernel32.dll", "HANDLE", "GetStdHandle", "DWORD", 4294967285)
    If @error Then Return 0

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

    Local $_SMALL_RECT=DllStructCreate("SHORT Left; SHORT Top; SHORT Right; SHORT Bottom")
    DllStructSetData($_SMALL_RECT, "Left", $X)
    DllStructSetData($_SMALL_RECT, "Top", $Y)
    DllStructSetData($_SMALL_RECT, "Right", $width+$X)
    DllStructSetData($_SMALL_RECT, "Bottom", $heigth+$Y)


    DllCall("Kernel32.dll", "BOOL", "SetConsoleWindowInfo", "HANDLE", $console[0], "BOOL", True, "Ptr", DllStructGetPtr($_SMALL_RECT))
    If @error Then Return 0
    EndFunc

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

    ; #FUNCTION# ======================================================================================
    ; Name ..........: _ConsoleSetState()
    ; Description ...: It is GUISetState() for the consolewindow
    ; Syntax ........: _ConsoleSetState($state)
    ; Author ........: Gunnar
    ; Related .......: GUISetState($flag, $winhandle)
    ; Link ..........: http://msdn.microsoft.com/en-us/library/ms633548(VS.85).aspx
    ; =================================================================================================

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

    Func _ConsoleSetState($state) ; Wie GUISetState
    DllCall("User32.dll", "BOOL", "ShowWindow", "HWND", _ConsoleGetHWND(), "int", $state)
    If @error Then Return 0
    EndFunc

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

    ; #FUNCTION# ======================================================================================
    ; Name ..........: _ConsoleSetTitle()
    ; Description ...: Changes the title of the consolewindow
    ; Syntax ........: _ConsoleSetTitle($title)
    ; Author ........: Gunnar
    ; Link ..........: http://msdn.microsoft.com/en-us/library/ms686050(VS.85).aspx
    ; =================================================================================================

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

    Func _ConsoleSetTitle($title)
    DllCall("Kernel32.dll", "BOOL", "SetConsoleTitleW", "wstr",$title)
    Return @error
    EndFunc

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

    Beispiel:

    Spoiler anzeigen
    [autoit]

    #include "Console.au3"

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

    ConsoleWrite("Test1"&@crlf)
    MsgBox(0, "", "Konsole ausblenden:")
    _ConsoleSetState(@SW_HIDE)
    MsgBox(0, "", "Konsole wieder anzeigen:")
    _ConsoleSetState(@SW_SHOW)
    MsgBox(0, "", "Textfarbe ändern:")
    _ConsoleSetColor($_CONSOLE_BLUE, $_CONSOLE_YELLOW)
    ConsoleWrite("Test2"&@crlf)
    MsgBox(0, "", "Textfarbe zurücksetzen:")
    _ConsoleSetColor()
    ConsoleWrite("Test3"&@crlf)
    MsgBox(0, "", "Titel ändern:")
    _ConsoleSetTitle("Hallo")
    MsgBox(0, "", "Größe ändern und scrollen:")
    _ConsoleSetSize(20, 40, 2, 1)
    MsgBox(0, "", "Minimieren:")
    _ConsoleSetState(@SW_MINIMIZE)
    MsgBox(0, "", "Maximieren:")
    _ConsoleSetState(@SW_MAXIMIZE)
    MsgBox(0, "", "Schritgröße ändern:")
    _ConsoleSetFontSize(12, 16)
    MsgBox(0, "", "Cursor setzen:")
    _ConsoleSetCursor(10, 5)
    ConsoleWrite("Test4"&@CRLF)
    MsgBox(0, "", "ENDE!")

    [/autoit]

    Screenshots:

    Spoiler anzeigen

    [Blockierte Grafik: http://home.arcor.de/rber/gunnar/pictures/AutoIT-Console.jpg]

    Die nächsten sind nicht von mir, gehen aber auch damit:
    [Blockierte Grafik: http://www.adrianxw.dk/SoftwareSite/Consoles/Colour3.jpg][Blockierte Grafik: http://www.adrianxw.dk/SoftwareSite/Consoles/Colour4.jpg]

  • funktioniert bei mir leider nicht .. die KonsolenGUI wird nicht angezeigt ... auch nicht wenn ich es compile und dann starte ..

    Windows 7 64 Bit - Home Premium

    und habs auch mal als 32 bit ausgeführt aber geht leida nicht

  • Eine der Gründe warum ich AutoIt liebe :love:
    Es gibt für alles eine Udf :thumbup:
    Oder zwei :thumbup: :thumbup:
    Dann kann man sich ja die raussuchen die besser zu dem passt was man machen will. ;)

    mfg Ubuntu