WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Console Front End

Keywords:
Console Dialog StdOut Cmd msctls_progress32 

; Run a command line with progress bar and return results in dialog
; Les Ferch, 2008-02-18

; ----------------------------------------------------------------------------------------------
IntControl(1002,0,0,0,0) ; No Icon
IntControl(1003,0,0,0,0) ; No WinBatch Processing Window
IntControl(12,5,0,0,0) ; Terminate silently
ThisScript = IntControl(1004,0,0,0,0)
Title = "Console Front-End:"
Title2 = "Executing Command:"
Temp = Environment("Temp")
T0 = Temp:"\TmpTxt0.txt"
T1 = Temp:"\TmpTxt1.txt"
T2 = Temp:"\TmpTxt2.txt"
Percent = 0

; ----------------------------------------------------------------------------------------------
#DefineFunction CreateProgress(Title,solid,vertical,startx,starty,width,height)
hwnd = DllHwnd(Title)
hinst = DllHinst(Title)
u32 = DirWindows(1):"user32.dll"
hprog = DllCall(u32,long:"CreateWindowExA",long:0,lpstr:"msctls_progress32",lpstr:"",long:vertical | solid | 268435456 | 1073741824,long:startx,long:starty,long:width,long:height,long:hwnd,long:0,long:hinst,long:0)
Return hprog
#EndFunction

; ----------------------------------------------------------------------------------------------
#DefineFunction CleanText(Str)
Str = StrReplace(Str,@CR:@CR,@CR)
Str = StrReplace(Str,@CR:@CR,@CR)
Str = StrReplace(Str,@CR,@CRLF)
Str = StrReplace(Str,@LF:@LF,@LF)
While StrIndex(Str," ":@CR,1,@FWDSCAN)>0
   Str = StrReplace(Str," ":@CR,@CR)
EndWhile
Return Str
#EndFunction

; ----------------------------------------------------------------------------------------------
Cmd = ""
If Param0>0 Then Cmd = StrLower(Param1)
Switch 1
Case Cmd==""
   If WinExist(Title) Then Exit
   BoxTitle(Title)
   InProgress = 0
   CmdList = ""
   CmdListRegVal = "Software\ConsoleFrontEnd[CmdList]"
   If RegExistValue(@REGCURRENT,CmdListRegVal) Then CmdList = RegQueryValue(@REGCURRENT,CmdListRegVal)
   Break
Case Cmd<>""
   BoxTitle(Title2)
   Cmd = StrReplace(Cmd,"`","")
   Hide = ""
   If Param0>1 Then Hide = "Hide"
   Run%Hide%Wait(Environment("comspec"),"/c ":Cmd:'>"':T2:'" ':'2>"':T1:'"')
   TmpTxt1 = FileGet(T1)
   TmpTxt2 = FileGet(T2)
   TmpTxt1 = CleanText(TmpTxt1)
   TmpTxt2 = CleanText(TmpTxt2)
   FilePut(T0,TmpTxt1:@CRLF:TmpTxt2)
   Exit
EndSwitch

; ----------------------------------------------------------------------------------------------
#DefineSubRoutine Main(Proc_Handle,Proc_Message,Proc_ID,Proc_EventInfo,reserved)
MSG_INIT = 0
MSG_BUTTONPUSHED = 2
MSG_TIMER = 1
Switch Proc_Message
Case MSG_INIT
   DialogProcOptions(Proc_Handle,MSG_BUTTONPUSHED,1)
   DialogProcOptions(Proc_Handle,MSG_TIMER,250)
   Return(-1)
   Break
