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. Drawing from CImageList onto CButton

Drawing from CImageList onto CButton

Scheduled Pinned Locked Moved C / C++ / MFC
graphicscssdatabasejsonquestion
2 Posts 1 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.
  • T Offline
    T Offline
    Tym
    wrote on last edited by
    #1

    I have a CButton-derived class that is owner-drawn and has data members for a pointer to a CImageList and an index to select which image in the list to display. The bitmap resource that is used to create the ImageList is 8-bit and uses green as the background color to be masked. When I draw the images onto the button, the transparency mask works great, but the rest looks bad, like it might be a 4-bit image? Yet it looks fine in the resource editor. I'm missing something crucial. Thanks in advance for any advice. Tym! Here's what I'm doing more or less: The image list is created from a resource: an 8-bit bitmap strip with a green background for the masked transparent color: CImageList _defaultImages; _defaultImages.Create(IDB_BITMAP_RESOURCE_ID, _imageWidth, 32, 0x0000ff00); The Button is created dynamically: #define BTN_STYLE BS_PUSHBUTTON|WS_VISIBLE|WS_TABSTOP|WS_CHILDWINDOW|BS_NOTIFY|BS_OWNERDRAW ... CMyButton* _myButton = new CMyButton(); _myButton->Create("",BTN_STYLE,_buttonRect,this,3999); _myButton->SetImageList(&_defaultImages); _myButton->SetImageIndex(DEFAULT_IMAGE); and I am drawing the image like so: void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); UINT state = lpDrawItemStruct->itemState; ... // draw the bitmap: if (_imageList != NULL && _imageIndex != -1) { CPoint _location(2,2); // Offset the image if button is selected: if (state & ODS_SELECTED) _location.Offset(1,1); this->_imageList->Draw(pDC, _imageIndex, _location, ILD_TRANSPARENT); } ... }

    T 1 Reply Last reply
    0
    • T Tym

      I have a CButton-derived class that is owner-drawn and has data members for a pointer to a CImageList and an index to select which image in the list to display. The bitmap resource that is used to create the ImageList is 8-bit and uses green as the background color to be masked. When I draw the images onto the button, the transparency mask works great, but the rest looks bad, like it might be a 4-bit image? Yet it looks fine in the resource editor. I'm missing something crucial. Thanks in advance for any advice. Tym! Here's what I'm doing more or less: The image list is created from a resource: an 8-bit bitmap strip with a green background for the masked transparent color: CImageList _defaultImages; _defaultImages.Create(IDB_BITMAP_RESOURCE_ID, _imageWidth, 32, 0x0000ff00); The Button is created dynamically: #define BTN_STYLE BS_PUSHBUTTON|WS_VISIBLE|WS_TABSTOP|WS_CHILDWINDOW|BS_NOTIFY|BS_OWNERDRAW ... CMyButton* _myButton = new CMyButton(); _myButton->Create("",BTN_STYLE,_buttonRect,this,3999); _myButton->SetImageList(&_defaultImages); _myButton->SetImageIndex(DEFAULT_IMAGE); and I am drawing the image like so: void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); UINT state = lpDrawItemStruct->itemState; ... // draw the bitmap: if (_imageList != NULL && _imageIndex != -1) { CPoint _location(2,2); // Offset the image if button is selected: if (state & ODS_SELECTED) _location.Offset(1,1); this->_imageList->Draw(pDC, _imageIndex, _location, ILD_TRANSPARENT); } ... }

      T Offline
      T Offline
      Tym
      wrote on last edited by
      #2

      I found it. When creating the imagelist directly from the resource, the ImageList defaults to 4-bit apparently. So I has to do it the long way: CBitmap _imageBitmap _imageBitmap.LoadBitmap(IDB_BITMAP_RESOURCE_ID); CImageList _defaultImages; _defaultImages.Create(_imageWidth, _imageHeight, ILC_COLOR32|ILC_MASK, 1, 32); _defaultImages.Add(&_imageBitmap,0x0000ff00); This will create a 32-bit imagelist with a green mask from the resource.

      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