Re: VISTA & MFC icon
"Matrixinline" <anup.kataria@gmail.com> wrote in message
news:1184054800.003716.136660@j4g2000prf.googlegroups.com...
Here is some code
m_oList.GetClientRect(mRect);
CImageList* mImageList = new CImageList();
ASSERT(mImageList != NULL); // serious allocation failure checking
mImageList->Create(14,11,ILC_COLORDDB,1,1);
mImageList->SetBkColor(RGB(255,255,255));
mImageList->Add(AfxGetApp()->LoadIcon(IDI_ICON1));
mImageList->Add(AfxGetApp()->LoadIcon(IDI_ICON2));
mImageList->Add(AfxGetApp()->LoadIcon(IDI_ICON3));
int iSubItemSize = mRect->Width()-
MapDialogUnitX(14*2,NULL); // Added for the DPI Settings
m_oList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVIF_IMAGE |
LVS_NOCOLUMNHEADER |LVS_EX_SUBITEMIMAGES );
m_oList.InsertColumn(0,_T("User One"),LVCFMT_LEFT,20);
m_oList.InsertColumn(1,_T("User Two"),LVCFMT_LEFT,20);
m_oList.InsertColumn(2,_T("User Three"),LVCFMT_LEFT,iSubItemSize-10);
//// Map Dialog
int MapDialogUnitX(int iX, CWnd* pWnd) For Change in DPI
{
CRect rect(0, 0, iX, 0);
MapDialogRect(&rect);
iX = rect.right;
return iX;
}
A few things to check:
1. mImageList->Create(14,11,ILC_COLORDDB,1,1);
This specifies images 14x11 pixels. Is this really what you want?
Default is 16x16.
I've never used ILC_COLORDDB before. I've used ILC_COLOR8 | ILC_MASK.
Since your images are created using LoadIcon(), and icons contain masks,
perhaps you should specify at least ILC_MASK.
2. mImageList->SetBkColor(RGB(255,255,255));
If you use ILC_MASK, this should not be required.
3. mImageList->Add(AfxGetApp()->LoadIcon(IDI_ICON1));
mImageList->Add(AfxGetApp()->LoadIcon(IDI_ICON2));
mImageList->Add(AfxGetApp()->LoadIcon(IDI_ICON3));
AfxGetApp()->LoadIcon() only works with the 32x32 image and shrinks it.
It ignores any other image size in the icon file. I use LoadImage()
instead:
HICON hIcon = (HICON) ::LoadImage ( AfxGetResourceHandle(),
MAKEINTRESOURCE(IDI_ICON1),
IMAGE_ICON,
16, 16, // small icon
LR_DEFAULTCOLOR);
Also, since you know you are adding 3 icons, specify the inital size in
step #1 (parameter 3) to be 3.
4. MapDialogUnitX(14*2,NULL); // Added for the DPI Settings
I've no idea about this; try commenting out
These image lists are hard to work with because any of these parameters (or
combination) may be the culprit, and finding the correct combination is
trial and error. I think I had a similar problem with my image lists that
they worked on WinXP but displayed black on Win2K. I had to fiddle with
these parameters for a few hours before finally figuring out something that
worked. Good luck!
-- David