Thanks for your reply Mike. Here is the code as taken from the Class Browser (because I designed this visually), and with some explanatory annotations added.
PUBLIC oform1
oform1=NEWOBJECT("form1")
oform1.Show
RETURN
**************************************************
*-- Form: form1 (c:\program files\microsoft visual foxpro 8\third party stuff\rotate\prx2poly.scx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 08/14/04 01:24:13 PM
*
DEFINE CLASS form1 AS form
Top = 0
Left = 0
Height = 604
Width = 600
ShowWindow = 0 && IT'S THIS PROPERTY THAT IS THE PROBLEM......
DoCreate = .T.
Caption = "Prx2Poly"
WindowType = 0
WindowState = 0
Themes = .T.
Name = "Form1"
nhwnd = .F. && User-defined property to hold the Window Handle
ADD OBJECT command1 AS commandbutton WITH ;
Top = 327, ;
Left = 494, ;
Height = 27, ;
Width = 84, ;
Caption = "Command1", ;
Name = "Command1"
PROCEDURE num2struct
LPARAMETERS nNum
*Constructs a 4-byte string, smallest byte first.
nVar2 = INT(nNum/255)
nVar1 = nNum - (nVar2 * 255)
*---------------------------------------------------------
*We can dispense with calculating the 3rd and 4th bytes,
*cuz the number will never exceed 1024 (screen width),
*let alone 65,536.
*---------------------------------------------------------
RETURN CHR(nVar1) + CHR(nVar2) + CHR(0) + CHR(0)
ENDPROC
PROCEDURE drawpoly
Local HDC, lcStruct, nNumPts
With This
*-----------------------------------------------------------------
* Get the Handle for this window
*-----------------------------------------------------------------
.nHWND = APIGetHWND(This)
*-----------------------------------------------------------------
* Get the device context for this form
*-----------------------------------------------------------------
HDC = GetDC( .nHWND )
*-----------------------------------------------------------------
*Make up the Array Structure to pass to the API Polygon. The loop
*reads 30 pairs of values (xPos and yPos) from a dbf table, and
*converts them to 4-byte strings (using method Num2Struct(nVal),
*which are concatenated for the Structure.
*-----------------------------------------------------------------
nNumPts = RECCOUNT()+1
lcStruct = ""
SCAN
xPt = .num2struct(xpos) && A user defined function/method
yPt = .num2struct(ypos)
lcStruct = lcStruct + xPt + yPt
ENDSCAN
*--------------------------------------------------
*Add the margin line points to complete the polygon
*--------------------------------------------------
GO top
xPt = .num2struct(xpos)
GO bottom
yPt = .num2struct(ypos)
lcStruct=lcStruct + xpt + ypt
*-----------------------------------------------------------------
* Activate a brush and a color.
*-----------------------------------------------------------------
Local lnPrevBrush, lnBrush
lnBrush = CreateSolidBrush(RGB(225,255,255))
SelectObject( m.HDC, m.lnBrush )
*-----------------------------------------------------------------
* Paint the polygon
*-----------------------------------------------------------------
polygon(m.HDC, lcStruct, nNumPts)
*-----------------------------------------------------------------
* And release the device context. As advised, to avoid memory leaks.
*-----------------------------------------------------------------
ReleaseDC( .nHWND, m.HDC )
Endwith
ENDPROC
PROCEDURE Load
CLOSE all
*Open the dbf which holds the x-y positions
USE prxshrline IN 0
SELECT prxshrline
*-------------------------------------------------------
*This procedure, by Foxpert, 1999, downloaded from UT,
*holds the procedure APIGetHWND(), which returns the
*window handle, needed for the API call
*-------------------------------------------------------
SET PROCEDURE TO apix.prg additive
*-------------------------------------------------------
*Read a library of relevant API defintions,
*which holds the Polygon API
*-------------------------------------------------------
Do ApiDef.prg
ENDPROC
PROCEDURE command1.Click
thisform.drawpoly()
ENDPROC
ENDDEFINE
*
*-- EndDefine: form1
**************************************************