MFC CComboBoxEx icon update issue(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 图标更新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MFC CComboBoxEx 图标更新问题


基础教程推荐
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 这个宏可以转换成函数吗? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01