WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Boxes Examples from Users

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Pie Chart Drawing Program

Keywords: 	  gdipie.wbt pie chart

Someone wanted a pie-type progress bar, so I wrote this prototype for them to try out.
winx1 = 100
winy1 = 100
winx2 = 900
winy2 = 900
wincoords = StrCat(winx1, ",", winy1, ",", winx2, ",", winy2)
BoxesUp(wincoords, @Normal)
UserDLL = (StrCat(DirWindows(1),"user32.dll"))
GDIDLL = (StrCat(DirWindows(1),"GDI32.dll"))
UserH = DllLoad (UserDLL)
GdiH = DllLoad (GDIDLL)
win = WinName()
hwnd = DllHwnd(win)
MM_TEXT = 1
MM_ISOTROPIC = 7
PS_DASH = 1                    
PS_DASHDOT = 3                 
PS_DASHDOTDOT = 4              
PS_DOT = 2                     
PS_INSIDEFRAME = 6
PS_NULL = 5
PS_SOLID = 0
GDI_ERROR = 65535
penWidth = 1
penStyle = PS_SOLID


hRgn = 0
bbMax = 100000
bb = BinaryAlloc(bbMax)

WinhDC = DllCall (Userh, long:"GetDC", long:hWnd)
MaxX = WinMetrics(0)
MaxY = WinMetrics(1)
MapMode = MM_Isotropic
OldMapMode = DllCall (GdiH, long:"SetMapMode", long:WinhDC, long:MapMode)
SizeStruct = BinaryAlloc(8)
nXextent = 1000
nYextent = 1000
result = DllCall (GdiH, long:"SetWindowExtEx", long:WinhDC, long:nXextent, long:nYextent, lpBinary:SizeStruct)
nXextent = MaxX
nYextent = MaxY
result = DllCall (GdiH, long:"SetViewportExtEx", long:WinhDC, long:nXextent, long:nYextent, lpBinary:SizeStruct)
Params = "128 128 128"
Gosub CreateBrush
FirstObject = DllCall (GdiH, long:"SelectObject", long:WinhDC, long:HBrush)

Params = "8 155 8"
Gosub CreateBrush
Params = "253 10 15 3 0"
Gosub CreatePen
Params = "100 100 250 250"
Gosub DrawEllipse
Params = "128 155 128"
Gosub CreateBrush

x1 = 100
y1 = 100
x2 = 250
y2 = 250
r = (y2 - y1) / 2 ;if a true circle
p1x = x1
p1y = y1 + r
i2 = x2
i1 = x1
for loop = i1+5 to i2 by 5
  p2x = loop
  temp = (r**2) - ((loop - i1 - r)**2)
  temp2 = sqrt(abs(temp))
  p2y = int(temp2) + i1 + r
  Params = "%x1%,%y1% %x2%,%y2% %p1x%,%p1y% %p2x%,%p2y%"
  Gosub DrawPie
;  TimeDelay(0.1)
next loop
for loop = i2 to i1 by -5
  p2x = loop
  temp = (r**2) - ((loop - i1 - r)**2)
  temp2 = sqrt(abs(temp))
  p2y = int(temp2) * -1 + i1 + r
  Params = "%x1%,%y1% %x2%,%y2% %p1x%,%p1y% %p2x%,%p2y%"
  Gosub DrawPie
;  TimeDelay(0.1)
next loop



BoxTitle("Press control key to exit.")
While @True
  TimeDelay(0.2)
  If IsKeyDown(@ctrl) then break
EndWhile
Dummy = DllCall (GdiH, long:"DeleteObject", long:HPen)
Dummy = DllCall (GdiH, long:"DeleteObject", long:HBrush)
Dummy = DllCall (GdiH, long:"SelectObject", long:WinhDC, long:FirstObject)
Dummy = DllCall (GdiH, long:"SetMapMode", long:WinhDC, long:OldMapMode)
Result = DllCall (Userh, long:"ReleaseDC", long:hWnd, long:WinhDC)

DllFree (GdiH)
DllFree (UserH)
BinaryFree(bb)
BinaryFree(SizeStruct)
EXIT

:CreateBrush
ParseData(Params)
If Param0 != 3 then Message("Incorrect # of parameters for CreateBrush", "3 needed, %Param0% sent")
r = Param1
g = Param2
b = Param3
brushColor = (0 << 24) | (b << 16) | (g << 8) | r
if IsDefined(HBrush) then Dummy = DllCall (GdiH, long:"DeleteObject", long:HBrush)
HBrush = DllCall (GdiH, long:"CreateSolidBrush", long:brushColor)
Params = HBrush
Gosub SelectObject
RETURN

:CreatePen
;params = Red Green Blue penWidth penStyle
ParseData(Params)
If Param0 < 3 || Param0 > 5 then Message("Incorrect # of parameters for CreatePen", "3 to 5 needed, %Param0% sent")
r = Param1
g = Param2
b = Param3
if Param0 > 3 then penWidth = Param4
if Param0 == 5 then penStyle = Param5
penColor = (0 << 24) | (b << 16) | (g << 8) | r
if IsDefined(HPen) then Dummy = DllCall (GdiH, long:"DeleteObject", long:HPen)
HPen = DllCall (GdiH, long:"CreatePen", long:penStyle, long:penWidth, long:penColor)
Params = HPen
Gosub SelectObject
RETURN

:SelectObject
ParseData(Params)
if Param0 != 1 then Message("Incorrect # of parameters for SelectObject", "1 needed, %Param0% sent")
LastObject = DllCall (GdiH, long:"SelectObject", long:WinhDC, long:Param1)
if LastObject == 0 || LastObject == GDI_ERROR
  Message("Last object error is:", LastObject)
endif
RETURN

:DrawEllipse
ParseData(Params)
if Param0 != 4 then Message("Incorrect # of parameters for Ellipse", "4 needed, %Param0% sent")
Result = DllCall (GdiH, long:"Ellipse", long:WinhDC, long:Param1, long:Param2, long:Param3, long:Param4)
;Result = DllCall (GdiH, long:"Ellipse", long:WinhDC, long:x1, long:y1, long:x2, long:y2)
if Result == 0 then Message("Ellipse failed", "")
RETURN

:DrawPie
Params = StrReplace(Params, ",", " ")
ParseData(Params)
if Param0 != 8 then Message("Incorrect # of parameters for Pie", "8 needed, %Param0% sent")
Result = DllCall (GdiH, long:"Pie", long:WinhDC, long:Param1, long:Param2, long:Param3, long:Param4, long:Param5, long:Param6, long:Param7, long:Param8)
if Result == 0 then Message("Pie failed", "")
RETURN

Article ID:   W14400
Filename:   Pie Chart Drawing Program.txt
File Created: 2000:03:27:15:56:08
Last Updated: 2000:03:27:15:56:08