HI
I am beginner on powerbasic and I found a loot of good information in this forum, but in
this case I don't know what is wrong.
I use PieChart.Bas posted by Bernad Chapman
Evrytime I update the chartpie windows whith a timer (every ten seconds)can I se in the taskmanager,
that GDI-Object increase by 6, and after some hour the color in the pie is disappering (getting white)
and eating up resource from OS(xp).
The same happens if I use the orginal code and move a annother window many times over the piechart to force a updating.
I only guess that it has something to do whith the 'GDI-OBJECT' and the problem are in SUB PieChart.
Code extract from PieChart.Bas
'****************************************
SUB PieChart(hDC AS LONG,nosectors AS LONG,sectorname() AS STRING,sectorsize() AS SINGLE,XCentre AS LONG,YCentre AS LONG,radius AS LONG)
DIM DA(10) AS SINGLE
DIM gText(10) AS ASCIIZ * 200
LOCAL gTex AS ASCIIZ * 200
LOCAL I AS LONG
LOCAL TOTAL AS SINGLE
LOCAL CUMUL AS SINGLE
LOCAL pi2 AS SINGLE
LOCAL pct AS LONG
LOCAL recstart AS LONG
LOCAL hpenpie AS LONG
LOCAL hbrushpie AS LONG
LOCAL hFontPie AS LONG
LOCAL xStart AS LONG, yStart AS LONG, xEnd AS LONG, yEnd AS LONG
LOCAL xText AS LONG, yText AS LONG, korr AS LONG
LOCAL xLeft AS LONG, yTop AS LONG, xRight AS LONG, yBottom AS LONG
FOR I=1 TO nosectors
gText(I)=sectorname(I)
NEXT
TOTAL=0
FOR I=1 TO nosectors
DA(I) = sectorsize(i)
TOTAL = TOTAL + DA(I)
NEXT
xLeft = Xcentre - Radius : xRight = Xcentre + Radius
yTop = Ycentre - Radius : yBottom = Ycentre + Radius
hFontPie = MakeFont(FontName,FontSize)
SelectObject hDC, hFontPie
pi2=8*ATN(1)
CUMUL=0
korr=-11 ' empiric correction for height of characters. This may be improved.
FOR I=1 TO nosectors
CUMUL = CUMUL + DA(I)
pct=INT(100*DA(I)/TOTAL+0.5)
xText = INT(Xcentre+(Radius-korr)*COS(pi2 * (CUMUL - DA(I)/2) / TOTAL)+0.5)
yText = INT(Ycentre-(Radius-korr)*SIN(pi2 * (CUMUL - DA(I)/2) / TOTAL)+0.5)
IF COS(pi2 * (CUMUL - DA(I)/2) / TOTAL) >= 0 THEN
SetTextAlign hDC,%TA_LEFT ' text on right side of diagram
ELSE
SetTextAlign hDC,%TA_RIGHT ' text on left side of diagram
END IF
gTex=gText(I)+" ("+LTRIM$(STR$(pct))+"%)"
TextOut hDC, xText, yText+korr, gTex, BYVAL LEN(gTex)
NEXT
xStart=Xcentre+Radius: yStart=Ycentre ' select starting point for pie pieces
CUMUL=0
FOR I=1 TO nosectors
CUMUL = CUMUL + DA(I)
xEnd = INT(Xcentre+Radius*COS(pi2 * CUMUL / TOTAL)+0.5)
yEnd = INT(Ycentre-Radius*SIN(pi2 * CUMUL / TOTAL)+0.5)
hPenPie = SelectObject(hDC, CreatePen(%PS_SOLID, 0, gColor(10)))
hBrushPie = SelectObject(hDC, CreateSolidBrush (gColor(I)))
PIE hDC, xLeft,yTop,xRight,yBottom, xStart, yStart, xEnd, yEnd
xStart=xEnd: yStart=yEnd
NEXT
DeleteObject hPenpie
DeleteObject hBrushpie
DeleteObject hFontpie
END SUB
'****************************************************
Eddy Larsson
I am beginner on powerbasic and I found a loot of good information in this forum, but in
this case I don't know what is wrong.
I use PieChart.Bas posted by Bernad Chapman
Evrytime I update the chartpie windows whith a timer (every ten seconds)can I se in the taskmanager,
that GDI-Object increase by 6, and after some hour the color in the pie is disappering (getting white)
and eating up resource from OS(xp).
The same happens if I use the orginal code and move a annother window many times over the piechart to force a updating.
I only guess that it has something to do whith the 'GDI-OBJECT' and the problem are in SUB PieChart.
Code extract from PieChart.Bas
'****************************************
SUB PieChart(hDC AS LONG,nosectors AS LONG,sectorname() AS STRING,sectorsize() AS SINGLE,XCentre AS LONG,YCentre AS LONG,radius AS LONG)
DIM DA(10) AS SINGLE
DIM gText(10) AS ASCIIZ * 200
LOCAL gTex AS ASCIIZ * 200
LOCAL I AS LONG
LOCAL TOTAL AS SINGLE
LOCAL CUMUL AS SINGLE
LOCAL pi2 AS SINGLE
LOCAL pct AS LONG
LOCAL recstart AS LONG
LOCAL hpenpie AS LONG
LOCAL hbrushpie AS LONG
LOCAL hFontPie AS LONG
LOCAL xStart AS LONG, yStart AS LONG, xEnd AS LONG, yEnd AS LONG
LOCAL xText AS LONG, yText AS LONG, korr AS LONG
LOCAL xLeft AS LONG, yTop AS LONG, xRight AS LONG, yBottom AS LONG
FOR I=1 TO nosectors
gText(I)=sectorname(I)
NEXT
TOTAL=0
FOR I=1 TO nosectors
DA(I) = sectorsize(i)
TOTAL = TOTAL + DA(I)
NEXT
xLeft = Xcentre - Radius : xRight = Xcentre + Radius
yTop = Ycentre - Radius : yBottom = Ycentre + Radius
hFontPie = MakeFont(FontName,FontSize)
SelectObject hDC, hFontPie
pi2=8*ATN(1)
CUMUL=0
korr=-11 ' empiric correction for height of characters. This may be improved.
FOR I=1 TO nosectors
CUMUL = CUMUL + DA(I)
pct=INT(100*DA(I)/TOTAL+0.5)
xText = INT(Xcentre+(Radius-korr)*COS(pi2 * (CUMUL - DA(I)/2) / TOTAL)+0.5)
yText = INT(Ycentre-(Radius-korr)*SIN(pi2 * (CUMUL - DA(I)/2) / TOTAL)+0.5)
IF COS(pi2 * (CUMUL - DA(I)/2) / TOTAL) >= 0 THEN
SetTextAlign hDC,%TA_LEFT ' text on right side of diagram
ELSE
SetTextAlign hDC,%TA_RIGHT ' text on left side of diagram
END IF
gTex=gText(I)+" ("+LTRIM$(STR$(pct))+"%)"
TextOut hDC, xText, yText+korr, gTex, BYVAL LEN(gTex)
NEXT
xStart=Xcentre+Radius: yStart=Ycentre ' select starting point for pie pieces
CUMUL=0
FOR I=1 TO nosectors
CUMUL = CUMUL + DA(I)
xEnd = INT(Xcentre+Radius*COS(pi2 * CUMUL / TOTAL)+0.5)
yEnd = INT(Ycentre-Radius*SIN(pi2 * CUMUL / TOTAL)+0.5)
hPenPie = SelectObject(hDC, CreatePen(%PS_SOLID, 0, gColor(10)))
hBrushPie = SelectObject(hDC, CreateSolidBrush (gColor(I)))
PIE hDC, xLeft,yTop,xRight,yBottom, xStart, yStart, xEnd, yEnd
xStart=xEnd: yStart=yEnd
NEXT
DeleteObject hPenpie
DeleteObject hBrushpie
DeleteObject hFontpie
END SUB
'****************************************************
Eddy Larsson
Comment