Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

can't get MFC to communicate with itself

drb2k2drb2k2 Posts: 1Member
Im 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

Comments

  • stoberstober Posts: 9,765Member ✭✭✭
    : Im 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
    :
    :
    [blue]Where is Line1 defined? I couldn't see it in the code that you posted. If you declare it in your document class's .h file it will be persistent from one call to the next. It works just like a member of any class in C++. Here, I'm assuming you made Line1 a member object of you document class.
    [code]
    ASSERT_VALID(pDoc);
    CDC* pDC = GetDC ();
    [red]pDoc->[/red]Line1.DrawLine(pDC);
    [/code]

Sign In or Register to comment.