I’m having real problems getting MFC to communicate with itself. It seems that everything I define in the document is forgotten when the view file is run.
All I want a function to do is to draw a line based on XY co ordinates held in an array.
class CLine : public CObject
{
public:
int m_Cost;
int m_Penalty;
int m_Length;
int m_XYCoOrds[10][2];
//function definitions
void RandomCoOrd(void);// set the genes
void DrawLine(CDC* pDC) const;//draw the line
//int SectionLength(int m_XYCoOrds[][2]);//returns length of section
//int ncrosses(int m_XYCoOrds[][2]);//gets the number of lines crossed
};
The Coordinates are random numbers that are stored in the XYCoOrds Array. Where [i][0] is X and [i][1] is Y. for each point. A line should then be drawn to the next point i.e. [i+1][0], [i+1][1]
There will be 10 such objects of this type with the names line1, line2 etc….
Whenever a new document is initialised I want the lines to be different so I have put the following into the doc.cpp file
BOOL CThursDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
Line1.RandomCoOrd();
The randomCoOrd function fills the XY array.
Now all I want to do is to draw the line. I have defined a menu item called line1 to show Line1. Add put the following code into it:
CThursDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CDC* pDC = GetDC ();
Line1.DrawLine(pDC);
I thought that GetDocument was meant to let view see all the objects created in the DOC file. When I try and run this however it says that Lines1 is an undeclared identifier. PLEASE tell me where I am going wrong, I am literally tearing my hair out over this one.
Thanks
Dylan