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

查看:17
本文介绍了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天全站免登陆