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. Converting Integer to POSITION?

Converting Integer to POSITION?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
3 Posts 3 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.
  • S Offline
    S Offline
    sugumar
    wrote on last edited by
    #1

    I hv Integer Value which i need to convert as POSITION to assign starting POSITION for the collection class. CTypedPtrMap m_Contacts; POSITION pos; CString strKey; CContact* pContact; // Collection class which reads information from local file int iIndex = m_screenName.GetCurSel(); // gets cursor position from combo Now i need to assign the cursor position as POSITION for CTypedPtrMap. m_Contacts.GetNextAssoc(pos, strKey, pContact); Please inform me how to solve this?

    M D 2 Replies Last reply
    0
    • S sugumar

      I hv Integer Value which i need to convert as POSITION to assign starting POSITION for the collection class. CTypedPtrMap m_Contacts; POSITION pos; CString strKey; CContact* pContact; // Collection class which reads information from local file int iIndex = m_screenName.GetCurSel(); // gets cursor position from combo Now i need to assign the cursor position as POSITION for CTypedPtrMap. m_Contacts.GetNextAssoc(pos, strKey, pContact); Please inform me how to solve this?

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      Is the screen name the key into the contacts map? If it is, you can get that using m_screenName.GetLBText. If not, you could associate the key with the item in the combo using m_screenName.SetItemData. I assume you have a good reason for using a Map, otherwise I would suggest using a List or an Array. MFC's map classes are based on a hash-table, which means that you won't get elements out of them in the order you inserted them, or in any predictable order, so you can't just call GetStartPosition then call GetNextAssoc repeatedly. Stability. What an interesting concept. -- Chris Maunder

      1 Reply Last reply
      0
      • S sugumar

        I hv Integer Value which i need to convert as POSITION to assign starting POSITION for the collection class. CTypedPtrMap m_Contacts; POSITION pos; CString strKey; CContact* pContact; // Collection class which reads information from local file int iIndex = m_screenName.GetCurSel(); // gets cursor position from combo Now i need to assign the cursor position as POSITION for CTypedPtrMap. m_Contacts.GetNextAssoc(pos, strKey, pContact); Please inform me how to solve this?

        D Offline
        D Offline
        Diddy
        wrote on last edited by
        #3

        A POSITION is like an iterator for a collection - its not synomous with an integer. The CTypedPtrMap will be keyed by what ever you templateized it on - looking at this a string. So you can find your CContact based on a CSring easily, which is the key into the map. How did you insert into the map? Did you insert all the keys into m_screenName, then insert each CContact into the map based on the key? If so, you can do a GetText on the combo to get the text for item iIndex, then use that look up in the map. CString str; str = m_screenName.GetText(iIndex); CContact* p = NULL; BOOL b = m_Contacts.Lookup(str, p); etc If not, the only thing u can do is to advance around the map until u hit the position at iIndex: POSTION pos = m_Contacts.GetStartPosition(); int nElement = 0; while(pos != NULL && nElement++ <= iIndex) { pos = m_Contacts.GetNextAssoc(pos, strKey, pContact); } You get the idea - iterate around the map until you get to element iIndex.

        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