Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/Util/Process/Process Example
Function:
Required plugins for this example: MBS MacOSX Plugin, MBS Picture Plugin, MBS Util Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Util/Process/Process Example
This example is the version from Mon, 24th Nov 2013.
Project "Process Example.rbp"
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() process.getcurrentProcess update End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() process.getfrontProcess update End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action() process.GetfirstProcess update End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End Control
Control StaticText5 Inherits Label
ControlInstance StaticText5 Inherits Label
End Control
Control processname Inherits Label
ControlInstance processname Inherits Label
End Control
Control processvisible Inherits Label
ControlInstance processvisible Inherits Label
End Control
Control processfront Inherits Label
ControlInstance processfront Inherits Label
End Control
Control processcurrent Inherits Label
ControlInstance processcurrent Inherits Label
End Control
Control processpath Inherits Label
ControlInstance processpath Inherits Label
End Control
Control StaticText6 Inherits Label
ControlInstance StaticText6 Inherits Label
End Control
Control StaticText7 Inherits Label
ControlInstance StaticText7 Inherits Label
End Control
Control StaticText10 Inherits Label
ControlInstance StaticText10 Inherits Label
End Control
Control StaticText11 Inherits Label
ControlInstance StaticText11 Inherits Label
End Control
Control StaticText12 Inherits Label
ControlInstance StaticText12 Inherits Label
End Control
Control processtype Inherits Label
ControlInstance processtype Inherits Label
End Control
Control StaticText8 Inherits Label
ControlInstance StaticText8 Inherits Label
End Control
Control processcreator Inherits Label
ControlInstance processcreator Inherits Label
End Control
Control StaticText9 Inherits Label
ControlInstance StaticText9 Inherits Label
End Control
Control processfree Inherits Label
ControlInstance processfree Inherits Label
End Control
Control processsize Inherits Label
ControlInstance processsize Inherits Label
End Control
Control processtime Inherits Label
ControlInstance processtime Inherits Label
End Control
Control PushButton4 Inherits PushButton
ControlInstance PushButton4 Inherits PushButton
EventHandler Sub Action() if not process.getNextProcess then msgBox "no more processes" end if update End EventHandler
End Control
Control StaticText13 Inherits Label
ControlInstance StaticText13 Inherits Label
End Control
Control processlaunch Inherits Label
ControlInstance processlaunch Inherits Label
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub Paint(g As Graphics) if icon1<>nil then icon1.DrawIcon(g,me.left,me.top,me.Width,me.Height) end if End EventHandler
End Control
Control Canvas3 Inherits Canvas
ControlInstance Canvas3 Inherits Canvas
EventHandler Sub Paint(g As Graphics) if icon1<>nil then icon1.DrawIcon(g,me.left,me.top,me.Width,me.Height) end if End EventHandler
End Control
Control Canvas2 Inherits Canvas
ControlInstance Canvas2 Inherits Canvas
EventHandler Sub Paint(g As Graphics) if icon2<>nil then icon2.DrawIcon(g,me.left,me.top,me.Width,me.Height) end if End EventHandler
End Control
Control Canvas4 Inherits Canvas
ControlInstance Canvas4 Inherits Canvas
EventHandler Sub Paint(g As Graphics) if icon2<>nil then icon2.DrawIcon(g,me.left,me.top,me.Width,me.Height) end if End EventHandler
End Control
Control StaticText14 Inherits Label
ControlInstance StaticText14 Inherits Label
End Control
Control processid Inherits Label
ControlInstance processid Inherits Label
End Control
Control PushButton5 Inherits PushButton
ControlInstance PushButton5 Inherits PushButton
EventHandler Sub Action() process.Visible=false End EventHandler
End Control
Control PushButton6 Inherits PushButton
ControlInstance PushButton6 Inherits PushButton
EventHandler Sub Action() process.Visible=true End EventHandler
End Control
Control PushButton7 Inherits PushButton
ControlInstance PushButton7 Inherits PushButton
EventHandler Sub Action() ' Disabled because it's dangerous if TargetWin32 then dim e as integer e=process.KillProcess Select case e case 0 MsgBox "Can't kill the process." case 1 MsgBox "Killed the process well." case 1 MsgBox "Killed the process badly." else MsgBox "unknown result code." end Select else if process.KillProcess=0 then MsgBox "Killed the process." else MsgBox "Can't kill the process. "+str(process.Lasterror) end if end if End EventHandler
End Control
Control PushButton8 Inherits PushButton
ControlInstance PushButton8 Inherits PushButton
EventHandler Sub Action() dim e as integer e=process.QuitProcess MsgBox "Quitted the process with error code "+str(e)+"." End EventHandler
End Control
EventHandler Sub Open() process=new ProcessMBS process.getcurrentProcess End EventHandler
Sub update() dim f as folderItem dim p as ProcessMBS dim s as string dim m as memoryBlock processname.text=process.name if process.visible then processvisible.text="yes" else if targetcarbon then processvisible.text="no" else processvisible.text="n/a" end if end if if process.CurrentProcess then processcurrent.text="yes" else processcurrent.text="no" end if if process.frontProcess then processfront.text="yes" else processfront.text="no" end if processtype.text=process.MacType processcreator.text=process.MacCreator if process.memorysize=0 then processsize.text="n/a" else processsize.text=format(process.memorysize/1024,"0")+" KB" // (0 for Mac OS X native applications) end if if process.memoryfree=0 then processfree.text="n/a" else processfree.text=format(process.memoryfree/1024,"0")+" KB" // (0 for Mac OS X native applications) end if processtime.text=format(process.cpUTime/3600,"0")+" minutes." if RunningOnCarbonXMBS then processtime.text=processtime.text+" (allways 0 on Mac OS X native applications)" end if f=process.path if f=nil then processpath.text="n/a" // should never happen icon1=nil else if f.Parent.Name="MacOS" then // bundle? f=f.Parent.Parent.Parent // move to bundle end if processpath.text=f.UnixpathMBS icon1=new IconMBS(f) if not icon1.Valid then icon1=nil end if end if Canvas1.Refresh Canvas3.Refresh m=process.MacProcessSerial if m<>nil then s=", MacProcessSerial: "+hex(m.long(0))+":"+hex(m.long(4)) end if processid.text=str(process.processID)+s p=process.LaunchProcess if p<>Nil then processlaunch.text=p.name f=p.path if f<>nil then if f.Parent.Name="MacOS" then // bundle? f=f.Parent.Parent.Parent // move to bundle end if icon2=new IconMBS(f) if not icon1.Valid then icon2=nil end if else icon2=nil end if else processlaunch.text="n/a" // should never happen icon2=nil end if Canvas2.Refresh Canvas4.Refresh End Sub
Property Protected icon1 As iconmBS
Property Protected icon2 As iconmBS
Property process As processMBS
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Activate() window1.update End EventHandler
EventHandler Sub Deactivate() 'window1.update End EventHandler
End Class
End Project

See also:

Feedback, Comments & Corrections

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




Links
MBS Xojo blog