Problem with TreeView, NM_CUSTOMDRAW and CDDS_ITEMPREPAINT

I have a TreeView (without MFC) and I want to change the background color of the text. I use the following code, as showed into the MSDN. My problem is that my app never receive the CDDS_ITEMPREPAINT message when I add a node to the tree.
The CDDS_PREPAINT is well processed.
Argh!!!!

Does anybody know WHY ?
Thank you !

// Within the WM_NOTIFY process :
case IDL_C:      // notify from my tree view
switch (ph->code)
{
case NM_CUSTOMDRAW:
{
LPNMTVCUSTOMDRAW pd = (LPNMTVCUSTOMDRAW)ph;
if (pd->nmcd.dwDrawStage==CDDS_PREPAINT)
return CDRF_NOTIFYITEMDRAW;
if (pd->nmcd.dwDrawStage==CDDS_ITEMPREPAINT)
{
pd->clrTextBk = WEYellow;
return CDRF_NEWFONT;
}
return CDRF_DODEFAULT;
}
LVL 2
lif081199Asked:
Who is Participating?
 
NickRepinConnect With a Mentor Commented:
You could accept my comment as answer.
0
 
NickRepinCommented:
Try to force repaint after adding node by InvalidateRect(hTView,clientRect); UpdateWindow(hTView)
0
 
NickRepinCommented:
You said you never recieve CDDS_ITEMPREPAINT. So added node is displayed w/o yellow background?
May be, it is just a yet another bug already fixed in new version of comctl32.dll?
Also sometimes Windows doesn't send notification on YOUR action. For example, SendMessage(TVM_EXPAND) doesn't cause TVN_ITEMEXPANDING. Of course, Windows must send CDDS_ITEMPREPAINT in your case, but who knows...
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
lif081199Author Commented:
Your first idea doesn't work :(
I just receive more CDDS_PREPAINT messages.

About your question, yes, each node is displayed witouht the colored bkgnd.

Note that my soft has to work with the 4.70 version of comctl32 :(
0
 
lif081199Author Commented:
Your first idea doesn't work :(
I just receive more CDDS_PREPAINT messages.

About your question, yes, each node is displayed witouht the colored bkgnd.

Note that my soft has to work with the 4.70 version of comctl32 :(
0
 
NickRepinCommented:
By the way, is your control in dialog?
If so, I wonder how dialog proc can return anything except of TRUE or FALSE.
Try to return codes in SetWindowLong(hDlg,DWL_MSGRESULT,...)
0
 
lif081199Author Commented:
Hum... that is a good clue. The parent is a standard window, but my encapsulation is maybe bad or corrupted.
I check immediatly.
0
 
lif081199Author Commented:
You win !

My NOTIFY encapsulation was returning only a BOOL. Now it works for the text.

Curiously, the background behind the cross to collapse/expand a node stay uncolored. I still have to work :(

Please post a message as an answer to get your points.

And thank you a lot !

Lionel.
0
All Courses

From novice to tech pro — start learning today.