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. Creating a column with bitmaps on CListCtrl residing on a dialog

Creating a column with bitmaps on CListCtrl residing on a dialog

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestion
5 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
    JJeffrey
    wrote on last edited by
    #1

    Sorry to trouble you guys, but I think I'm missing something in my understanding of the List Control boxes. I'm creating a CListCtrl box with 3 columns. The first 2 are text and the third will show bitmaps. My code goes like this:

    void PopulateList ()
    {
    LVCOLUMN lvColumn1,lvColumn2,lvColumn3;
    COLORREF rgbMask = RGB(0,0,0); //(rgb[0].rgbtRed, rgb[0].rgbtGreen, rgb[0].rgbtBlue);
    // I believe I need to create a CImageList for the bitmap column, right?
    CImageList ThumbList;
    ThumbList.Create(MAXWIDTH, MAXHEIGHT, ILC_COLOR, 1, 1);

    //Create Column 1
    lvColumn1.mask = LVCF\_FMT | LVCF\_TEXT | LVCF\_WIDTH;
    lvColumn1.fmt = Alignment;
    lvColumn1.cx = 120;
    lvColumn1.pszText = ColumnHeading\[0\];
    nCol = m\_MainList.InsertColumn(0, &lvColumn1);
    
    int NextIndex = nCol;
    
    //Populate Column 1
    while (!EOF)
        {
          //Read the Data from File and store in "OutputTitle"
          .
          .
          LVITEM lvItem;
      lvItem.mask = LVIF\_TEXT;
      lvItem.iItem = NextIndex;
      lvItem.iSubItem = 0;
      lvItem.pszText = OutputTitle;
      NextIndex = m\_MainList.InsertItem(&lvItem);
          .
        }
    ListView\_SortItemsEx( m\_MainList.m\_hWnd, CompareProc, (LPARAM)&m\_MainList );
    
    //Create Column 2
    lvColumn2.mask = LVCF\_FMT | LVCF\_TEXT | LVCF\_WIDTH;
    lvColumn2.fmt = Alignment;
    lvColumn2.cx = 120;
    lvColumn2.pszText = ColumnHeading\[1\];
    nCol = m\_MainList.InsertColumn(1, &lvColumn2);
    
    //Populate Column 2
    int NumOfEntries = m\_MainList.GetItemCount();
    
    for(int i=0; i>NumOfEntries; i++)
    {
           //Get data based on First Column entries
           .
           .
           .
       m\_MainList.SetItemText(i,1, );
    }
    
    //Create Column 3
    lvColumn3.mask = LVCF\_FMT | LVCF\_TEXT | LVCF\_WIDTH;
    lvColumn3.fmt = Alignment;
    lvColumn3.cx = 240;
    lvColumn3.pszText = ColumnHeading\[2\];
    nCol = m\_MainList.InsertColumn(2, &lvColumn3);
    
    
    NextIndex = nCol;
    
    //Populate Column 3
    BYTE PreviewInfo\[MAXHEIGHT\]\[MAXWIDTH\]\[3\]={0};
    int ImageIndex = 0;
    
    for(int i=0; i
    		CBitmap	\*ThumbNail = new CBitmap;
    		ThumbNail->Attach(Picture );
    		ImageIndex = ThumbList.Add(ThumbNail,rgbMask);
    		m\_MainList.SetImageList(&ThumbList, LVSIL\_SMALL);
    
    		LVITEM lvItem;
    		lvItem.mask = LVIF\_IMAGE;
    		lvItem.iItem = i;              // I tried
    		lvItem.iSubItem = 0;
    		lvItem.iImage = ImageIndex;
    		NextIndex =
    
    S 1 Reply Last reply
    0
    • J JJeffrey

      Sorry to trouble you guys, but I think I'm missing something in my understanding of the List Control boxes. I'm creating a CListCtrl box with 3 columns. The first 2 are text and the third will show bitmaps. My code goes like this:

      void PopulateList ()
      {
      LVCOLUMN lvColumn1,lvColumn2,lvColumn3;
      COLORREF rgbMask = RGB(0,0,0); //(rgb[0].rgbtRed, rgb[0].rgbtGreen, rgb[0].rgbtBlue);
      // I believe I need to create a CImageList for the bitmap column, right?
      CImageList ThumbList;
      ThumbList.Create(MAXWIDTH, MAXHEIGHT, ILC_COLOR, 1, 1);

      //Create Column 1
      lvColumn1.mask = LVCF\_FMT | LVCF\_TEXT | LVCF\_WIDTH;
      lvColumn1.fmt = Alignment;
      lvColumn1.cx = 120;
      lvColumn1.pszText = ColumnHeading\[0\];
      nCol = m\_MainList.InsertColumn(0, &lvColumn1);
      
      int NextIndex = nCol;
      
      //Populate Column 1
      while (!EOF)
          {
            //Read the Data from File and store in "OutputTitle"
            .
            .
            LVITEM lvItem;
        lvItem.mask = LVIF\_TEXT;
        lvItem.iItem = NextIndex;
        lvItem.iSubItem = 0;
        lvItem.pszText = OutputTitle;
        NextIndex = m\_MainList.InsertItem(&lvItem);
            .
          }
      ListView\_SortItemsEx( m\_MainList.m\_hWnd, CompareProc, (LPARAM)&m\_MainList );
      
      //Create Column 2
      lvColumn2.mask = LVCF\_FMT | LVCF\_TEXT | LVCF\_WIDTH;
      lvColumn2.fmt = Alignment;
      lvColumn2.cx = 120;
      lvColumn2.pszText = ColumnHeading\[1\];
      nCol = m\_MainList.InsertColumn(1, &lvColumn2);
      
      //Populate Column 2
      int NumOfEntries = m\_MainList.GetItemCount();
      
      for(int i=0; i>NumOfEntries; i++)
      {
             //Get data based on First Column entries
             .
             .
             .
         m\_MainList.SetItemText(i,1, );
      }
      
      //Create Column 3
      lvColumn3.mask = LVCF\_FMT | LVCF\_TEXT | LVCF\_WIDTH;
      lvColumn3.fmt = Alignment;
      lvColumn3.cx = 240;
      lvColumn3.pszText = ColumnHeading\[2\];
      nCol = m\_MainList.InsertColumn(2, &lvColumn3);
      
      
      NextIndex = nCol;
      
      //Populate Column 3
      BYTE PreviewInfo\[MAXHEIGHT\]\[MAXWIDTH\]\[3\]={0};
      int ImageIndex = 0;
      
      for(int i=0; i
      		CBitmap	\*ThumbNail = new CBitmap;
      		ThumbNail->Attach(Picture );
      		ImageIndex = ThumbList.Add(ThumbNail,rgbMask);
      		m\_MainList.SetImageList(&ThumbList, LVSIL\_SMALL);
      
      		LVITEM lvItem;
      		lvItem.mask = LVIF\_IMAGE;
      		lvItem.iItem = i;              // I tried
      		lvItem.iSubItem = 0;
      		lvItem.iImage = ImageIndex;
      		NextIndex =
      
      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      JJeffrey wrote:

      lvItem.iSubItem = 0;

      Try changing that line to

      lvItem.iSubItem = nCol; // where nCol is the result of the line 'nCol = m_MainList.InsertColumn(2, &lvColumn3);'

      ?

      J 1 Reply Last reply
      0
      • S Stuart Dootson

        JJeffrey wrote:

        lvItem.iSubItem = 0;

        Try changing that line to

        lvItem.iSubItem = nCol; // where nCol is the result of the line 'nCol = m_MainList.InsertColumn(2, &lvColumn3);'

        ?

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

        No change in output. Column 1 data disappears. Column 3 remains empty

        S 1 Reply Last reply
        0
        • J JJeffrey

          No change in output. Column 1 data disappears. Column 3 remains empty

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          I'm an f-ing idiot at times.... First problem - you've made your image-list local to the PopulateList function - it needs to be alive as long as the list control is alive (makes sense?), so declare it at class scope with the list control variable. Second problem - the image index refers to the optional icon that can be to the left of the text in the first column. You can only put text in the rest of the columns - that's the bit I should have remembered :doh: To get images in an arbitrary column, you need to use custom-draw. Or a ready-written list control sub-class, like the ones here on CodeProject[^]. This one[^], for example, allows images in any column.

          J 1 Reply Last reply
          0
          • S Stuart Dootson

            I'm an f-ing idiot at times.... First problem - you've made your image-list local to the PopulateList function - it needs to be alive as long as the list control is alive (makes sense?), so declare it at class scope with the list control variable. Second problem - the image index refers to the optional icon that can be to the left of the text in the first column. You can only put text in the rest of the columns - that's the bit I should have remembered :doh: To get images in an arbitrary column, you need to use custom-draw. Or a ready-written list control sub-class, like the ones here on CodeProject[^]. This one[^], for example, allows images in any column.

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

            Thanks again. I'm still trying to work out the solution after shifting everything to the CQuickList class. Took me a while to figure out how to use the class even with the webpage. Thanks.

            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