MFC CComboBoxEx图标更新问题
我正在使用 MFC 中的 CComboBoxEx 控件来实现浏览器应用程序的地址框,该应用程序显示地址和相关站点图标。
根据此链接:http://msdn.microsoft。 com/en-us/library/bb775788(v=vs.85).aspx,调用 iItem 为 -1 的 CComboBoxEx::SetItem 将修改当前在编辑中显示的项目 控制。这是我使用的代码段,
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 后图标不会更新。设置新图标后,仍显示之前的图标。请注意,图像索引永远不会改变。我只是更新图像列表中的实际图标。
有趣的是,我发现如果我使用鼠标在组合框内单击,然后在其他控件内单击以使组合框失去焦点,图标将会更新。我可以通过编程来做到这一点,但我觉得这是一个尴尬的解决方法。
除此之外,在组合框上调用 Invalidate 或 RedrawWindow 在不更新时不会显示新图标。
任何有关这方面的经验或建议将不胜感激。多谢。
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.
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);
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能您需要调用 CComboBoxEx::SetImageList
Probably you need to call CComboBoxEx::SetImageList again.
我曾经遇到过类似的问题。后来发现原因是我创建时的CImageList。
我改成更新后
直到
WM_KILLFOCUS
收到的现象消失了。但可惜的是,形象比以前美了一些。I once encountered a similar problem. Later I found that the cause is the CImageList when I created it.
After I changed
to
the phenomenon of updating until
WM_KILLFOCUS
received disappeared. But it's a pity that the image is a little less beautiful than before.