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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Polygon drawing problem

Status
Not open for further replies.

wilfranz

Technical User
Oct 4, 2003
122
US
Hello friends,

I am encountering a perplexing problem with drawing a polygon on a form programatically, using the API Polygon call.

Problem: The polygon is drawn nicely when the Form's ShowWindow is set to Default or In-Top-Level-Screen (0 or 1). But when I try to set the Form to As-Top-Level-Form (ShowWindow = 2), the polygon will not draw. And I need the Form to be a top-level form, so this is an impeding glitch.

The form is modeless and maximized. I have tried altering the size, and making the form modal. Also tried Themes both .T. and .F. Still nada.

I suspect this may have something to do with the fact that the Polygon call requires a Device Context (another API call) to be passed, which maybe works differently for the Top-Level Window???

Any ideas?

TIA

wilfranz
 

I have an example of the use of the POLYGON API call and I change the form to a top-level form and the example still works.

I suspect this may have something to do with the fact that the Polygon call requires a Device Context (another API call) to be passed, which maybe works differently for the Top-Level Window???

No I don't think so, can you post your code (or a part of it) so we can see what is the problem?


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
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
**************************************************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top