Jump to content

[SOLVED] Creating a console


 Share

Recommended Posts

Hi guys

Firstly i apologise if this is a dumb question but its late and ive been wrecking my brain. Can anyone point me in the direction to creat an output console so th euser can see exactly whats goin on. I dont know if anyone remembers dvd decrypter but that had an output console that displayed the info on where the program was upto and what is was doing.

It just needs to be small but scrollable once completed.

Thanks

Jamie

Edited by engjcowi

Drunken Frat-Boy Monkey Garbage

Link to comment
Share on other sites

Hi enaiman

Thats for the suggestion. Ive tried creating a form and puttin in an edit box called $comconsole and then used the command

GUICtrlSetData($comconsole, "this has updated")
to update the information going to the edit box. My problem is that when i use the same command up to add further information such as using a command button it just overwrites whats already there.

is there anyway i can tell it to keep whats there and add to a new line only please?

Drunken Frat-Boy Monkey Garbage

Link to comment
Share on other sites

Try this - Untested:

GUICtrlSetData($comconsole, GUICtrlRead($comconsole) & "this has updated")

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Nice tip jaberwocky, I've never used the default value parameter so I had forgotten about how it works in an edit control.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Jaberwocky thanks very much i didnt see that myself lol. All is now right with thte world and working and ive included an example below in case anyone would like to see.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 658, 386, 302, 218)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form2Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form2Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form2Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form2Restore")
$Edit1 = GUICtrlCreateEdit("", 24, 48, 353, 217)
GUICtrlSetData(-1, "Edit1" & @CRLF)
GUICtrlSetOnEvent(-1, "Edit1Change")
$Button1 = GUICtrlCreateButton("Button1", 160, 304, 153, 41, 0)
GUICtrlSetOnEvent(-1, "Button1Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1

    Sleep(100)
WEnd

Func Button1Click()
GUICtrlSetData($edit1, "this has updated" & @CRLF, ' ')


EndFunc
Func Edit1Change()

EndFunc
Func Form2Close()
exit
EndFunc
Func Form2Maximize()

EndFunc
Func Form2Minimize()

EndFunc
Func Form2Restore()

EndFunc

Drunken Frat-Boy Monkey Garbage

Link to comment
Share on other sites

Hi

sorry to be a pain. Ive created the following program using the bits of code above to run mkisofs. Ther is 2 attempts below, 1 is readt to run, the other is blocked by #cs and #ce so just delete the other whilw wend loop then use the commented out 1 to try. The problem is that i use ctupdate in the directory which has lots of lists with long fielnames and after a very short period the the output just stops (see attached pic) but the program continues behind the scenes. If i remove the folder containing the files then it reads the percentage fine. Is there a limit to the information a edit box can contain?

Hope someone can help

Thanks

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 623, 451, 323, 153)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form2Close")

$Button1 = GUICtrlCreateButton("Exit", 176, 360, 265, 73, 0)
GUICtrlSetOnEvent(-1, "Button1Click")
$Comconsole = GUICtrlCreateEdit("Console", 56, 32, 529, 297, $ES_AUTOVSCROLL + $WS_VSCROLL)
GUICtrlSetData(-1, "Comconsole")
GUICtrlSetOnEvent(-1, "ComconsoleChange")
$Label1 = GUICtrlCreateLabel("ISO CREATION ", 264, 8, 83, 17)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

FileChangeDir(@ScriptDir & "\files\")


#cs
$pid = Run('mkisofs.exe -l -J -r -V "APHC" -o "' & @DesktopDir & '\APHC.iso" ' & '"' & @ScriptDir & '"', "", @SW_hide, 0x8) ; 0x8 = $STDERR_MERGED (StdOutRead receives Stdout and stderr)
$sOutput = ''
While 1

    Sleep(50)
    $sRead = StdoutRead($pid)
    If @error <> 0 Then ExitLoop
    $sOutput &= $sRead
    ;oolTip($sOutput)
    GUICtrlSetData($Comconsole, $sOutput, ' ')
WEnd
StdioClose($pid)
ToolTip("")
MsgBox(0, 'Finished', $sOutput)

#ce





$foo = Run('mkisofs.exe -l -J -r -V "APHC" -o"' & @DesktopDir & '\APHC.iso" ' & '"' & @ScriptDir & '"', "", @SW_Hide, $STDERR_CHILD + $STDOUT_CHILD)

While 1
    $line = StderrRead($foo)
    If @error Then ExitLoop
        $message = ""
    $message = $line
    GUICtrlSetData($Comconsole, $message, ' ')
Wend
MsgBox(0, 'ISO Created', $message)
StdioClose($line)





Func Button1Click()
ProcessClose("mkisofs.exe")
exit
EndFunc
Func ComconsoleChange()

EndFunc
Func Form2Close()
ProcessClose("mkisofs.exe")
exit
EndFunc

Drunken Frat-Boy Monkey Garbage

Link to comment
Share on other sites

@RichardRobertson

Why do you need a UDF? It's a single line. After you allocate it, you just use ConsoleWrite to send data to it.

So simple? - wow, I do need to have a closer look at that ;)

Thanks alot.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Hmm, I too was curious about this one-API-call-does-it-all, so I tested it out. But alas, it doesn't work with ConsoleWrite.

Here's the way I got it to work for me:

DllCall("kernel32.dll","bool","AllocConsole")
$hConsole=DllCall("kernel32.dll","handle","GetStdHandle","int",-11)
ConsoleWrite("Console handle:"&$hConsole[0]&", Error:"&@error&@CRLF)
$aRet=DllCall("kernel32.dll","bool","WriteConsoleW","handle",$hConsole[0],"wstr","Testing123","dword",10,"dword*",0,"ptr",0)
MsgBox(0,"see any consoles?","look harder!")

Note that WriteConsole must be called with a handle retrieved through GetStdHandle, and the program must not be run from SciTE (otherwise you won't get a valid handle).

Link to comment
Share on other sites

  • 8 years later...
On 10/25/2010 at 6:37 PM, Ascend4nt said:

 

DllCall("kernel32.dll","bool","AllocConsole")
$hConsole=DllCall("kernel32.dll","handle","GetStdHandle","int",-11)
ConsoleWrite("Console handle:"&$hConsole[0]&", Error:"&@error&@CRLF)
$aRet=DllCall("kernel32.dll","bool","WriteConsoleW","handle",$hConsole[0],"wstr","Testing123","dword",10,"dword*",0,"ptr",0)
MsgBox(0,"see any consoles?","look harder!")

 

Nice! Thank you. Cut, Paste, Done.

Except ...
How to know when (not) running running within SciTE, to know to (not) call this?

i.e. Make console output / debugging establishment fire and forget regardless of the environment of the time.
- permitting one to just ConsoleWrite "away" trusting it will always be displayed appropriately.

Link to comment
Share on other sites

Easy:

Global $CW = @Compiled ? _ConsoleWrite : ConsoleWrite

Func _ConsoleWrite(ByRef $s)
    Local Static $hCon = __ConsoleInit()
    DllCall("kernel32.dll", "bool", "WriteConsoleW", "handle", $hCon, "wstr", $s, "dword", StringLen($s), "dword*", 0, "ptr", 0)
    Return
EndFunc

Func __ConsoleInit()
    DllCall("kernel32.dll", "bool", "AllocConsole")
    Return DllCall("kernel32.dll", "handle", "GetStdHandle", "int", -11)
EndFunc

For $i = 1 to 10
    $cw($i & " - Hello world!" & @LF)
Next

Just invoke $CW($string_to_be_displayed) when needed.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...