MFC CComboBoxEx图标更新问题 [英] MFC CComboBoxEx icon update issue

查看:122
本文介绍了MFC CComboBoxEx图标更新问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MFC中使用CComboBoxEx控件为浏览器应用程序实现一个地址框,该框显示了地址和相关的站点图标.

I am using the CComboBoxEx control in MFC to implement an address box for a browser application which shows the address and the related site icon.

根据此链接: http://msdn .microsoft.com/en-us/library/bb775788(v = vs.85).aspx ,iItem为-1的CComboBoxEx :: SetItem调用将修改当前显示在编辑控件中的项目.这是我用来

According this link: http://msdn.microsoft.com/en-us/library/bb775788(v=vs.85).aspx, calling CComboBoxEx::SetItem with iItem of -1 will modify the item currently displayed in the edit control. Here is the code segment I use to

HICON hIcon=LoadIcon(....);     //load the new icon from somewhere
imagelist.Replace(1,hIcon);     //replace the existing icon in the image list.
int nImage=1;

item.mask = CBEIF_IMAGE|CBEIF_SELECTEDIMAGE ;
item.iItem = -1;
item.iImage = nImage;
item.iSelectedImage = nImage;
SetItem(&item);

我发现在调用SetItem之后,图标有时不会更新.设置新图标后,它仍显示上一个图标.请注意,图像索引永远不会改变.我只更新图像列表中的实际图标.

I found that ocassionally the icon doesn't update after SetItem is called. It still displays the previous icon after the new icon is set. Please note that the image index never changes. I am only updating the actual icon inside the image list.

有趣的是,我发现如果我用鼠标在组合框内单击,然后在其他控件内单击,以使组合框失去焦点,则图标将更新.我可以以编程方式做到这一点,但我觉得这是一个尴尬的解决方法.

Interestingly, I found that if I use mouse to click inside the combobox andn then click inside some other control so that the combobox loses focus, the icon will update. I could programmatically do that but I feel that's an awkard workaround.

除此之外,在组合框上调用Invalidate或RedrawWindow不会在不更新时显示新图标.

Other than that, calling Invalidate or RedrawWindow on the combobox won't get the new icon to show up when it doesn't update.

任何经验或技巧,将不胜感激.非常感谢.

Any experience or tips on this will be greatly appreciated. Thanks a lot.

推荐答案

我曾经遇到过类似的问题.后来我发现原因是在创建它时是CImageList.

I once encountered a similar problem. Later I found that the cause is the CImageList when I created it.

更改后

m_pImgLst->Create(32,20,ILC_COLOR32,2,2);

m_pImgLst->Create(32,20,ILC_COLOR16,2,2); 

直到收到WM_KILLFOCUS的更新现象消失了.但可惜的是,图像的美感比以前差了一些.

the phenomenon of updating until WM_KILLFOCUS received disappeared. But it's a pity that the image is a little less beautiful than before.

这篇关于MFC CComboBoxEx图标更新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