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

CListCtrl

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

    I have used the CListCtrl example 'LVCustomDraw' to create a list control with colored columns. This works fine until I add an imagelist (BITMAP) to the list control. My class is derived from the CListCtrl class, and I use two functions 'OnEraseBkgnd' and 'OnCustomDraw' to color the alternate columns. The list control and imagelist are defined in the dialog class header ... CListCtrlEx m_ctlList; CImageList m_cImageListNormal, m_cImageListSmall, m_cImageListState; ... and the bitmap is add in the dialog class ... // Create 256 color image lists HIMAGELIST hList = ImageList_Create(32,32, ILC_COLOR8 |ILC_MASK , 8, 1); m_cImageListNormal.Attach(hList); hList = ImageList_Create(16, 16, ILC_COLOR8 | ILC_MASK, 8, 1); m_cImageListSmall.Attach(hList); // Load the large icons CBitmap cBmp; cBmp.LoadBitmap(IDB_IMAGES_NORMAL); m_cImageListNormal.Add(&cBmp, RGB(255, 0, 255)); //m_colRow1 cBmp.DeleteObject(); // Load the small icons cBmp.LoadBitmap(IDB_IMAGES_SMALL); m_cImageListSmall.Add(&cBmp, RGB(255,0,255)); // Attach them m_ctlList.SetImageList(&m_cImageListNormal, LVSIL_NORMAL); m_ctlList.SetImageList(&m_cImageListSmall, LVSIL_SMALL); ... The columns and items are then added. I assume the default color of the list control is white, and the image is transparent, but when the background is redrawn, the image is not being 'refreshed', and hence it appears to have a white background. I have noticed another example on CodeProject that has a similar result when the image is added. Thank you Steve

    N 1 Reply Last reply
    0
    • S Steve144

      I have used the CListCtrl example 'LVCustomDraw' to create a list control with colored columns. This works fine until I add an imagelist (BITMAP) to the list control. My class is derived from the CListCtrl class, and I use two functions 'OnEraseBkgnd' and 'OnCustomDraw' to color the alternate columns. The list control and imagelist are defined in the dialog class header ... CListCtrlEx m_ctlList; CImageList m_cImageListNormal, m_cImageListSmall, m_cImageListState; ... and the bitmap is add in the dialog class ... // Create 256 color image lists HIMAGELIST hList = ImageList_Create(32,32, ILC_COLOR8 |ILC_MASK , 8, 1); m_cImageListNormal.Attach(hList); hList = ImageList_Create(16, 16, ILC_COLOR8 | ILC_MASK, 8, 1); m_cImageListSmall.Attach(hList); // Load the large icons CBitmap cBmp; cBmp.LoadBitmap(IDB_IMAGES_NORMAL); m_cImageListNormal.Add(&cBmp, RGB(255, 0, 255)); //m_colRow1 cBmp.DeleteObject(); // Load the small icons cBmp.LoadBitmap(IDB_IMAGES_SMALL); m_cImageListSmall.Add(&cBmp, RGB(255,0,255)); // Attach them m_ctlList.SetImageList(&m_cImageListNormal, LVSIL_NORMAL); m_ctlList.SetImageList(&m_cImageListSmall, LVSIL_SMALL); ... The columns and items are then added. I assume the default color of the list control is white, and the image is transparent, but when the background is redrawn, the image is not being 'refreshed', and hence it appears to have a white background. I have noticed another example on CodeProject that has a similar result when the image is added. Thank you Steve

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      try calling the CImageList::SetBkColor() and then check whether the background has changed or not.

      nave

      S 1 Reply Last reply
      0
      • N Naveen

        try calling the CImageList::SetBkColor() and then check whether the background has changed or not.

        nave

        S Offline
        S Offline
        Steve144
        wrote on last edited by
        #3

        I tried setting the background color in the OnInitDialog() function. No change ... Next I tried CImageList *img = (CImageList *) CListCtrlEx::GetDlgItem (IDB_IMAGES_SMALL); ASSERT ( img != NULL ); but the return value of img is NULL.

        N 1 Reply Last reply
        0
        • S Steve144

          I tried setting the background color in the OnInitDialog() function. No change ... Next I tried CImageList *img = (CImageList *) CListCtrlEx::GetDlgItem (IDB_IMAGES_SMALL); ASSERT ( img != NULL ); but the return value of img is NULL.

          N Offline
          N Offline
          Naveen
          wrote on last edited by
          #4

          Steve144 wrote:

          CImageList *img = (CImageList *) CListCtrlEx::GetDlgItem (IDB_IMAGES_SMALL);

          What are you tryig to do?? To get the image list in a list control there is a function called GetImageList()...

          nave

          S 1 Reply Last reply
          0
          • N Naveen

            Steve144 wrote:

            CImageList *img = (CImageList *) CListCtrlEx::GetDlgItem (IDB_IMAGES_SMALL);

            What are you tryig to do?? To get the image list in a list control there is a function called GetImageList()...

            nave

            S Offline
            S Offline
            Steve144
            wrote on last edited by
            #5

            Oops - not a good bit of code ... I have inserted the following code in the OnCustomDraw() function, and there is no change in B/G color of the listview image CImageList *imgS = (CImageList *) CListCtrlEx::GetImageList ( LVSIL_SMALL ); ASSERT ( imgS != NULL ); CImageList *imgN = (CImageList *) CListCtrlEx::GetImageList ( LVSIL_NORMAL ); ASSERT ( imgN != NULL ); ..... case CDDS_SUBITEM | CDDS_PREPAINT | CDDS_ITEM: { imgS->SetBkColor ( RGB(225, 225, 225) ); imgN->SetBkColor ( RGB(225, 225, 225) );

            N 1 Reply Last reply
            0
            • S Steve144

              Oops - not a good bit of code ... I have inserted the following code in the OnCustomDraw() function, and there is no change in B/G color of the listview image CImageList *imgS = (CImageList *) CListCtrlEx::GetImageList ( LVSIL_SMALL ); ASSERT ( imgS != NULL ); CImageList *imgN = (CImageList *) CListCtrlEx::GetImageList ( LVSIL_NORMAL ); ASSERT ( imgN != NULL ); ..... case CDDS_SUBITEM | CDDS_PREPAINT | CDDS_ITEM: { imgS->SetBkColor ( RGB(225, 225, 225) ); imgN->SetBkColor ( RGB(225, 225, 225) );

              N Offline
              N Offline
              Naveen
              wrote on last edited by
              #6

              Steve144 wrote:

              imgS->SetBkColor ( RGB(225, 225, 225) );

              I think you want to change the white background of the image. But the above code will set the background of the image as white itself. Try using some other color say. imgS->SetBkColor ( RGB(255,0,0) );// Red COlOR

              nave

              S 1 Reply Last reply
              0
              • N Naveen

                Steve144 wrote:

                imgS->SetBkColor ( RGB(225, 225, 225) );

                I think you want to change the white background of the image. But the above code will set the background of the image as white itself. Try using some other color say. imgS->SetBkColor ( RGB(255,0,0) );// Red COlOR

                nave

                S Offline
                S Offline
                Steve144
                wrote on last edited by
                #7

                Nave, The color is grey (225,225,225). I have changed to red, but no change is B/G color of image

                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