本文整理汇总了C++中CGridListCtrlEx::SetImageList方法的典型用法代码示例。如果您正苦于以下问题:C++ CGridListCtrlEx::SetImageList方法的具体用法?C++ CGridListCtrlEx::SetImageList怎么用?C++ CGridListCtrlEx::SetImageList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGridListCtrlEx
的用法示例。
在下文中一共展示了CGridListCtrlEx::SetImageList方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AppendStateImages
//------------------------------------------------------------------------
//! Appends the checkbox state images to the list control image list
//!
//! @param owner The list control adding column
//! @param imagelist The image list assigned to the list control
//! @return Image index where the two state images (unchecked/checked) was inserted
//------------------------------------------------------------------------
int CGridColumnTraitImage::AppendStateImages(CGridListCtrlEx& owner, CImageList& imagelist)
{
if (!(owner.GetExtendedStyle() & LVS_EX_SUBITEMIMAGES))
owner.SetExtendedStyle(owner.GetExtendedStyle() | LVS_EX_SUBITEMIMAGES);
if (!imagelist)
imagelist.Create(16, 16, ILC_COLOR16 | ILC_MASK, 1, 0);
if (!owner.GetImageList(LVSIL_SMALL))
owner.SetImageList(&imagelist, LVSIL_SMALL);
VERIFY( owner.GetImageList(LVSIL_SMALL)==&imagelist );
bool createdStateImages = false;
CImageList* pStateList = owner.GetImageList(LVSIL_STATE);
if (pStateList==NULL)
{
if (!(owner.GetExtendedStyle() & LVS_EX_CHECKBOXES))
{
createdStateImages = true;
owner.SetExtendedStyle(owner.GetExtendedStyle() | LVS_EX_CHECKBOXES);
pStateList = owner.GetImageList(LVSIL_STATE);
}
}
int imageCount = -1;
ASSERT(pStateList!=NULL);
if (pStateList!=NULL)
{
imageCount = imagelist.GetImageCount();
HICON uncheckedIcon = pStateList->ExtractIcon(0);
imagelist.Add(uncheckedIcon);
DestroyIcon(uncheckedIcon);
HICON checkedIcon = pStateList->ExtractIcon(1);
imagelist.Add(checkedIcon);
DestroyIcon(checkedIcon);
}
if (createdStateImages)
owner.SetExtendedStyle(owner.GetExtendedStyle() & ~LVS_EX_CHECKBOXES);
return imageCount;
}
示例2: AppendStateImages
//------------------------------------------------------------------------
//! Appends the checkbox state images to the list control image list
//!
//! @param owner The list control adding column
//! @param imagelist The image list assigned to the list control
//! @return Image index where the two state images (unchecked/checked) was inserted
//------------------------------------------------------------------------
int CGridColumnTraitImage::AppendStateImages(CGridListCtrlEx& owner, CImageList& imagelist)
{
if (!(owner.GetExtendedStyle() & LVS_EX_SUBITEMIMAGES))
owner.SetExtendedStyle(owner.GetExtendedStyle() | LVS_EX_SUBITEMIMAGES);
if (!imagelist)
imagelist.Create(16, 16, ILC_COLOR16 | ILC_MASK, 1, 0);
if (!owner.GetImageList(LVSIL_SMALL))
owner.SetImageList(&imagelist, LVSIL_SMALL);
VERIFY(owner.GetImageList(LVSIL_SMALL) == &imagelist);
bool createdStateImages = false;
CImageList* pStateList = owner.GetImageList(LVSIL_STATE);
if (pStateList == NULL)
{
if (!(owner.GetExtendedStyle() & LVS_EX_CHECKBOXES))
{
createdStateImages = true;
owner.SetExtendedStyle(owner.GetExtendedStyle() | LVS_EX_CHECKBOXES);
pStateList = owner.GetImageList(LVSIL_STATE);
}
}
int imageCount = -1;
ASSERT(pStateList != NULL);
if (pStateList != NULL && pStateList->GetImageCount() >= 2)
{
imageCount = imagelist.GetImageCount();
// Get the icon size of current imagelist
CSize iconSize(16, 16);
if (imageCount > 0)
{
IMAGEINFO iconSizeInfo = { 0 };
VERIFY(imagelist.GetImageInfo(0, &iconSizeInfo));
iconSize =
CSize(iconSizeInfo.rcImage.right - iconSizeInfo.rcImage.left,
iconSizeInfo.rcImage.bottom - iconSizeInfo.rcImage.top);
}
// Scale the icon-position if necessary
CPoint iconPos(1, 0); // +1 pixel to avoid overlap with left-grid-line
{
IMAGEINFO stateSizeInfo = { 0 };
VERIFY(pStateList->GetImageInfo(0, &stateSizeInfo));
int stateIconHeight = stateSizeInfo.rcImage.bottom - stateSizeInfo.rcImage.top;
if (iconSize.cy > stateIconHeight)
iconPos.y = (iconSize.cy - stateIconHeight) / 2;
}
// Redraw the state-icon to match the icon size of the current imagelist (without scaling image)
CClientDC clienDC(&owner);
CDC memDC;
VERIFY(memDC.CreateCompatibleDC(&clienDC));
CBitmap dstBmp;
VERIFY(dstBmp.CreateCompatibleBitmap(&clienDC, iconSize.cx, iconSize.cy));
CBitmap* pBmpOld = memDC.SelectObject(&dstBmp);
COLORREF oldBkColor = pStateList->SetBkColor(imagelist.GetBkColor());
CBrush brush(imagelist.GetBkColor());
memDC.FillRect(CRect(0, 0, iconSize.cx, iconSize.cy), &brush);
VERIFY(pStateList->Draw(&memDC, 0, iconPos, ILD_NORMAL));
memDC.SelectObject(pBmpOld);
VERIFY(imagelist.Add(&dstBmp, oldBkColor) != -1);
pBmpOld = memDC.SelectObject(&dstBmp);
memDC.FillRect(CRect(0, 0, iconSize.cx, iconSize.cy), &brush);
VERIFY(pStateList->Draw(&memDC, 1, iconPos, ILD_NORMAL));
memDC.SelectObject(pBmpOld);
VERIFY(imagelist.Add(&dstBmp, oldBkColor) != -1);
pStateList->SetBkColor(oldBkColor);
}
if (createdStateImages)
owner.SetExtendedStyle(owner.GetExtendedStyle() & ~LVS_EX_CHECKBOXES);
return imageCount;
}