Originally posted by: Arup Banerjee
However one beautiful thing is in the NMCD's dwItemSpec. Basically this represents the Item handle!!!.
U can type_cast this to HTREEITEM and use the Tree_View Macros as usual.U may choose to store
Before I leave one final point setting clrText by catching iLevel works with returning
Surprising I don't know why??. It works by returning CDRF_NEWFONT.
//Code Snippet
switch( lpcd->nmcd.dwDrawStage )
case CDDS_ITEMPREPAINT :
When we receive the NM_CUSTOMDRAW notification,the only information we have is in the NMTVCUSTOMDRAW.
This provide only one extra attribute called iLevel which provides an almost crude information
per Item.
Well u got it the tree world is open again!
the item specific font color blah blah in the lParam of the TVITEM. Careful its ur responsibility
to deallocate the memory held in the lParam when the tree is destroyed. Probably u will choose
FinalRelease() if ur using ATL to develop ur customised Control.
CDRF_SKIPDEFAULT. It however doesn't work setting clrText per item using dwItemSpec and returning
CDRF_SKIPDEFAULT even if u don't select a different Font.
LRESULT CEnterpriseTree::OnCustomDraw(int idCtrl, NMHDR *pNMHDR, BOOL& bHandled)
{
LPNMTVCUSTOMDRAW lpcd = (LPNMTVCUSTOMDRAW) pNMHDR;
{
case CDDS_PREPAINT:
return CDRF_NOTIFYITEMDRAW;
break;
//To change the font,select the desired font
//into the provided HDC.
if (lpcd->nmcd.uItemState == (CDIS_FOCUS | CDIS_SELECTED)) // selected
{
lpcd->clrText = RGB(255, 255, 255);
}
else
{
lpcd->clrText = GetItemColor((HTREEITEM)(lpcd->nmcd.dwItemSpec));
}
SelectObject(lpcd->nmcd.hdc , GetItemFont((HTREEITEM)(lpcd->nmcd.dwItemSpec)));
return CDRF_NEWFONT;
break;
default:
return CDRF_DODEFAULT;
break;
}
}
Originally posted by: Stephen Totten
The blue text output in my example draws in a static position every time (i.e. it doesn't vary its
position with the text font etc, but you should be able to work that out using the NMCUSTOMDRAW.dwItemSpec
member and the CDC.GetTextExtent function).
NB: for a tree item NMCUSTOMDRAW.lItemlParam equals TV_INSERTSTRUCT.item.lParam
BOOL CMyWnd::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
switch( pNmhdr->code )
case CDDS_ITEMPREPAINT:
case CDDS_ITEMPOSTPAINT:
CDC dc;
// set text colour to blue
char outText[20];
dc.TextOut( area.right - 40, area.top, outText, strlen(outText) );
dc.Detach();
*pResult = CDRF_DODEFAULT;
default:
If anyone is interested in drawing a tree control similar to that of the news section in MSOE 5 (with the
blue text to the side), here's roughly how it's done.
{
LPNMHDR pNmhdr = (LPNMHDR)lParam;
{
case NM_CUSTOMDRAW:
{
LPNMTVCUSTOMDRAW pCustomDraw = (LPNMTVCUSTOMDRAW)lParam;
switch (pCustomDraw->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
// Need to process this case and set pResult to CDRF_NOTIFYITEMDRAW,
// otherwise parent will never receive CDDS_ITEMPREPAINT notification. (GGH)
*pResult = CDRF_NOTIFYITEMDRAW;
return true;
if( pCustomDraw->iLevel == 1 )
{
// only want to do custom drawing on level 1 tree items
*pResult = CDRF_NOTIFYPOSTPAINT;
return true;
}
else
{
*pResult = CDRF_DODEFAULT;
return true;
}
break;
{
RECT area = pCustomDraw->nmcd.rc;
dc.Attach( pCustomDraw->nmcd.hdc );
dc.SetTextColor( 0x00ff0000 );
sprintf( outText, "(%d)", pCustomDraw->nmcd.lItemlParam );
return true;
}
break;
}
break;
}
break;
}
return CPropertyPage::OnNotify(wParam, lParam, pResult);
}
Originally posted by: Gene Sewell
In your sample, and on my code, the tree control repaints
I made my code look like this:
if (pcd->nmcd.uItemState == (CDIS_FOCUS | CDIS_SELECTED)) // selected
No matter how I played with it, when the user clicks on a
Any ideas?
Thanks,
Gene
Thanks for the nice code snip.
in a non-standard way.
{
pcd->clrText = GetSysColor(COLOR_HIGHLIGHTTEXT); //RGB(255, 255, 255);
pcd->clrTextBk = GetSysColor(COLOR_HIGHLIGHT);
}
else ...
pcd->clrText = RGB(255, 0, 0);
new leaf, and doesn't release the button, both leaves are
painted, rather than just the new leaf with focus.
Originally posted by: Markus Lutz
Hi Garen,
your code works pretty good but when I tried to change the font (as explained in the MS-Specs)it did not
work correctly. The font was changed but the metrics where not calculated. Is there any function or notify
like
MEASUREITEM ?
Thanks Markus