• 0

Changing font on my CTreeCtrl


Question

I have overloaded the CTreeCtrl::OnCustomdraw ( NMHDR* pNMHDR, LRESULT* pResult )

Function and would like to make the item texts Bold.

Can I use the NMLVCUSTOMDRAW struct. I have tried looking in MSDN.

I successfully have changed the text color with the following code:

void MyTreeCtrl::OnCustomdraw ( NMHDR* pNMHDR, LRESULT* pResult )
{
	NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
pLVCD->clrText   = RGB( 210, 65, 20 );
}

Any suggestion how to change the font? ?

Link to comment
https://www.neowin.net/forum/topic/241956-changing-font-on-my-ctreectrl/
Share on other sites

2 answers to this question

Recommended Posts

  • 0

You could try the following without having to overload anything:

Create two member variables in your .h file, eg:

CFont m_fontTree;
CTreeCtrl *m_ptreeData;

Then in your OnInitDialog() function in the .cpp file do the following:

//Font Structure
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = 12;
lf.lfWeight = FW_BOLD;
strcpy(lf.lfFaceName, "Times New Roman");
m_fontTree.CreateFontIndirect(&lf);

//Create new
m_ptreeData = new CTreeCtrl;
m_ptreeData->Create(WS_VISIBLE|WS_CHILD|WS_BORDER|TVS_HASBUTTONS|TVS_LINESATROOT|TVS_HASLINES, CRect(5, 5, 200, 300), this, WM_USER + 1);

//Set Font
m_ptreeData->SetFont(&m_fontTree);

Of course you wont be able to change the colour this way, but with you already having overloaded OnCustomDraw it should still work.

Oh and don't forget to

delete m_ptreeData;

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.