combox的ITEM设置不了字体的BUG

来源:互联网 发布:风油精滴在b 知乎 编辑:程序博客网 时间:2024/09/21 09:04

Combo控件的itemfont属性, 可以设置点击Combo弹出列表中的item的字体. 但是发现点击后, 弹出的列表里, 字体不是我们设置的.

查看源代码, 可以发现Combo弹出的列表是个新窗口, 该窗口的CPaintManagerUI成员(m_pm)调用了这句m_pm.UseParentResource(m_pOwner->GetManager()); ,虽然这个新窗口没有自己的字体, 但它可以使用父窗口资源.

经过代码跟踪, 发现CPaintManagerUI::GetFont没有获取到正确的字体,

原来的代码是:

HFONT CPaintManagerUI::GetFont(int index){    if( index < 0 || index >= m_aCustomFonts.GetSize() ) return GetDefaultFontInfo()->hFont;    TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_aCustomFonts[index]);    return pFontInfo->hFont;}

需要改成如下

HFONT CPaintManagerUI::GetFont(int index){    if( index < 0 || index >= m_aCustomFonts.GetSize() ){if (m_pParentResourcePM) return m_pParentResourcePM->GetFont(index);return GetDefaultFontInfo()->hFont;}    TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_aCustomFonts[index]);    return pFontInfo->hFont;}

可以看到修改部分所做的工作是: 当找不到字体时, 使用父窗口资源字体.

改完后, 我们发现虽然字体对了, 不过ITEM的高度不对, 继续跟踪, 发现还需要修改TFontInfo* CPaintManagerUI::GetFontInfo(int index), 其实也是同样的BUG

2 0
原创粉丝点击