Welcome to Foxite.COM Community Weblog Sign in | Join | Help
<July 2006>
SuMoTuWeThFrSa
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

Navigation

Syndication




Distributable Command Window

Adel Gharib has submit a tip of the month in Advisor Guide to Visual FoxPro July 2006 issue to create a distributable command window which can be embedded into a compiled VFP exe.  I have worked on Adel's tip and package the code into a class (commandprompt of sysadmin.vcx).

I use the ACCEPT command instead of the INPUTBOX command suggested by Ceil because it acts more like a command window that way.  And a form is used as the input/output service. 

To open the command prompt window, run the following code in the VFP command window or through a menu pad or in a mouse click event handler:

   ox = newobject('commandprompt','sysadmin')

Here is a screenshot of it in action.

Click here to download the VCX and below is the source code of it:

DEFINE CLASS commandprompt AS form

 Height = 250
 Width = 467
 ShowWindow = 2
 DoCreate = .T.
 AutoCenter = .T.
 Caption = "Command Prompt"
 FontName = "Courier New"
 FontSize = 10
 BackColor = RGB(255,255,255)
 Name = "commandprompt"

 *-- Start the command prompt.
 PROCEDURE start
  #define EXIT_TOKEN 'quit'

  LOCAL lcPrompt, lcCmd
  LOCAL loEx as Exception

  this.Caption = "Type '" + EXIT_TOKEN + "' to finish"
  this.Show
  ? version()
  ? os(1) + " " + os(7) + " " + sys(17) + " " + strtran(sys(0)," #","")

  DO WHILE .t.
     lcPrompt = SYS(5)+SYS(2003) + IIF(EMPTY(ALIAS()),""," (" + ALIAS() + ")") + " > "
     accept lcPrompt to lcCmd
     IF ALLTRIM(LOWER(lcCmd)) == EXIT_TOKEN
        EXIT
     ELSE
        TRY
           EXECSCRIPT(lcCmd)
        CATCH TO loEx
           MESSAGEBOX(loEx.Message,0, "Error " +tran(loEx.ErrorNo))
        ENDTRY
     ENDIF
  ENDDO
 ENDPROC

 PROCEDURE Init
  this.Show
  this.start
  return .f.
 ENDPROC

ENDDEFINE


 

Published Sunday, July 30, 2006 1:13 AM by davidfung

Comments

Anonymous comments are disabled
Powered by Community Server, by Telligent Systems