Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Anybody played with the GDI32.DLL? 2

Status
Not open for further replies.

NFI

Programmer
Jun 7, 2000
278
GB
Hiya,

I'm trying to draw filled polygons on a form and I'm trying to use the GDI32.DLL API to do it.

My code is pretty straight forward;

Code:
[COLOR=#00007f]Private Declare Function [COLOR=#000000]PolyPolygon[/color] Lib [COLOR=#000000]"gdi32.dll"[/color] (ByVal [COLOR=#000000]hdc[/color] As Long, [COLOR=#000000]lpPoint[/color] As POINTAPI, [COLOR=#000000]lpPolyCounts[/color] As long, ByVal [COLOR=#000000]nCount[/color] As Long) As Long

Private Declare Function [COLOR=#000000]CreateSolidBrush[/color] Lib [COLOR=#000000]"gdi32.dll"[/color] (ByVal [COLOR=#000000]crColor[/color] As Long) As Long

Private Type [COLOR=#000000]POINTAPI[/color]
  [COLOR=#000000]x[/color] As Long
  [COLOR=#000000]y[/color] As Long
End Type

[COLOR=#000000]hBrush[/color] = CreateSolidBrush(RGB([COLOR=#000000]127,127,255[/color]))
[COLOR=#000000]lngRC[/color] = PolyPolygon([COLOR=#000000]frmMain.hdc, arrAPIPoints(0), arrAPINumPoints(0), 1[/color])[/color]

where:
arrAPIPoints is an array of type POINTAPI containing the x.y coords of my polygon
arrAPINumPoints is an array of type LONG containing a single element stating the number of points in arrAPIPoints

According to lngRC, PolyPolygon(...) isn't throwing an error, but nothing appears on my form :(

So what am I doing wrong?

Any help will be much appreciated,

Thanks,

Paul
 
See what the following does for you (you just need a form and a command button):
Code:
[blue]Option Explicit

Private Declare Function PolyPolygon Lib "gdi32.dll" (ByVal hdc As Long, lpPoint As POINTAPI, lpPolyCounts As Long, ByVal nCount As Long) As Long

Private Type POINTAPI
  x As Long
  y As Long
End Type


Private Sub Command1_Click()
    Dim pts(2) As POINTAPI
    Dim ptscounts(0) As Long
    Dim lngRC As Long

    pts(0).x = 10
    pts(0).y = 10
    pts(1).x = 75
    pts(1).y = 40
    pts(2).x = 15
    pts(2).y = 100
    ptscounts(0) = 3
    
    Form1.FillColor = RGB(127, 127, 255)
    Form1.FillStyle = vbSolid
    Form1.ForeColor = vbRed
    PolyPolygon Form1.hdc, pts(0), ptscounts(0), 1

End Sub[/blue]

(although my main guess is that you are doing the drawing in the Form's load event, in which case you'll want to set the AutoRedraw property to true before doing the drawing)
 
Aaaahhh...

Well that's pretty odd - I'd read about the AutoRedraw "feature" but didn't think it would affect what I was trying to do.

With the frmMain.FillColour and frmMain.FillStyle properties set, I do, indeed, get a polygon (a whacking great huge one that goes way off the form...not sure what's going on there) - any idea why the CreateSolidBrush(...) function isn't working like it should?

Do I need to set start coords or something for each polygon I draw, or do the coords you load into the Points() array do that for you?

Thanks for your help,


Paul
 
Hello again,

OK - this gets weirder and weirder.

I'm already drawing a bunch of shapes on my form using the VB LINE function. To get the polygons drawn by the GDI32 API to overlay these shapes, I have to divide all my coordinates by 15!

Why would that be?


Paul
 
Look at the scale mode. If I'm not mistaken, the API call expects pixels, but you are probably using twips.

There are usually 15 twips per pixel.

Debug.Print Screen.TwipsPerPixelX
Debug.Print Screen.TwipsPerPixelY



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Oh yes...

Well...that shows what I know...


Thanks for that :)

Paul
 
>any idea why the CreateSolidBrush(...) function isn't working like it should?


yes - you are not selecting it into the device context. But since (more-or-less) .Fillcolor IS a SolidBrush, why worry about using the API when working with VB forms and controls?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top