Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/Win/Windows Shell
Function:
Required plugins for this example: MBS Win Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/Windows Shell
This example is the version from Tue, 13th Mar 2017.
Project "Windows Shell.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control ApplicationName Inherits TextField
ControlInstance ApplicationName Inherits TextField
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control CommandLine Inherits TextField
ControlInstance CommandLine Inherits TextField
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
Control CurrentDirectory Inherits TextField
ControlInstance CurrentDirectory Inherits TextField
End Control
Control SelectFolderButton Inherits PushButton
ControlInstance SelectFolderButton Inherits PushButton
EventHandler Sub Action() dim f as FolderItem = SelectFolder if f <> nil then #if RBVersion < 2013 then CurrentDirectory.Text = f.AbsolutePath #else CurrentDirectory.Text = f.NativePath #endif end if End EventHandler
End Control
Control RunButton Inherits PushButton
ControlInstance RunButton Inherits PushButton
EventHandler Sub Action() ClearFields w = new MyWindowsProcessMBS w.ApplicationName = ApplicationName.Text // if empty, comes from comamnd line w.CommandLine = CommandLine.Text w.CurrentDirectory = CurrentDirectory.Text // can be empty if w.Run then ProcessID.Text = str(w.ProcessID) EndButton.Enabled = true WriteButton.Enabled = True else MsgBox "Error "+str(w.LastError)+EndOfLine+EndOfLine+w.LastErrorMessage end if End EventHandler
End Control
Control Label4 Inherits Label
ControlInstance Label4 Inherits Label
End Control
Control ProcessID Inherits Label
ControlInstance ProcessID Inherits Label
End Control
Control Log Inherits TextArea
ControlInstance Log Inherits TextArea
End Control
Control EndButton Inherits PushButton
ControlInstance EndButton Inherits PushButton
EventHandler Sub Action() if w.Terminate(1234) then // ok me.Enabled = false else MsgBox "Error "+str(w.LastError)+EndOfLine+EndOfLine+w.LastErrorMessage end if End EventHandler
End Control
Control Label5 Inherits Label
ControlInstance Label5 Inherits Label
End Control
Control InputField Inherits TextField
ControlInstance InputField Inherits TextField
End Control
Control WriteButton Inherits PushButton
ControlInstance WriteButton Inherits PushButton
EventHandler Sub Action() dim n as integer dim s as string = InputField.Text + EndOfLine.Windows n = w.Write(s) if n <> lenb(s) then MsgBox "Written "+str(n)+" of "+str(lenb(s))+" bytes." end if End EventHandler
End Control
Sub ClearFields() ProcessID.Text = "" log.Text = "" w = nil End Sub
Note "Example commands"
show directory: cmd /c dir launch notepad app: notepad produce output on error via invalid parameter, here invalid drive letter z: cmd /c dir z: use echo command in cmd: cmd /c echo Hello run time command and send empty input to exit app or use terminate button: cmd /c time
Property W As WindowsProcessMBS
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyWindowsProcessMBS Inherits WindowsProcessMBS
EventHandler Sub DataAvailable(AvailableBytesOutput as Integer, AvailableBytesError as Integer) if AvailableBytesOutput > 0 then log str(AvailableBytesOutput)+" Bytes available on output:" dim o as string = me.ReadOutput(AvailableBytesOutput) if o <> "" then 'dim f as FolderItem = SpecialFolder.Desktop.Child("output.txt") 'dim t as TextOutputStream = TextOutputStream.Append(f) 't.Write o o = FixEncoding(o) // you should know encoding of other app! log o end if end if if AvailableBytesError > 0 then log str(AvailableBytesError)+" Bytes available on error:" dim e as string = me.ReadError(AvailableBytesError) if e <> "" then e = FixEncoding(e) // you should know encoding of other app! log e end if end if End EventHandler
EventHandler Sub Terminated(ExitCode as Integer) log "Terminated with exit code "+str(ExitCode) End EventHandler
Function FixEncoding(e as string) As string if e.Encoding = nil then if encodings.UTF8.IsValidData(e) then e = DefineEncoding(e, encodings.UTF8) else e = DefineEncoding(e, encodings.DOSLatin1) // works for me with umlauts end if end if Return e End Function
Sub log(message as string) MainWindow.Log.AppendText message + EndOfLine + EndOfLine MainWindow.Log.ScrollPosition = 10000000 // to end End Sub
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Win Plugin.




Links
MBS FileMaker blog