如何在停靠窗格的标题栏中显示图标 [英] How to show icon in title bar of docked pane

查看:92
本文介绍了如何在停靠窗格的标题栏中显示图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows MFC C ++应用程序 - 我有一个窗口,在自动隐藏模式下停靠在主框架上。窗口的标题栏有一个图标和文本。当隐藏停靠窗格时,选项卡上会显示图标,但是当窗口被取消隐藏时,不显示图标,只显示标题文本。我也希望看到图标(它也需要以编程方式进行更改)

Windows MFC C++ app - I have a window that is docked to the main frame in auto-hide mode. The window's title bar has an icon as well as text. When the docked pane is hidden, the icon shows on the tab, but when the pane is unhidden, the icon is not shown, just the title text. I would like to see the icon as well (it needs to be changed programmatically too)

推荐答案

进一步的研究揭示了答案,我在这里发布以防万一其他人有同样的问题。停靠窗格是从CDockablePane类派生的(并不太令人惊讶),并且该类的实现中存在一个错误:它只是不打扰绘图图标。我的解决方案是从中派生一个类并重写DrawCaption方法。在该功能中,我调整文本矩形以为图标腾出空间,然后绘制图标。使用:: DrawIconEx绘制图标,因为:: DrawIcon使用(错误的)默认大小绘制它。还必须使用:: LoadImage而不是:: LoadIcon加载图标(项目中的其他位置),否则会再次出现错误的大小。
Further research has revealed the answer, which I publish here in case anyone else has the same problem. Docked panes are derived (not too surprisingly) from the CDockablePane class, and there is a bug in the implementation of that class: it just doesn't bother with drawing icons. My solution was to derive a class from it and override the DrawCaption method. In that function I adjust the text rectangle to make room for the icon, and then draw the icon. The icon is drawn using ::DrawIconEx as ::DrawIcon draws it with a (wrong) default size. Also had to load the icon (elsewhere in the project) using ::LoadImage rather than ::LoadIcon, otherwise the wrong size again results.


这篇关于如何在停靠窗格的标题栏中显示图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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