Experience with VC development program (two continued)

zhaozj2021-02-16  54

// The following is the implementation of the three classes above, pay attention to the use of List

//

// CMYARC CLASS

//

//

// construction / destruction

//

CMYARC :: CMYARC (Myxyz i_pc, myxyz i_ps, myxyz i_pe)

{

M_PC = I_PC;

M_PS = i_ps;

M_PE = i_pe;

}

Int Cmyarc :: Draw (Long Ldevice)

{

Double DR = SQRT ((m_ps.x-m_pc.x) * (m_ps.x-m_pc.x) (m_ps.y-m_pc.y) * (m_ps.y-m_pc.y) (m_ps.z- m_pc.z) * (m_ps.z-m_pc.z));

:: Arc ((HDC) Ldevice, M_PC.x-DR, M_PC.Y-DR, M_PC.x DR, M_PC.Y DR, M_PS.X, M_PS.Y, M_PE.X, M_PE.Y);

Return 0;

}

//

// CMYPOLYLN CLASS

//

//

// construction / destruction

//

CMYPOLYLN :: ~ CMYPOLYLN ()

{

MyPolyln :: item;

For (iter = m_polyln.begin (); it! = m_polyln.end (); iter )

{

Delete (* iter);

}

m_polyln.clear ();

}

INT CMYPOLYLN :: AddPoint (myxyz * pxyz)

{

MYXYZ * P = New myxyz;

* p = * pxyz;

m_polyln.insert (m_polyln.end (), p);

Return 0;

}

Int CMYPOLYLN :: DRAW (long LDEvice)

{

HDC HDC = (HDC) Ldevice;

MyPolyln :: item ore = m_polyln.begin ();

// The point is more apparent, expand the ratio of the line, change the position of the line, and the statement in the comment should be used normally.

MoveToex (HDC, (* iTer) -> x * 100 100, - (* iter) -> Y * 100 200, NULL);

// MoveToex (HDC, (* iTer) -> x, (* iter) -> y, null;

For (iter = m_polyln.begin (); it! = m_polyln.end (); iter )

{

// The point is more apparent, expand the ratio of the line, change the position of the line, and the statement in the comment should be used normally.

LINETO (HDC, (* iTer) -> x * 100 100, - (* iter) -> y * 100 200);

// lineto (HDC, (* iTer) -> x, (* it) -> y);

}

Return 0;

}

//

// cshape class

//

//

// construction / destruction

//

Cshape :: ~ cshape ()

{

List :: iterator it;

For (iter = m_list.begin (); it! = m_list.end (); iter )

{

Delete (* iter);

}

m_list.clear ();

}

INT CSHAPE :: Draw (long ldevice)

{

List :: iterator it;

For (iter = m_list.begin (); it! = m_list.end (); ore ) {

(* iTer) -> Draw (Ldevice);

}

Return 0;

}

At this point, the geometric element object class is complete, and it can be tested in the main program:

Void CshapeView :: OnDraw (CDC * PDC)

{

Cshapedoc * pdoc = getDocument ();

Ask_VALID (PDOC);

{

Cshape shape;

CMYARC * PARC = New Cmyarc (CMYXZ (100, 100, 0), CMYXYZ (100, 20, 0), CMYXYZ (180, 100, 0));

Shape.m_list.insert (Shape.m_List.end (), PARC);

CMYPOLYLN * PPOLYLN = New CMYPOLYLN;

CMYXYZ XYZ (1, 1, 0);

PPOLYLN-> AddPoint (& xyz);

XYZ.X = 2;

XYZ.Y = 2;

PPOLYLN-> AddPoint (& xyz);

XYZ.X = 2;

XYZ.Y = 1;

PPOLYLN-> AddPoint (& xyz);

Shape.m_list.insert (Shape.m_List.end (), PPOLYLN);

Shape.DRAW ((long) PDC-> M_HDC);

}

}

Don't worry about running, there will be some assertion errors when you run. This is because you have access to space in the main program, and it is released in the DLL (Cshape's destructor releases memory), solve the memory) The method of this problem is described in detail below:

With GlobalAlloc () instead of New, use globalfree () instead of delete.

In fact, there is still a way to change the CODE GENERATION of the DLL's settings C / C tab to the Debug Multithreaded DLL, change to Multithreaded DLL in the Release version, you can use New and Delete directly, no problem

The method of comparing the specification point is generally the memory allocated by the DLL is released by DLL.

Here, the method of setting the Debug Multithreaded DLL is solved.

转载请注明原文地址:https://www.9cbs.com/read-22828.html

New Post(0)