Platforms to show: All Mac Windows Linux Cross-Platform
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 CPU Usage
This example is the version from Sun, 17th Mar 2012.
Project "Windows CPU Usage.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
if not TargetWin32 then
MsgBox "This example requires Windows XP"
end if
End EventHandler
End Class
Class Window1 Inherits Window
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 ProgressBar1 Inherits ProgressBar
ControlInstance ProgressBar1 Inherits ProgressBar
End Control
Control ProgressBar2 Inherits ProgressBar
ControlInstance ProgressBar2 Inherits ProgressBar
End Control
Control ProgressBar3 Inherits ProgressBar
ControlInstance ProgressBar3 Inherits ProgressBar
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action()
// query CPU times
dim w as new WindowsProcessStatisticsMBS(-1, WindowsProcessStatisticsMBS.ModeTotalTime)
// calculate deltas as we get the absolute time spend for this and we want only the values for last second
dim deltaIdle as Uint64 = w.TotalIdleTime - LastIdle
dim deltaUser as Uint64 = w.TotalUserTime - LastUser
dim deltaKernel as Uint64 = w.TotalKernelTime - LastKernel
// kernel includes idle time, so remove it there
deltaKernel = deltaKernel - deltaIdle
// total
dim sum as Uint64 = deltaIdle + deltaUser + deltaKernel
// fill progress bars
ProgressBar1.Value = deltaUser * 100.0 / sum
ProgressBar2.Value = deltaKernel * 100.0 / sum
ProgressBar3.Value = deltaIdle * 100.0 / sum
// and remember last value
LastIdle = w.TotalIdleTime
LastKernel = w.TotalKernelTime
LastUser = w.TotalUserTime
'System.DebugLog "Values for Idle: "+str(LastIdle)+" kernel: "+str(LastKernel)+" user: "+str(LastUser)
'System.DebugLog "Deltas for Idle: "+str(deltaIdle)+" kernel: "+str(deltaUser)+" user: "+str(deltaKernel)
End EventHandler
End Control
EventHandler Sub Open()
dim w as new WindowsProcessStatisticsMBS(-1, WindowsProcessStatisticsMBS.ModeTotalTime)
LastIdle = w.TotalIdleTime
LastKernel = w.TotalKernelTime
LastUser = w.TotalUserTime
self.WinTopMostWindowMBS = true
End EventHandler
Property LastIdle As Uint64
Property LastKernel As Uint64
Property LastUser As Uint64
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project
See also:
- /Win/Windows Font
- /Win/Windows Font Dialog
- /Win/Windows Font Unicode and Code Pages
- /Win/Windows QOS/Windows QOS with UDPSocket
- /Win/Windows Shell
- /Win/Windows Shortcuts/File Shortcut
- /Win/Windows Speech/Windows Speech Test
- /Win/Windows Switch Printers for printing
- /Win/Windows System Tray
- /Win/Windows System Tray with Icon file/Windows System Tray with Icon file
The items on this page are in the following plugins: MBS Win Plugin.