The sample shows use of images in cells.
Class CGridView is determined from parent class CALXGridView. In it's constructor are added column (function AddCol()) and defined
type control (function DefineColCtrl()). Cells columns are defined as a cell containing the image (function
DefineImage()). DIT_BITMAP - bitmap the image, DIT_ICON - an icon, DIT_IMGLIST - the image
from the list (class CImageList).
CGridView::CGridView()
{
// Bitmap
DefineColCtrl(AddCol(180,"Bitmap && LeftText",
ACFF_LEFT, AHFF_LEFT),GA_EDITCTRL,WS_CHILD | ES_LEFT | ES_AUTOHSCROLL);
DefineImage(0,7,7,DIT_BITMAP);
// Icon
DefineColCtrl(AddCol(180,"Icon && CenterText",
ACFF_CENTER, AHFF_CENTER),GA_EDITCTRL,WS_CHILD | ES_CENTER | ES_AUTOHSCROLL);
DefineImage(1,9,9,DIT_ICON);
// ImageList
DefineColCtrl(AddCol(180,"ImageList && RightText",
ACFF_RIGHT, AHFF_RIGHT),GA_EDITCTRL,WS_CHILD | ES_RIGHT | ES_AUTOHSCROLL);
DefineImage(2,15,15,DIT_IMGLIST);
m_BMP.LoadBitmap(IDB_BITMAP);
VERIFY(m_ImageList.Create(IDB_BITMAP_IMGLIST, 15, 1,
(COLORREF)0x808000));
SetGridRowCount(10000);
}
Also virtual functions GetCellData() (returns the data cells
necessary for display), GetImage() (return index on the
image of a cell, for cells DIT_BITMAP and DIT_ICON), GetImageListDrawParams() (returns the
index on the image of a cell and his parameters, for cells DIT_IMGLIST) are redefined.
LPARAM CGridView::GetImage(int nCol, int nRow, BOOL bSelected)
{
if(nCol == 0)
return (LPARAM)(HBITMAP)m_BMP;
if(nCol == 1)
return
(LPARAM)m_ImageList.ExtractIcon(bSelected ? 1 : 0);
return NULL;
}
void CGridView::GetImageListDrawParams(int
nCol, int nRow, IMAGELISTDRAWPARAMS* pimldp, BOOL bSelected)
{
pimldp->himl = m_ImageList.m_hImageList;
if(bSelected)
pimldp->fStyle = ILD_SELECTED;
pimldp->i = 0;
}
|