何でもいいのならば、テスト用のソースコードを貼り付けておきます。
//------------------------------------------------------------------------------
// 科学太郎のサンプル for HSP(Ver.3.3.2)
//==============================================================================
// テーマ:CPU使用率のグラフ描画
//------------------------------------------------------------------------------
//--------------------------------------
// Win32API関数の命令登録(OK)
//--------------------------------------
#uselib "Pdh.dll"
#func global PdhOpenQuery "PdhOpenQueryA" sptr,sptr,var
#func global PdhCloseQuery "PdhCloseQuery" sptr
#func global PdhAddCounter "PdhAddCounterA" sptr,sptr,sptr,var
#func global PdhCollectQueryData "PdhCollectQueryData" sptr
#func global PdhGetFormattedCounterValue "PdhGetFormattedCounterValue" sptr,sptr,sptr,var
//--------------------------------------
// 記号定数(API定数)
//--------------------------------------
#const NULL $00000000
#const PDH_FMT_LONG $00000100
//--------------------------------------
// メイン部(OK)
//--------------------------------------
*Init
dim hQuery
dim hCounter
dim fmtValue,3
dim CPUGraph,60
dim CPUPos
CPUInit
*Main
;デバッグ・ウインドウ
fn=14
sx=fn+fn*strlen("*CPUGraph(59)=100%")/2
sy=fn+fn*length(CPUGraph)
screen 1,sx,sy,SCREEN_NORMAL|SCREEN_FIXEDSIZE|SCREEN_TOOL:gsel 1,2
title "CPUGraph"
cx=(ginfo_dispX-ginfo_sizeX)
cy=(ginfo_dispY-ginfo_sizeY)/2
width sx,sy,cx,cy
font MSGOTHIC,fn
;メイン・ウインドウ
sx=300*2 ;480
sy=300 ;88
cx=0
cy=0
ex=cx+sx-1
ey=cy+sy-1
bx=(sx/length(CPUGraph))/2
by=(0)
fn=(sy/10*2)*80/100
screen 0,sx,sy,SCREEN_NORMAL:gsel 0,2
title "No.002(CPU使用率のグラフ描画)"
font MSGOTHIC,fn
onexit *Quit
repeat
;デバッグ・ウインドウ
gsel 1
redraw 0
color $FF,$FF,$CC:boxf
color $66,$33,$00:pos 7,7
foreach CPUGraph
if(cnt==CPUPos):c='*':else:c=' '
mes strf("%cCPUGraph(%2d)=%3d%%",c,cnt,CPUGraph(cnt))
loop
redraw 1
;メイン・ウインドウ
gsel 0
redraw 0
gradf cx,cy,sx,sy,1,$FFFFCC,$FFBB00
color $DD,$AA,$00
;縦罫線
y1=by
y2=by+sy-1
repeat length(CPUGraph)+1
n=bx+(sx/length(CPUGraph))*cnt
line n,y2,n,y1
loop
;横罫線
x1=bx
x2=bx+(sx*(length(CPUGraph)-1)/length(CPUGraph))
repeat 11
n=by+(sy/10)*cnt
line x2,n,x1,n
loop
;外枠
color $66,$33,$00
line cx,ey,cx,cy
line ex,ey
line ex,cy
line cx,cy
;CPU使用率
CPUUsage
CPUGraph(CPUPos)=stat:CPUPos++
if(CPUPos>=length(CPUGraph)):CPUPos=0
s=strf("CPU%3d%%",stat)
x=(sx-fn*strlen(s)/2)/2
y=((sy/10*2)-fn)/2
pos x,y:mes s
;後半グラフ
pos bx,by+(sy-sy*CPUGraph(CPUPos)/100)
repeat length(CPUGraph)-CPUPos
x=bx+(sx/length(CPUGraph))*cnt
y=by+(sy-sy*CPUGraph(CPUPos+cnt)/100)
; circle x-2,y-2,x+2,y+2,1
line x,y
loop
;前半グラフ
n=(length(CPUGraph)-CPUPos)
repeat CPUPos
x=bx+(sx/length(CPUGraph))*(n+cnt)
y=by+(sy-sy*CPUGraph(cnt)/100)
; circle x-2,y-2,x+2,y+2,1
line x,y
loop
redraw 1
await 100
loop
stop
//--------------------------------------
// アプリケーションの後始末(OK)
//--------------------------------------
*Quit
CPUTerm
end
//--------------------------------------
// CPU使用率の初期化(OK)
//--------------------------------------
#deffunc CPUInit
PdhOpenQuery NULL,0,hQuery
PdhAddCounter hQuery,"\\Processor(_Total)\\% Processor Time",0,hCounter
PdhCollectQueryData hQuery
return
//--------------------------------------
// CPU使用率の後始末(OK)
//--------------------------------------
#deffunc CPUTerm
PdhCloseQuery hQuery
return
//--------------------------------------
// CPU使用率の取得(OK)
//--------------------------------------
#deffunc CPUUsage
PdhCollectQueryData hQuery
PdhGetFormattedCounterValue hCounter,PDH_FMT_LONG,NULL,fmtValue
return fmtValue(2)
//------------------------------------------------------------------------------
// End of newSample002.hsp
//------------------------------------------------------------------------------
こんな感じでしょうかね。