且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在停靠窗格的标题栏中显示图标

更新时间:2023-01-05 10:02:56

进一步的研究揭示了答案,我在这里发布以防万一其他人有同样的问题。停靠窗格是从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.