Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CArray can't add

CArray can't add

Scheduled Pinned Locked Moved C / C++ / MFC
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jw81
    wrote on last edited by
    #1

    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.

    B 1 Reply Last reply
    0
    • J jw81

      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.

      B Offline
      B Offline
      Bob Ciora
      wrote on last edited by
      #2

      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 to OnMouseMove. When OnMouseMove exits, the array is destroyed, since its a local variable of OnMouseMove. So every time the mouse moves and your OnMouseMove 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

      J 1 Reply Last reply
      0
      • B 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 to OnMouseMove. When OnMouseMove exits, the array is destroyed, since its a local variable of OnMouseMove. So every time the mouse moves and your OnMouseMove 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

        J Offline
        J Offline
        jw81
        wrote on last edited by
        #3

        Hi thanks, Can you give me some guides?

        B 1 Reply Last reply
        0
        • J jw81

          Hi thanks, Can you give me some guides?

          B Offline
          B Offline
          Bob Ciora
          wrote on last edited by
          #4

          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

          J 1 Reply Last reply
          0
          • B 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

            J Offline
            J Offline
            jw81
            wrote on last edited by
            #5

            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.

            B 1 Reply Last reply
            0
            • J jw81

              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.

              B Offline
              B Offline
              Bob Ciora
              wrote on last edited by
              #6

              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

              J 1 Reply Last reply
              0
              • B 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 Ciora

                J Offline
                J Offline
                jw81
                wrote on last edited by
                #7

                Hi 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.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups