C++ MFC

Moderators: Lundin
Number of threads: 3354
Number of posts: 9032

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
can't get MFC to communicate with itself Posted by drb2k2 on 3 Apr 2003 at 9:23 AM
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

Report
Re: can't get MFC to communicate with itself Posted by stober on 3 Apr 2003 at 7:35 PM
: 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
:
:
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.
 	ASSERT_VALID(pDoc);
 	CDC* pDC = GetDC ();
 	pDoc->Line1.DrawLine(pDC);





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.