Gets the specified item from the ImageList Control.
#include "ltwrappr.h"
virtual L_INT LImageListControl::DrawItem (pDrawItem)
Pointer to an LILDRAWITEM structure that contains information about the item to be painted.
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. |
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
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.
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.
Win32, x64.
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 Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document