KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

GUI Command Prompt

 
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive
View previous topic :: View next topic  
Author Message
krabourn
KiXforms Aficionado
KiXforms Aficionado


Joined: 05 Mar 2003
Posts: 273
Location: San Antonio. TX

PostPosted: Wed Apr 28, 2004 3:10 am    Post subject: GUI Command Prompt Reply with quote

I was testing button and keyboard response times and I made this little GUI command prompt program. I was asked to share it so here it is.

I know I learned a lot making this and I hope it helps others.

Here is my request, since I have not figured it out yet.
Make a System.NotifyIcon that can:
    OnClick launch seperate instance of GUI Command Prompt Form
    OnDoubleClick exit.

Code:
BREAK ON

$System = CreateObject("Kixtart.System")

$frmCommandLine = fnCreateCommandLine()
$frmCommandLine.pnlPanel.txtCommandLineCommand.SetFocus
$frmCommandLine.Show
WHILE $frmCommandLine.Visible
   $Nul = Execute($System.Application.DoEvents(0))
LOOP

QUIT 1

FUNCTION fnCreateCommandLine()
   $frmForm = $System.Form()
   $frmForm.Text = "GUI Command Prompt"
   $frmForm.ClientSize = 580, 500
   $frmForm.MinimumSize = 375, 150
   $frmForm.Center
   $frmForm.FormBorderStyle = "Sizable"
   $frmForm.ImageList = $System.BuiltinImageList
   $frmForm.Icon = "%systemroot%\system32\cmd.exe;0"

   $frmForm.pnlPanel = $frmForm.Panel()
   $frmForm.pnlPanel.ClientSize = 580, 500
   $frmForm.pnlPanel.Center
   $frmForm.pnlPanel.Anchor = "All"

   $frmForm.pnlPanel.txtCommandLineCommand = $frmForm.pnlPanel.TextBox()
   $frmForm.pnlPanel.txtCommandLineCommand.Location = 5, 5
   $frmForm.pnlPanel.txtCommandLineCommand.Size = $frmForm.pnlPanel.ClientWidth - 10, 20
   $frmForm.pnlPanel.txtCommandLineCommand.Anchor = "TopLeftRight"

   $frmForm.pnlPanel.btnStop = $frmForm.pnlPanel.Button()
   $frmForm.pnlPanel.btnStop.Text = "Stop"
   $frmForm.pnlPanel.btnStop.Size = 60, 20
   $frmForm.pnlPanel.btnStop.Location = 5, $frmForm.pnlPanel.txtCommandLineCommand.Bottom + 5
   $frmForm.pnlPanel.btnStop.Anchor = "TopLeft"
   $frmForm.pnlPanel.btnStop.OnClick = "$$SwitchStopProgress = 1"
   $frmForm.pnlPanel.btnStop.Enabled = 0

   $frmForm.pnlPanel.btnDoCommand = $frmForm.pnlPanel.Button()
   $frmForm.pnlPanel.btnDoCommand.Text = "Execute"
   $frmForm.pnlPanel.btnDoCommand.Size = 60, 20
   $frmForm.pnlPanel.btnDoCommand.Location = $frmForm.pnlPanel.btnStop.Right + 5, $frmForm.pnlPanel.btnStop.Top
   $frmForm.pnlPanel.btnDoCommand.Anchor = "TopLeft"
   $frmForm.pnlPanel.btnDoCommand.Default = 1
   $frmForm.pnlPanel.btnDoCommand.OnClick = "fnCommandLineRunning($$System.ActiveForm) fnbtnDoCommandOnClick($$System.ActiveForm.pnlPanel.txtCommandLineCommand, $$System.ActiveForm.pnlPanel.rtbCommandLineOutput) fnCommandLineRunning($$System.ActiveForm)"

   $frmForm.pnlPanel.btnCommandLineOutputClear = $frmForm.pnlPanel.Button()
   $frmForm.pnlPanel.btnCommandLineOutputClear.Text = "Clear"
   $frmForm.pnlPanel.btnCommandLineOutputClear.Size = 60, 20
   $frmForm.pnlPanel.btnCommandLineOutputClear.Location = $frmForm.pnlPanel.btnDoCommand.Right + 5, $frmForm.pnlPanel.btnStop.Top
   $frmForm.pnlPanel.btnCommandLineOutputClear.Anchor = "TopLeft"
   $frmForm.pnlPanel.btnCommandLineOutputClear.OnClick = "fnbtnCommandLineOutputClearOnClick($$System.ActiveForm.pnlPanel.rtbCommandLineOutput, $$System.ActiveForm.pnlPanel.txtCommandLineCommand)"

   $frmForm.pnlPanel.btnExit = $frmForm.pnlPanel.Button()
   $frmForm.pnlPanel.btnExit.Text = "Exit"
   $frmForm.pnlPanel.btnExit.Size = 60, 20
   $frmForm.pnlPanel.btnExit.Location = $frmForm.pnlPanel.btnCommandLineOutputClear.Right + 5, $frmForm.pnlPanel.btnStop.Top
   $frmForm.pnlPanel.btnExit.Anchor = "TopLeft"
   $frmForm.pnlPanel.btnExit.OnClick = "fnbtnExitOnClick($$System.ActiveForm)"

   $frmForm.pnlPanel.lblStop = $frmForm.pnlPanel.Label()
   $frmForm.pnlPanel.lblStop.Text = "Control-C will break."
   $frmForm.pnlPanel.lblStop.Size = 200, 20
   $frmForm.pnlPanel.lblStop.Location = $frmForm.pnlPanel.btnExit.Right + 5, $frmForm.pnlPanel.btnStop.Top
   $frmForm.pnlPanel.lblStop.Anchor = "TopLeft"

   $frmForm.pnlPanel.rtbCommandLineOutput = $frmForm.pnlPanel.RichTextBox()
