CTreeCtrl 中的字体更改后项目大小未调整
我使用以下代码更改 CTreeCtrl 中树项目的字体:
void CTreeCtrlEx::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTVCUSTOMDRAW pNMCD = reinterpret_cast<LPNMTVCUSTOMDRAW>(pNMHDR);
*pResult = 0;
switch(pNMCD->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
return;
case CDDS_ITEMPREPAINT:
{
CFont * pco_font = GetSomeFont();
::SelectObject(pNMCD->nmcd.hdc, pco_font->GetSafeHandle());
*pResult = CDRF_NEWFONT;
}
return;
}
}
但是,文本的末尾被剪裁在项目中,显然它没有
调整为使用新字体的文本长度。
补救办法是什么?
I change the font of tree items in CTreeCtrl with the following code:
void CTreeCtrlEx::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTVCUSTOMDRAW pNMCD = reinterpret_cast<LPNMTVCUSTOMDRAW>(pNMHDR);
*pResult = 0;
switch(pNMCD->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
return;
case CDDS_ITEMPREPAINT:
{
CFont * pco_font = GetSomeFont();
::SelectObject(pNMCD->nmcd.hdc, pco_font->GetSafeHandle());
*pResult = CDRF_NEWFONT;
}
return;
}
}
However, the end of the text is being clipped in the items, apparently it is not being
adjusted to the length of the text with the new font.
what would be the remedy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题,可以确认 CCM_SETVERSION 不起作用。事实上,对我来说唯一可靠的方法是在绘制过程完成后重新设置文本。我的方法是捕获 TVN_ITEMEXPANDING 消息并重新设置文本。当节点展开时,这将更正所有子项的文本。当然,这对于粗体根节点不起作用。
这是我的代码的草图:
I had the same problem and can confirm that CCM_SETVERSION did not work. In fact the only thing that worked reliably for me was to re-set the text after the paint process was finished. The way I did it was by catching the TVN_ITEMEXPANDING message and by re-setting the text. This would correct the text of all sub-items when a node is expanded. Of course this does not work for bold root nodes.
Here is a sketch of my code:
从我的 MSDN 副本来看,我似乎无法在网上找到:
另请参阅CCM_SETVERSION 文档。
From my copy of MSDN, which I can't seem to find online:
See also the documentation for CCM_SETVERSION.