Anscheinend funktionieren manche Stringbefehle nicht,
wenn man threadsicher compiliert, ohne geht es aber.
PBOSL_CPUmonitor
CPU1.pb
Funktioniert, allerdings nur als nicht threadsicher.
CPU2.pb
Code: Alles auswählen
;----------------------------------------
;----------------------------------------
; start program code
;----------------------------------------
;----------------------------------------
Global Dim Progress.l(34)
Procedure updateCPUgadget()
For a = 1 To 34 : Progress(a-1) = Progress(a) : Next a
Progress(34) = CpuUsage()
For a = 0 To 34 : SetGadgetState(a,Progress(a)):Next a
;Beep_(1400,3)
EndProcedure
hWnd = OpenWindow(1,100,100,176,100,#PB_Window_SystemMenu,"CPU Monitor")
SetWindowPos_(hWnd,#HWND_TOPMOST,0,0,0,0,#SWP_NOACTIVATE|#SWP_SHOWWINDOW|#SWP_NOMOVE|#SWP_NOSIZE)
CreateGadgetList(hWnd)
For a = 0 To 34
ProgressBarGadget(a,a*5,0,6,100,0,100,#PB_ProgressBar_Smooth|#PB_ProgressBar_Vertical)
Next a
; set the Priority of this process To 'High'
; this makes sure our program gets updated, even when
; another process is consuming lots of CPU cycles
SetThreadPriority_( GetCurrentThread_() , #THREAD_BASE_PRIORITY_MAX)
SetPriorityClass_( GetCurrentProcess_(), #HIGH_PRIORITY_CLASS)
StartTimer(1,500,@updateCPUgadget())
Repeat: Until WaitWindowEvent() = #PB_Event_CloseWindow
EndTimer(1)
Beep_(1400,200)
Delay(310)
;----------------------------------------
;----------------------------------------
; end program code
;----------------------------------------
;----------------------------------------
; ExecutableFormat=Windows
; Executable=CPUmon_02.exe
; DisableDebugger
CPU3.pb
Code: Alles auswählen
;----------------------------------------
; Includes
;----------------------------------------
IncludeFile "HideFromTaskbar.pbi"
;----------------------------------------
; Variables and Constants
;----------------------------------------
Width = 130
Height = 75
BorderColor = RGB(56,203,14)
DrawingColor = RGB($FF,$FF,$00)
Global Dim Progress.l(Width)
;----------------------------------------
; Procedures
;----------------------------------------
Procedure updateCPUgadget()
Shared hWnd, image, Width, Height, BorderColor, DrawingColor
HideFromTaskbar(hWnd,#True)
For a = 1 To Width : Progress(a-1) = Progress(a) : Next a
Progress(Width) = CpuUsage()
;UseImage(1)
StartDrawing(ImageOutput(1)): Box(1,1,width,Height,0)
For a = 0 To Width:
b.f = Progress(a)*(Height/100)
LineXY(a+1,Height,a+1,(Height)-b,DrawingColor)
Next a
DrawingMode(4): Box(0,0,width+2,Height+2,BorderColor):
StopDrawing()
StartDrawing(WindowOutput(1)): DrawImage(image,0,0): StopDrawing()
EndProcedure
;----------------------------------------
;----------------------------------------
; start program code
;----------------------------------------
;----------------------------------------
If CreatePopupMenu(0)
MenuItem(1, "About")
MenuItem(2, "Quit")
EndIf
hWnd = OpenWindow(1,100,100,Width+2,Height+2,#WS_POPUP,"CPU Monitor")
InitHideFromTaskbar()
HideFromTaskbar(hWnd,#True)
SetWinBackgroundColor(hWnd,0)
; StayOnTop
SetWindowPos_(hWnd,#HWND_TOPMOST,0,0,0,0,#SWP_NOACTIVATE|#SWP_SHOWWINDOW|#SWP_NOMOVE|#SWP_NOSIZE)
; Change Cursor
Cursor = LoadCursor_(0, #IDC_CROSS)
SetClassLong_(hWnd,#GCL_HCURSOR,Cursor)
; set the Priority of this process To 'High'
; this makes sure our program gets updated, even when
; another process is consuming lots of CPU cycles
SetThreadPriority_( GetCurrentThread_() , #THREAD_BASE_PRIORITY_MAX)
SetPriorityClass_( GetCurrentProcess_(), #HIGH_PRIORITY_CLASS)
image = CreateImage(1,Width+2, Height+2)
StartTimer(1,100,@updateCPUgadget())
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow: Quit = 1
Case #WM_PAINT : StartDrawing(WindowOutput(1)): DrawImage(image,0,0): StopDrawing()
Case #WM_RBUTTONDOWN : DisplayPopupMenu(0, WindowID(1))
Case #WM_LBUTTONDOWN : HideFromTaskbar(hWnd,#True): SendMessage_(hWnd,#WM_NCLBUTTONDOWN, #HTCAPTION,0)
;Case #WM_MOUSEMOVE :
Case #PB_Event_Menu
Select EventMenu() ; To see which menu has been selected
Case 1 : MessageRequester("CPU monitor Info","Coded by Danilo, 2002"+Chr(13)+" with PureBasic",0); About
Case 2 : Quit = 1 ; Quit
EndSelect
EndSelect
HideFromTaskbar(hWnd,#True)
Until Quit = 1
CodeEnd:
HideWindow(1,#True)
EndTimer(1)
Delay(110)
EndHideFromTaskbar()
CloseWindow(1)
DestroyCursor_(Cursor)
;----------------------------------------
;----------------------------------------
; end program code
;----------------------------------------
;----------------------------------------
; ExecutableFormat=Windows
; Executable=CPUmon_03.exe
; DisableDebugger
PBOSL_Timer
Timer-TEST 1.pb
Timer funktionieren, aber Beep_ nicht.
Timer-TEST 2.pb
Funktioniert nur als nicht threadsicher, Beep_ funktioniert nicht.