;   $frmForm.pnlPanel.rtbCommandLineOutput.ForeColor = "White"
;   $frmForm.pnlPanel.rtbCommandLineOutput.BackColor = "Black"
   $frmForm.pnlPanel.rtbCommandLineOutput.Location = 5, $frmForm.pnlPanel.btnStop.Bottom + 5
   $frmForm.pnlPanel.rtbCommandLineOutput.Size = $frmForm.pnlPanel.ClientWidth - 10, $frmForm.pnlPanel.ClientHeight - $frmForm.pnlPanel.btnStop.Bottom - 10
   $frmForm.pnlPanel.rtbCommandLineOutput.Font = $System.Font("Lucida Console", 10)
   $frmForm.pnlPanel.rtbCommandLineOutput.Anchor = "All"
   $frmForm.pnlPanel.rtbCommandLineOutput.ScrollBars = $System.ScrollBars.Vertical
   $frmForm.pnlPanel.rtbCommandLineOutput.MaxLength = 0
   $frmForm.pnlPanel.rtbCommandLineOutput.ReadOnly = 1
   $frmForm.pnlPanel.rtbCommandLineOutput.OnKeyDown = "fnrtbCommandLineOutputOnKeyDown()"
   $frmForm.pnlPanel.rtbCommandLineOutput.SelectedText = ">"

   $fnCreateCommandLine = $frmForm
   $frmForm = ""
ENDFUNCTION

FUNCTION fnbtnDoCommandOnClick($Command, $Output)
   DIM $WshShell, $oExec, $LineIn
   SELECT
      CASE UCase($Command.Text) = "CLS"
         fnbtnCommandLineOutputClearOnClick($Output, $Command)
      CASE UCase($Command.Text) = "EXIT"
         fnbtnExitOnClick($System.ActiveForm)
      CASE $Command.Text <> ""
         $Output.SetFocus
         $Output.SelectionStart = Len($Output.Text)
         $Output.SelectionLength = 0
         $Output.SelectedText = $Command.Text + @CRLF + @CRLF
         $SwitchStopProgress = 0
         $WshShell = CreateObject("WScript.Shell")
         $oExec = $WshShell.Exec("%Comspec% /e:1024 /C " + $Command.Text)
         WHILE (NOT $oExec.StdOut.AtEndOfStream) AND $SwitchStopProgress = 0
            $Nul = Execute($System.Application.DoEvents(0))
             $LineIn = $oExec.StdOut.ReadLine
            IF InStr($LineIn, Chr(13))
               $Output.SelectedText = $LineIn
            ELSE
               $Output.SelectedText = $LineIn + @CRLF
            ENDIF
         LOOP
         $oExec = 0
         $WshShell = 0
         $Output.SelectedText = @CRLF + ">"
         $Output.SetFocus
         $Output.SelectionStart = Len($Output.Text)
         $Output.ScrollToCaret()
         $Command.SetFocus
   ENDSELECT
ENDFUNCTION

FUNCTION fnbtnCommandLineOutputClearOnClick($CommandLineOutput, $CommandLineInput)
   $CommandLineOutput.Text = ""
   $CommandLineOutput.SelectedText = ">"
   $CommandLineInput.SetFocus
ENDFUNCTION

FUNCTION fnbtnExitOnClick($frmForm)
   $frmForm.Hide
ENDFUNCTION

FUNCTION fnrtbCommandLineOutputOnKeyDown()
   IF $System.ActiveForm.pnlPanel.rtbCommandLineOutput.KeyState(17) AND $System.ActiveForm.pnlPanel.rtbCommandLineOutput.KeyCode = 67
      $SwitchStopProgress = 1
   ENDIF
ENDFUNCTION

FUNCTION fnCommandLineRunning($frmForm)
   IF $frmForm.pnlPanel.btnStop.Enabled = 0
      $frmForm.pnlPanel.btnStop.Enabled = 1
      $frmForm.pnlPanel.btnCommandLineOutputClear.Enabled = 0
      $frmForm.pnlPanel.btnExit.Enabled = 0
      $frmForm.pnlPanel.btnDoCommand.Enabled = 0
   ELSE
      $frmForm.pnlPanel.btnStop.Enabled = 0
      $frmForm.pnlPanel.btnCommandLineOutputClear.Enabled = 1
      $frmForm.pnlPanel.btnExit.Enabled = 1
      $frmForm.pnlPanel.btnDoCommand.Enabled = 1
   ENDIF
ENDFUNCTION

_________________
Kelly
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Sat Aug 21, 2004 11:48 pm    Post subject: Reply with quote

suits you sir?
_________________
Hammer
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group