| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
Re: Polyline and vector<POINT>
::PolyLine(&singlepoints[0], (int)singlepoints.size());
|
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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()); |
|
#5
|
|||
|
|||
|
Re: Polyline and vector<POINT>
Quote:
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 |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
||||
|
||||
|
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. |
|
#8
|
|||
|
|||
|
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 |
|
#9
|
||||
|
||||
|
Re: Polyline and vector<POINT>
Good point, I follow your advice
|
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|