gpt4 book ai didi

c++ - CTreeCtrl 中的字体更改后未调整项目大小

转载 作者:行者123 更新时间:2023-11-28 08:27:27 25 4
gpt4 key购买 nike

我使用以下代码更改 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;
}
}

然而,文本的末尾在项目中被剪裁,显然它没有被
调整为新字体的文本长度。
补救措施是什么?

最佳答案

我有同样的问题,可以确认 CCM_SETVERSION 没有工作。事实上,对我来说唯一可靠的方法是在绘制过程完成后 重新设置文本。我这样做的方法是捕捉 TVN_ITEMEXPANDING 消息并重新设置文本。这将在展开节点时更正所有子项的文本。当然,这不适用于粗体根节点。

这是我的代码草图:

BEGIN_MESSAGE_MAP(CTreeViewEx, CTreeView)
ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnItemExpanding)
END_MESSAGE_MAP()

void CTreeViewEx::OnItemExpanding(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
if(pNMTreeView==NULL) {
return;
}
HTREEITEM hTreeItem = pNMTreeView->itemNew.hItem;
if(hTreeItem!=NULL) {
ReevaluteItemTextOfChildren(hTreeItem);
...
}
}

void CTdTreeViewEx::ReevaluteItemTextOfChildren(HTREEITEM hRootNode)
{
if (hRootNode == NULL) {
return;
}
CTreeCtrl& ctlTree = GetTreeCtrl();
HTREEITEM hTreeItemCursor = ctlTree.GetNextItem(hRootNode, TVGN_CHILD);
// Loop over all siblings
while (hTreeItemCursor != NULL) {
// Change the text of the current item
CString csItemText(ctlTree.GetItemText(hTreeItemCursor));
ctlTree.SetItemText(hTreeItemCursor, csItemText);
// Get the next brother
HTREEITEM hNextSibling = ctlTree.GetNextItem(hTreeItemCursor, TVGN_NEXT);
hTreeItemCursor = hNextSibling;
}
}

关于c++ - CTreeCtrl 中的字体更改后未调整项目大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3408918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com