LImageListControl::DrawItem

#include "ltwrappr.h"

virtual L_INT LImageListControl::DrawItem (pDrawItem)

pLILDRAWITEM pDrawItem;

pointer to structure

Gets the specified item from the ImageList Control.

Parameter

Description

pDrawItem

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

Returns

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 doesnt perform any further painting for the current item.

NOTE: This function will be called as described above only if the ImageList control has the L_ILS_OWNERDRAWITEM style. In other words, in order to make the control an owner-drawn one, use that style. The style can be assigned to the control when it is first created (using LImageListControl::CreateControl) or after it has been created (using SetWindowLong). For a list of available styles, refer to LTIMAGELISTCLASS Registered Class: Styles.

NOTE: Before returning from the function, ensure that the device context identified by the hDC member of the LILDRAWITEM structure has been returned to the state in which it was received.

Required DLLs and Libraries

LTDIS
LTFIL
LTIMG

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Win32, x64.

See Also

Functions:

Class Members

Topics:

Using the ImageList Control

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 20.0.2019.9.23
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2019 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help