Thread: can't get MFC to communicate with itself

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    27

    can't get MFC to communicate with itself

    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

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    589
    Haven't done mfc for awhile but I think you need to do
    pDoc->Line1.DrawLine(pDC);

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    27

    You are a legend

    Thats done the trick thanks very much, you are a star

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 08:52 PM
  2. Release MFC Programs & Dynamic MFC DLL :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-18-2002, 06:42 PM
  3. Understanding The Future of MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 04-15-2002, 09:08 PM
  4. Beginning MFC (Prosise) Part III - Now What? :: C++
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 03-03-2002, 06:58 PM
  5. MFC is Challenging :: C++
    By kuphryn in forum C++ Programming
    Replies: 8
    Last Post: 02-05-2002, 01:33 AM