CArray can't add
-
I have a struct struct CoData { float x; float y; }; // Adding position of mouse every left click CArray arrayPoint; CoData strRawCoords, strOut; CString m_list; if((nFlags & MK_LBUTTON) == MK_LBUTTON) { strRawCoords.x = point.x; strRawCoords.y = point.y; arrayPoint.Add(strRawCoords); } // Print out the coordinates when right click if((nFlags & MK_RBUTTON) == MK_RBUTTON) { for(int i=0;iTextOut(0,0,m_list); pDC->SetTextColor(RGB(0,0,0)); pDC->SelectObject(NormalPen); } } Cant work.
-
I have a struct struct CoData { float x; float y; }; // Adding position of mouse every left click CArray arrayPoint; CoData strRawCoords, strOut; CString m_list; if((nFlags & MK_LBUTTON) == MK_LBUTTON) { strRawCoords.x = point.x; strRawCoords.y = point.y; arrayPoint.Add(strRawCoords); } // Print out the coordinates when right click if((nFlags & MK_RBUTTON) == MK_RBUTTON) { for(int i=0;iTextOut(0,0,m_list); pDC->SetTextColor(RGB(0,0,0)); pDC->SelectObject(NormalPen); } } Cant work.
Do you see any output at all? Is all of this within your
OnMouseMove
function? If so, then the problem is one of scope.arrayPoint
is local toOnMouseMove
. WhenOnMouseMove
exits, the array is destroyed, since its a local variable ofOnMouseMove
. So every time the mouse moves and yourOnMouseMove
is called, it builds, then destroys, this array. Try moving the array out of the function and make it a member variable of your window or dialog. Hope this helps! Bob Ciora -
Do you see any output at all? Is all of this within your
OnMouseMove
function? If so, then the problem is one of scope.arrayPoint
is local toOnMouseMove
. WhenOnMouseMove
exits, the array is destroyed, since its a local variable ofOnMouseMove
. So every time the mouse moves and yourOnMouseMove
is called, it builds, then destroys, this array. Try moving the array out of the function and make it a member variable of your window or dialog. Hope this helps! Bob Ciora -
First off, did that fix the problem? :) What sorts of guides are you looking for? This website is full of guides! For general VisualStudio programming, I find the MSDN Library[^] an invaluable source of information. Bob Ciora
-
I understand but it tried to create member variable but the VC++ doesnt allow me to add CArray type of variable. I need more detail solution. I am new to VC++ but have C b/ground. THanks.
Instead of making the CArray a member of the class, just move the declaration to just above your
OnMouseMove
function. This moves it outside the function and outside the class. Effectively, it becomes a global variable *shudder* but it should still put a temporary band-aid on the problem. As for C++ in general, if you're a seasoned C programmer, see if you can find a book called "Moving From C To C++". I got this book about 10 years ago, and it's the only C++ book I've ever needed. Bob Ciora -
Instead of making the CArray a member of the class, just move the declaration to just above your
OnMouseMove
function. This moves it outside the function and outside the class. Effectively, it becomes a global variable *shudder* but it should still put a temporary band-aid on the problem. As for C++ in general, if you're a seasoned C programmer, see if you can find a book called "Moving From C To C++". I got this book about 10 years ago, and it's the only C++ book I've ever needed. Bob CioraHi thanks Do you mean outside the class or outside the onmouseover? It is actually outside the onmouseover and inside the class. Do you mean declaring as public variable? What kind of type of variable shld I use? CArray ? The VC++ doesnt allow me the declare this type. Someone in the forum mentioned to create another header file and include it before declaring it. I got a lot of errors after I did that.