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. How to use SetItem() and GetItem() for ListCtrl having JPEG images?

How to use SetItem() and GetItem() for ListCtrl having JPEG images?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
4 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.
  • A Offline
    A Offline
    Atul23
    wrote on last edited by
    #1

    Hi All, I am using listctrl in which I add JPEG images loading from images saves on hard disk. To Set item in ListCtrl control I use SetItem() function as follows CString pstr = "C:\\JPEG_image"; BOOL blnCheck = mWebPagePrvListCtrl.SetItemData(iItemindex,(DWORD)pstr); But the above statement not set the value of pstr in ListCtrl. To identify which images is click by user I use following code to access data of image. as int itemIndex = mWebPagePrvListCtrl.GetHotItem(); CString* pStr = (CString*) mWebPagePrvListCtrl.GetItemData(itemIndex); Plz send me what is the problem in above code. Thanks in Advance Atul

    N 1 Reply Last reply
    0
    • A Atul23

      Hi All, I am using listctrl in which I add JPEG images loading from images saves on hard disk. To Set item in ListCtrl control I use SetItem() function as follows CString pstr = "C:\\JPEG_image"; BOOL blnCheck = mWebPagePrvListCtrl.SetItemData(iItemindex,(DWORD)pstr); But the above statement not set the value of pstr in ListCtrl. To identify which images is click by user I use following code to access data of image. as int itemIndex = mWebPagePrvListCtrl.GetHotItem(); CString* pStr = (CString*) mWebPagePrvListCtrl.GetItemData(itemIndex); Plz send me what is the problem in above code. Thanks in Advance Atul

      N Offline
      N Offline
      Nishad S
      wrote on last edited by
      #2

      CString pstr = "C:\\JPEG_image"; It is local, right?

      - NS -

      A 1 Reply Last reply
      0
      • N Nishad S

        CString pstr = "C:\\JPEG_image"; It is local, right?

        - NS -

        A Offline
        A Offline
        Atul23
        wrote on last edited by
        #3

        Hi Yes It is Local. atul

        N 1 Reply Last reply
        0
        • A Atul23

          Hi Yes It is Local. atul

          N Offline
          N Offline
          Nishad S
          wrote on last edited by
          #4

          Atulmahajan wrote:

          Yes It is Local.

          So I think you are mistaken. Actually you are trying to save the image name along with each list control item, right? SetItemData is holding only a 4 byte value. We are using this to hold a pointer. Here in your case, it is a pointer to the string. Since the string is local when you exit from the function, the pointer will not be valid. So the stored pointer has no use. One solution is that you can dynamically allocate the string in heap (using new CString). But need to delete the memory when you close the window, or delete the list control item. Another method is that you can use a CStringArray object as member variable. Then you can store each string in the array and can keep the index in the list control item data. Here also removal of the string item from the array is needed, if you delete a list control item (just for saving the memory). Hope you got the idea.

          - NS -

          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