CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 5th, 2009, 04:19 AM
    npuleio npuleio is offline
    Member
     
    Join Date: Aug 2009
    Posts: 46
    npuleio is an unknown quantity at this point (<10)
    Polyline and vector<POINT>

    Hello everyone...

    I'm trying to use CDC::PolyLine to draw some lines and I'm storing
    values with:

    typedef vector<POINT> points;
    typedef vector<points> matrix_points;

    matrix_points mPoints; // which would be an array of arrays
    ...
    points singlepoints(mPoints[0]);
    ::PolyLine(&singlepoints, sizeof(singlepoints));

    but it reports a conversion error on first parameter of PolyLine (cannot convert parameter 1 from 'points *' to 'const POINT *')...why?... that vector<POINT> is anyway an array of POINT...

    Thanks to all
    Ciao
    Luigi
    Reply With Quote
      #2    
    Old November 5th, 2009, 05:29 AM
    Alex F's Avatar
    Alex F Alex F is offline
    Senior Member
     
    Join Date: Jul 2002
    Posts: 1,512
    Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)
    Re: Polyline and vector<POINT>

    ::PolyLine(&singlepoints[0], (int)singlepoints.size());
    Reply With Quote
      #3    
    Old November 5th, 2009, 05:38 AM
    npuleio npuleio is offline
    Member
     
    Join Date: Aug 2009
    Posts: 46
    npuleio is an unknown quantity at this point (<10)
    Re: Polyline and vector<POINT>

    HI AlexF,

    first thanks for your reply...
    But isn't this &singlepoints[0] in fact the first element of the array of POINT when Polyline wants the entire array as defined in the help guide?...

    As you can see, I coded:

    points singlepoints(mPoints[0]);

    which is the first line of array of POINT arrays then you can implement:

    singlepoints.at(0).x

    or shall I have missed/misunderstood something?...

    Ciao
    Luigi
    Reply With Quote
      #4    
    Old November 5th, 2009, 06:35 AM
    Alex F's Avatar
    Alex F Alex F is offline
    Senior Member
     
    Join Date: Jul 2002
    Posts: 1,512
    Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)
    Re: Polyline and vector<POINT>

    According to C++ statdatd, vector class keeps its elements in contiguous memory block, like plain array. Therefore, it is possible to take a pointer to vector element and use it as plain pointer.
    (&singlepoints[0], (int)singlepoints.size()
    this means: pointer to array kept in the vector, and number of elements in this array.
    Your &singlepoints does not make sence, this is just pointer to vector instance, and not to vector data.

    points singlepoints(mPoints[0]);
    I don't understand what this line means, possibly it is incorrect. Don't copy vector instances.

    //points singlepoints(mPoints[0]);
    //::PolyLine(&singlepoints[0], (int)singlepoints.size());

    ::PolyLine(&m_Points[0][0], (int)m_Points[0].size());

    Or:
    points* singlepoints = &mPoints[0];
    ::PolyLine(&(*singlepoints)[0], (int)singlepoints->size());
    Reply With Quote
      #5    
    Old November 5th, 2009, 06:47 AM
    Paul McKenzie Paul McKenzie is offline
    Elite Member
    Power Poster
     
    Join Date: Apr 1999
    Posts: 20,404
    Paul McKenzie has a reputation beyond repute (3000+)Paul McKenzie has a reputation beyond repute (3000+)Paul McKenzie has a reputation beyond repute (3000+)Paul McKenzie has a reputation beyond repute (3000+)Paul McKenzie has a reputation beyond repute (3000+)Paul McKenzie has a reputation beyond repute (3000+)Paul McKenzie has a reputation beyond repute (3000+)Paul McKenzie has a reputation beyond repute (3000+)Paul McKenzie has a reputation beyond repute (3000+)Paul McKenzie has a reputation beyond repute (3000+)Paul McKenzie has a reputation beyond repute (3000+)
    Re: Polyline and vector<POINT>

    Quote:
    Originally Posted by npuleio View Post
    but it reports a conversion error on first parameter of PolyLine (cannot convert parameter 1 from 'points *' to 'const POINT *')...why?... that vector<POINT> is anyway an array of POINT...
    No.

    A vector<POINT> is a class that wraps an array of points. A vector<POINT> itself is not an array of points.

    Think of a vector like a car garage. To drive the car, you must get into the garage first, and then start the car -- you don't "start the garage" to drive the car.

    Same thing with vector -- to get to the array in the vector, you have to get inside of the vector, and Alex F shows you how to get to the array that's in the vector class.

    Regards,

    Paul McKenzie
    Reply With Quote
      #6    
    Old November 5th, 2009, 08:55 AM
    npuleio npuleio is offline
    Member
     
    Join Date: Aug 2009
    Posts: 46
    npuleio is an unknown quantity at this point (<10)
    Re: Polyline and vector<POINT>

    Uhm.... so I tried this approach suggested:

    CPen qPolylinePen(PS_SOLID, 1, RGB(255,0,0)); // which is red
    CClientDC dc(this);
    dc.SelectObject(qPolylinePen);
    points* singlepoints = &mPoints[0];
    dc.PolyLine(&(*singlepoints)[0], (int)singlepoints->size());
    qPolylinePen.DeleteObject();

    then I watched *singlepoints and I see in it the values but when I look at the form I doesn't see the red lines...

    Here how I set points to pass to Polyline():

    CRect rc;
    GetWindowRect(&rc);
    ScreenToClient(&rc);
    for(...)
    mPoints[0].at(i).x= numbers from 0 to rc.right;
    mPoints[0].at(i).y=rc.bottom-1;

    May I have missed something?...

    thanks again
    Ciao
    Luigi
    Reply With Quote
      #7    
    Old November 5th, 2009, 09:01 AM
    Alex F's Avatar
    Alex F Alex F is offline
    Senior Member
     
    Join Date: Jul 2002
    Posts: 1,512
    Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)
    Re: Polyline and vector<POINT>

    Just fill mPoints with something simple, like:
    (0,0) (100, 100) (200, 300) and test this. If you see result on the screen, fill mPoints with values you need. Solve one problem at every step.
    Reply With Quote
      #8    
    Old November 5th, 2009, 09:51 AM
    npuleio npuleio is offline
    Member
     
    Join Date: Aug 2009
    Posts: 46
    npuleio is an unknown quantity at this point (<10)
    Re: Polyline and vector<POINT>

    Found it.... I couldn't use CClientDC but CMemDC otherwise it won't draw on the screen...
    Thanks again to AlexF and to Paul which with the example of car garage made me getting the point about writing the [0] to vector variable! :-)

    A fresh beer for you two!
    Ciao
    Luigi
    Reply With Quote
      #9    
    Old November 5th, 2009, 09:57 AM
    Alex F's Avatar
    Alex F Alex F is offline
    Senior Member
     
    Join Date: Jul 2002
    Posts: 1,512
    Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)Alex F is a glorious beacon of light (400+)
    Re: Polyline and vector<POINT>

    Quote:
    Originally Posted by npuleio View Post
    A fresh beer for you two!
    Luigi
    Good point, I follow your advice
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 12:55 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009