LImageListControl::DrawItem

Summary

Gets the specified item from the ImageList Control.

Syntax

#include "ltwrappr.h"

virtual L_INT LImageListControl::DrawItem (pDrawItem)

Parameters

pLILDRAWITEM pDrawItem

Pointer to an LILDRAWITEM structure that contains information about the item to be painted.

Returns

Value Meaning
ERROR_USER_ABORT The ImageListControl will not perform any further painting on the current item.
<> ERROR_USER_ABORT Returning any other value will cause the ImageListControl to paint the current item normally.

Comments

This function gets called whenever an item in the image list needs to be painted/repainted, such as when the item is first drawn, when part of it is covered by a window, or when its selection state changes. The function is passed a pointer to an LILDRAWITEM structure which contains information about the item. The passed information is necessary to paint the item.

The LImageListControl version of this function simply returns SUCCESS, which is not ERROR_USER_ABORT, and so the ImageList control paints the items normally. In order to customize the function, derive a new class from LImageListControl and override LImageListControl::DrawItem, adding the necessary code for drawing the items. (Create the object from the new class.) The overriding version should return ERROR_USER_ABORT so that the ImageList control does not perform any further painting for the current item.

NOTES

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

The following example creates a new class derived from LImageListControl and overrides the LImageListControl::DrawItem function to draw the items of an image list in its own way.

class LUserImageListControl : public LImageListControl 
{ 
   virtual L_INT DrawItem(pLILDRAWITEM pDrawItem) 
   { 
      if (!pDrawItem) 
         return SUCCESS; 
 
      if (!pDrawItem->pItem) 
         return SUCCESS; 
 
      LBitmapBase Bitmap; 
      HRGN hRgn; 
      RECT rcImage, rcText; 
 
      CopyRect(&rcImage, &pDrawItem->rcItem); 
      rcImage.bottom = rcImage.top 
                       + 3 * (rcImage.bottom - rcImage.top) / 4; 
      SubtractRect(&rcText, &pDrawItem->rcItem, &rcImage); 
      InflateRect(&rcImage, -1, -1); 
 
      hRgn = CreateEllipticRgn(rcImage.left, rcImage.top,  
                               rcImage.right, rcImage.bottom); 
 
      SaveDC(pDrawItem->hDC); 
       
      if (pDrawItem->pItem->bSelected) 
      { 
         SelectObject(pDrawItem->hDC, 
                     (HBRUSH) GetStockObject(WHITE_BRUSH)); 
         SetTextColor(pDrawItem->hDC, RGB(0, 0, 0)); 
      } 
      else 
      { 
         SelectObject(pDrawItem->hDC, 
                     (HBRUSH) GetStockObject(BLACK_BRUSH)); 
         SetTextColor(pDrawItem->hDC, RGB(255, 255, 255)); 
      } 
 
      Rectangle(pDrawItem->hDC, pDrawItem->rcItemBack.left, 
                                pDrawItem->rcItemBack.top, 
                                pDrawItem->rcItemBack.right, 
                                pDrawItem->rcItemBack.bottom); 
 
      SetBkMode(pDrawItem->hDC, TRANSPARENT); 
      if (pDrawItem->pItem->pText && lstrlen(pDrawItem->pItem->pText)) 
         DrawText(pDrawItem->hDC, pDrawItem->pItem->pText,  
                   lstrlen(pDrawItem->pItem->pText), &rcText,  
                   DT_SINGLELINE | DT_CENTER | DT_VCENTER); 
 
      SelectObject(pDrawItem->hDC, hRgn); 
      Bitmap.SetHandle(pDrawItem->pItem->pBitmap); 
      Bitmap.SetSrcRect(NULL); 
      Bitmap.SetClipSrcRect(NULL); 
      Bitmap.SetDstRect(&rcImage); 
      Bitmap.SetClipDstRect(NULL); 
      Bitmap.Paint()->SetDC(pDrawItem->hDC); 
      Bitmap.Paint()->PaintDC(); 
 
      MoveMemory(pDrawItem->pItem->pBitmap, Bitmap.GetHandle(),  
     sizeof(BITMAPHANDLE)); 
      Bitmap.SetHandle(NULL, FALSE); 
 
      RestoreDC(pDrawItem->hDC, -1); 
      DeleteObject(hRgn); 
 
      return ERROR_USER_ABORT; 
   } 
}; 

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.