Structure Meter
PBimg.l
width.l
height.l
offset.l
values.l[1024]
EndStructure
#WM_UPDATEMETER = #WM_USER+1500
#WM_SETFGCOLOR = #WM_USER+1501
#WM_SETBGCOLOR = #WM_USER+1502
#WM_SETGDCOLOR = #WM_USER+1503
#WM_SETBDCOLOR = #WM_USER+1504
#WM_FILLED = #WM_USER+1506
#WM_PEAK = #WM_USER+1507
Procedure MeterProc(hwnd,msg,wParam,lParam)
Select msg
Case #WM_UPDATEMETER
*mr.Meter=GetWindowLong_(hwnd,#GWL_USERDATA)
If *mr\offset=10
*mr\offset=0
EndIf
For d=0 To *mr\width-1
*mr\values[d]=*mr\values[d+1]
Next
*mr\values[*mr\width-1]=lParam
StartDrawing(ImageOutput(*mr\PBimg))
Box(0,0,*mr\width,*mr\height,#Black)
For a=0 To *mr\height Step 10
LineXY(0,a,*mr\width,a,$7F00)
Next
For a=0 To *mr\width+*mr\offset Step 10
LineXY(a-*mr\offset,0,a-*mr\offset,*mr\height,$7F00)
Next
For d=0 To *mr\width
bottom.l=*mr\height
thepercent.f=(*mr\values[d]/100)
actualheight.l=Int(thepercent* *mr\height)
Y1.l=bottom-actualheight
thepercent.f=(*mr\values[d+1]/100)
actualheight.l=Int(thepercent* *mr\height)
Y2.l=bottom-actualheight
LineXY(d,Y1,d+1,Y2,$FF00)
Next
*mr\offset+1
StopDrawing()
SetWindowLong_(hwnd,#GWL_USERDATA,*mr)
SendMessage_(hwnd,#STM_SETIMAGE,#IMAGE_BITMAP,ImageID(*mr\PBimg))
EndSelect
ProcedureReturn CallWindowProc_(GetProp_(hwnd,"oldproc"),hwnd,msg,wParam,lParam)
EndProcedure
Procedure MeterControl(id.l,x,Y,width,height)
image=CreateImage(#PB_Any,width,height)
StartDrawing(ImageOutput(image))
Box(0,0,width,height,#Black)
For a=0 To height Step 10
LineXY(0,a,width,a,$7F00)
Next
For a=0 To width Step 10
LineXY(a,0,a,height,$7F00)
Next
StopDrawing()
imagegad.l=ImageGadget(id,x,Y,width,height,ImageID(image),#PB_Image_Border)
SetProp_(GadgetID(imagegad),"oldproc",SetWindowLong_(GadgetID(imagegad),#GWL_WNDPROC,@MeterProc()))
If id=#PB_Any
hwndreturn=imagegad
hwnd=GadgetID(imagegad)
Else
hwndreturn=imagegad
hwnd=imagegad
EndIf
*mtr.Meter=AllocateMemory(SizeOf(Meter))
*mtr\PBimg=image
*mtr\width=width
*mtr\height=height
SetWindowLong_(hwnd,#GWL_USERDATA,*mtr)
ProcedureReturn hwndreturn
EndProcedure
Procedure GetMeterImage(id.l)
*mr.Meter=GetWindowLong_(GadgetID(id),#GWL_USERDATA)
bitmapreturn.l=*mr\PBimg
ProcedureReturn bitmapreturn
EndProcedure
OpenWindow(0,0,0,470,460,"Meter Control",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
themeter.l=MeterControl(#PB_Any,90,10,290,200)
TrackBarGadget(20,110,300,260,30,0,100)
ButtonGadget(21,160,350,140,20,"Save Meter Image")
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
SendMessage_(GadgetID(themeter),#WM_UPDATEMETER,0,GetGadgetState(20))
Select EventGadget()
Case 21
Pattern$ + "Bitmap (*.bmp)|*.bmp|"
Pattern = 0
filename.s=SaveFileRequester("Please Choose The File Name To Save", "", Pattern$, Pattern)
If filename
If GetExtensionPart(filename)<>"bmp"
filename+".bmp"
EndIf
SaveImage(GetMeterImage(themeter),filename,#PB_ImagePlugin_BMP)
EndIf
EndSelect
Case #PB_Event_CloseWindow
Quit=1
EndSelect
Until Quit=1