Case MSG_BUTTONPUSHED
   If Proc_ID==3
      FileDelete(T0)
      FileDelete(T1)
      FileDelete(T2)
      Cmd = DialogControlGet(Proc_Handle,006,6) ; Get command line from dialog
      HideCmd = DialogControlGet(Proc_Handle,007,1) ; Get hidden option from dialog
      Hide = ""
      If HideCmd Then Hide = "Hide"
      If Cmd<>""
         InProgress = 1
         Percent = 0
         DialogControlState(Proc_Handle,005,4,1) ; Unhide Execute message
         DialogControlState(Proc_Handle,001,3,2) ; Disable OK button
         DialogControlState(Proc_Handle,003,3,2) ; Disable Execute button
         DialogControlSet(Proc_Handle,004,3,"") ; Clear contents of multiline
         hprog = CreateProgress(Title,0,0,26,70,436,15)
         Run(ThisScript,"`":Cmd:"` ":Hide)
      EndIf
      Return(-2)  ; Keep the dialog on screen...
   EndIf
   Break
Case MSG_TIMER
   If InProgress
      If Percent==100 Then Percent = 0
      If IsDefined(hprog) Then SendMessageA(hprog,1026,Percent,0)
      Percent = Percent + 1
   EndIf
   If FileExist(T0)
      T3 = FileGet(T0)
      DialogControlSet(Proc_Handle,004,3,T3) ; Put contents of file into multiline
      DialogControlSet(Proc_Handle,004,10,1) ; Scroll multiline back to the top
      InProgress = 0
      FileDelete(T0)
      If IsDefined(hprog) Then SendMessageA(hprog,1026,100,0)
      DialogControlState(Proc_Handle,005,3,1) ; Hide Execute message
      DialogControlState(Proc_Handle,001,4,2) ; Enable OK button
      DialogControlState(Proc_Handle,003,4,2) ; Enable Execute button
      ClipPut(T3)
      Output = ""
      If FileExist(T2) Then Output = StrTrim(FileGet(T2))
      If Output<>"" && ItemLocate(StrLower(Cmd),StrLower(CmdList),@TAB)==0 ; Save command
         CmdList = StrTrim(CmdList:@TAB:Cmd)
         While ItemCount(CmdList,@TAB)>30 ; Keep only last 30 commands
            CmdList = ItemRemove(1,CmdList,@TAB)
         EndWhile
         RegSetValue(@REGCURRENT,CmdListRegVal,CmdList)
         DialogControlSet(Proc_Handle,006,5,CmdList) ; Update command list in dialog
         DialogControlSet(Proc_Handle,006,6,Cmd) ; Reset selected command in dialog
         SendKeysTo(Title,"{END}") ; Move cursor to end of command
      EndIf
   EndIf
   Break
EndSwitch
Return(-1)
#EndSubRoutine

; ----------------------------------------------------------------------------------------------
MyDialogFormat = `WWWDLGED,6.1`

MyDialogCaption = Title
MyDialogX = -01
MyDialogY = -01
MyDialogWidth = 246
MyDialogHeight = 293
MyDialogNumControls = 007
MyDialogProcedure = `Main`
MyDialogFont = `DEFAULT`
MyDialogTextColor = `DEFAULT`
MyDialogBackground = `DEFAULT,DEFAULT`
MyDialogConfig = 0

MyDialog001 = `013,269,036,012,PUSHBUTTON,DEFAULT,"OK",1,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog002 = `195,269,036,012,PUSHBUTTON,DEFAULT,"Cancel",0,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003 = `013,005,030,012,PUSHBUTTON,DEFAULT,"Execute:",2,5,32,DEFAULT,DEFAULT,DEFAULT`
MyDialog004 = `013,045,218,210,MULTILINEBOX,Data,"",DEFAULT,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog005 = `013,025,056,010,STATICTEXT,DEFAULT,"Executing...",DEFAULT,1,1,DEFAULT,DEFAULT,DEFAULT`
MyDialog006 = `050,005,180,260,DROPLISTBOX,CmdList,DEFAULT,DEFAULT,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog007 = `050,018,050,012,CHECKBOX,HideCmd,"Run Hidden",1,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed = Dialog("MyDialog")

:CANCEL
While WinExist(Title2)
   TerminateApp(Title2,0,0)
EndWhile
Exit

Article ID:   W18239
Filename:   Console Front End.txt
File Created: 2010:05:21:07:54:52
Last Updated: 2010:05:21:07:54:52