CTreeCtrl加ICON图标的代码片段如下:
这里要注意:Create的第二个参数
(1)颜色深度一定要选择正确eg,ILC_COLOR32
(2)或上掩码处理ILC_MASK,对ICON来说会使得其黑色的背景透明
m_imgList.Create(16,16,ILC_COLOR32|ILC_MASK,2,0);
m_imgList.Add(AfxGetApp()->LoadIcon(IDI_ICON_PLUS));
m_imgList.Add(AfxGetApp()->LoadIcon(IDI_ICON_MINUS));
m_tree.SetImageList(&m_imgList,TVSIL_NORMAL);
m_tree.InsertItem(_T("root"));
CTreeCtrl控件中的CimageList插入一个图标为什么显示成黑色呢
我在Dialog中方了一个CTreeCtrl控件,按照需要插入节点,但是我的程序中节点能够插入,但是节点的图标都是黑的,各位大侠给看看错在哪里?
void CClassTreeCtrl::AddImage(const COLORREF& dwColor)
{
BYTE color3[3];
color3[0] = GetRValue(dwColor);
color3[1] = GetGValue(dwColor);
color3[2] = GetBValue(dwColor);
CBitmap bitmap;
BYTE* lpBits=NULL;
lpBits = new BYTE[16*16*3];
for (int i=0;i <16*16;i++)
{
for (int j=0;j <3;j++)
{
*(lpBits+i+j) = color3[j];
}
}
bitmap.CreateBitmap(16,16,1,24,lpBits);
CImageList* pImgList = this-> GetImageList(TVSIL_NORMAL);
pImgList-> Add(&bitmap,RGB(255,255,255));
//////////////////////////////////////////////////////////////////
int nImgCount = pImgList-> GetImageCount();
this-> InsertItem(strClassName,nImgCount-1,1,TVI_ROOT);
//////////////////////////////////////////////////////////////////
delete lpBits;
lpBits=NULL;
}
但是发现ctreectrl中增加的这个节点的图为黑色的,请问什么原因
------解决方案--------------------
试试:
void CClassTreeCtrl::AddImage(const COLORREF& dwColor)
{
CPaintDC dc(this);
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(&dc,16,16);
CDC myDC;
myDC.CreateCompatibleDC(&dc);
CBitmap *pOldBitmap = myDC.SelectObject(m_bitmap);
CBrush mybrush(dwColor);
myDC.FillRect(&rc,&mybrush);
myDC.SelectObject(pOldBitmap);
myDC.DeleteDC();
CImageList* pImgList = this-> GetImageList(TVSIL_NORMAL);
pImgList-> Add(&bitmap,RGB(255,255,255));
bitmap.Detach();
//////////////////////////////////////////////////////////////////
int nImgCount = pImgList-> GetImageCount();
this-> InsertItem(strClassName,nImgCount-1,1,TVI_ROOT);
//////////////////////////////////////////////////////////////////
}
前面提到了CImageList类的Create(...)函数,虽然MSDN上已经有所解释,但仍有网友问到参数的具体含义,下面就我的理解,对参数进行一次轻量级的剖析
函数原型(其他重载函数请参看msdn):
BOOL Create(
int cx,
int cy,
UINT nFlags,
int nInitial,
int nGrow
);
cx ,cy:
图片的实际像素宽与高,没有问题
nFlags:
创建图像列表的类型,包括4/8/16/24/32/位色,
nInitial :
创建ImageList初始包括的图像个数
nGrow
当初始分配的图像个数不够的时候,新增一个图片时,指定图象列表能增加的新图象个数,图像列表空间不够而继续添加image时,将按照nGrow继续分配空间,设计时根据具体情况设置合适的值,避免内存频繁的改变图像列表而過度頻繁而使系統记忆体碎片化
例如
nInitial = 2,nGrow=3
当你添加了两个图像元素以后,还想添加第三个的时候,初始创建分配的nInitial已经使用完了,此时,系统会根据nGrow,为自动增大Imagelist3个元素容量,此时我们的Imagelist就可以容纳5个图像元素了,如果5个使用完毕后,会继续按照nGrow进行再分配,类似于一个可变数组,但参数到底设置多少,还是要根据实际的情况设置合理的值,一要避免浪费空间,又要避免频繁的对Image容器进行resize操作
Suese
2018-03-13 02:19:23
Very good material. Thanks! cialis tbl 2x 20 mg <a href="http://cialisfidel.com/">cialis without a doctor prescription</a> cialis ask your doctor <a href=http://cialisfidel.com/>cialis generic</a>
Suese
2018-04-13 23:07:06
levitra 20 mg canada <a href="http://myvardenafilok.com#">levitra 20 mg</a> levitra 20 mg cena de navidad <a href=http://mylevitraok.com#levitra+20mg>levitra 20 mg bayer prezzo</a> levitra savitry bisram
Suese
2018-04-14 07:10:07
levitra flavio 2014 corvette <a href="http://mylevitraok.com#">levitra prices</a> is levitra for women <a href=http://myvardenafilok.com#levitra+20+mg>levitra online</a> viagra levitra cialis qual o melhor investimento
Suese
2018-04-14 15:46:20
free trial viagra cialis levitra <a href="http://myvardenafilok.com#">levitra 20mg</a> levitra viagra online natural <a href=http://myvardenafilok.com#vardenafil+20mg>levitra online</a> acheter levitra 20mg
Suese
2018-04-15 01:42:28
rebika levitra <a href="http://myvardenafilok.com#">levitra generic</a> guarura de levitra oscar chavez boxer <a href=http://mylevitraok.com#levitra+online>levitra online</a> laura levitra yasmine akram
Suese
2018-04-15 10:00:41
levitra reviews by women <a href="http://mylevitraok.com#">buy levitra</a> levitra 5mg 10mg 20mg tablets for toddlers <a href=http://myvardenafilok.com#levitra+rezeptfrei+deutschland>vardenafil 20mg</a> levitra 10 mg filmtabletten ohne-rezept-kaufen-biz
Suese
2018-04-15 11:22:01
levitra orodispersibile 10 mg prezzo petrolio <a href="http://myvardenafilok.com#">vardenafil 20mg</a> side effects of levitra vs viagra <a href=http://myvardenafilok.com#generic+levitra>levitra online</a> levitra bloeddrukmeter gebruiksaanwijzing novy
Suese
2018-04-15 15:27:18
site o levitra flavio's home <a href="http://mylevitraok.com#">levitra online</a> levitra wikipedia francais crane <a href=http://mylevitraok.com#levitra+prices>levitra rezeptfrei deutschland</a> besser viagra cialis levitra
Suese
2018-04-15 15:28:07
u 76 key buy-levitra <a href="http://myvardenafilok.com#">vardenafil 20mg</a> levitra gabriele menezes pizza <a href=http://myvardenafilok.com#levitra+coupon>levitra rezeptfrei deutschland</a> impotenza psicologica levitra cost
Suese
2018-04-15 15:32:58
patentschutz levitra prices <a href="http://myvardenafilok.com#">levitra 20 mg bayer prezzo</a> el levitra clip experimento filadelfia <a href=http://myvardenafilok.com#levitra+20mg>levitra 20 mg</a> western health levitra coverage
Suese
2018-04-15 19:27:23
chistorete.com levitra link online <a href="http://myvardenafilok.com#">generic levitra</a> fantasma magic kit levitra online <a href=http://myvardenafilok.com#levitra+prices>levitra coupon</a> viagra levitra cialis offers up
Suese
2018-04-15 21:09:36
archive info levitra personal php remember <a href="http://mylevitraok.com#">levitra 20 mg bayer prezzo</a> jovem levitra palco mp3 leo <a href=http://mylevitraok.com#generic+levitra>levitra prices</a> buy dirz.mpage.jp levitra link online
Suese
2018-04-16 01:34:24
levitra machine shop <a href="http://mylevitraok.com#">levitra generic</a> andy levitra finances <a href=http://myvardenafilok.com#generic+levitra>levitra generic</a> andy levitra chargers football
Suese
2018-04-16 01:35:12
levitra 10 mg images <a href="http://mylevitraok.com#">vardenafil 20mg</a> generic levitra 20 mg <a href=http://mylevitraok.com#levitra+20mg>levitra online</a> ohad levitra omonoia apoel
Suese
2018-04-16 01:39:53
alan levitra <a href="http://myvardenafilok.com#">levitra 20mg</a> levitra table te cijena <a href=http://mylevitraok.com#levitra+20+mg+bayer+prezzo>levitra 10 mg prezzo</a> levitra orosolubile foglietto illustrativo inglese
Suese
2018-04-18 19:12:53
cheap online stock and option trading <a href="http://options-best-try-platform-binary.pw/vdub-binary-options-snipervx-v1-my-1-minute-60-secondcom-5631.php#">99 vip binary option signals</a> binary options business how to winning system <a href=http://platform-best-try-binary-options.pw/uganda-forex-bureau-today-6719.php>commodity broker that trading for youtube</a>
Suese
2018-04-19 08:54:19
adc levitra coupon <a href="http://levitra-gg.com">levitra coupon</a> buy generic levitra online <a href=http://myvardenafilok.com#buy+levitra>levitra 20mg</a>
Suese
2018-04-19 16:58:15
levitra online kaufen forum <a href="http://levitra-gg.com">levitra 20 mg</a> levitra samples for doctors <a href=http://myvardenafilok.com#vardenafil+20mg>vardenafil 20mg</a>
Suese
2018-04-19 20:47:46
andy levitra titans tickets <a href="http://levitra-gg.com">levitra 10 mg prezzo</a> apotik penjual levitra for sale <a href=http://mylevitraok.com#levitra+20+mg+bayer+prezzo>levitra coupon</a>
Suese
2018-04-20 00:33:03
cialis imperial levitra libidus viagra yohimbe <a href="http://levitra-gg.com">vardenafil 20mg</a> united pharmacy levitra <a href=http://myvardenafilok.com#levitra+20+mg+bayer+prezzo>levitra 20 mg bayer prezzo</a>
Suese
2018-04-20 04:20:14
20mg levitra cost <a href="http://levitra-gg.com">buy levitra</a> levitra ou sacerdote eudista <a href=http://mylevitraok.com#levitra+coupon>levitra 10 mg prezzo</a>
Suese
2018-04-20 08:15:27
book cheap com esther guest levitra site <a href="http://myvardenafilok.com">levitra 10 mg prezzo</a> levitra do senhor <a href=http://mylevitraok.com#levitra+20+mg>levitra 20 mg bayer prezzo</a>
Suese
2018-04-20 12:12:02
book buy guest levitra online <a href="http://mylevitraok.com">levitra 20 mg</a> levitra mt olympus <a href=http://levitra-gg.com#levitra+online>vardenafil 20mg</a>
Suese
2018-04-20 16:10:17
glebsky levitra <a href="http://levitra-gg.com">levitra 20mg</a> levitra 10 mg wikipedia the free <a href=http://mylevitraok.com#levitra+20mg>buy levitra</a>
Suese
2018-04-20 18:45:14
levitra 20mg bayer en mexico <a href="http://myvardenafilok.com">levitra coupon</a> levitra o que significa www <a href=http://myvardenafilok.com#generic+levitra>levitra rezeptfrei deutschland</a>
Suese
2018-04-20 22:32:23
trial samples of levitra <a href="http://myvardenafilok.com">levitra 20 mg bayer prezzo</a> levitra orodispersibile commission <a href=http://levitra-gg.com#levitra+20+mg>generic levitra</a>
Suese
2018-04-21 01:51:23
levitra josemir jose <a href="http://myvardenafilok.com">levitra 10 mg prezzo</a> levitra online malaysia passport <a href=http://levitra-gg.com#levitra+20mg>levitra generic</a>
Suese
2018-04-21 05:13:19
book buy guest levitra online pl site <a href="http://levitra-gg.com">vardenafil 20mg</a> levitra discount walmart online <a href=http://myvardenafilok.com#buy+levitra>levitra online</a>
Suese
2018-04-24 12:18:52
Hi, its fastidious paragraph about media print, we all know media is a wonderful source of facts.