Jump to content
Gord P

Why is the TCustomDrawState set empty?

Recommended Posts

I was unable to use styles to change the background color of a TreeView node, so I am trying an alternate route but once again have hit a road block.  I found some code in Delphi and converted it (I think) to C++. 

void __fastcall TForm1::TreeView1CustomDrawItem(TCustomTreeView *Sender, TTreeNode *Node,
                    TCustomDrawState State, bool &DefaultDraw)
{
 if(State.Contains(cdsSelected))
 {
    Sender->Canvas->Brush->Color = clBlack;
    Sender->Canvas->Font->Color = clWhite;
 }
}

 

The problem is that it never fires true.  When I set breakpoint at the "if" line, State shows up as "{ }"

 

What am I doing wrong here?

 

BTW, if I get rid of the "if" statement" so that it fires all the time, all the items show up as expected (white font on black background) except the selected node (which I don't know why).

 

Share this post


Link to post

I am no C++ expert but shouldn't the asterisks of the parameters be immediately following the types and not precede the parameter names?

Edited by PeaShooter_OMO

Share this post


Link to post

Turns out you need to turn off theming for the treeview control.

void __fastcall TForm1::FormCreate(TObject *Sender)
{
    SetWindowTheme(TreeView1->Handle, L"", L"");
}

It allows you to control the color but unfortunately when you do so, you get old school buttons on the treeview.

image.png.45cdfb8b005762ad2edafe69481115a0.png

 

It is kind of ridiculous why you have to go through so many hoops and hurdles just to adjust a color to match a specific theme.  It should be easily done through the Bitmap Style Designer so the developer can focus on other things.

 

Share this post


Link to post
13 hours ago, PeaShooter_OMO said:

I am no C++ expert but shouldn't the asterisks of the parameters be immediately following the types and not precede the parameter names?

Whitespace between tokens doesn't matter in C/C++.  Thus, "Type* VarName" and "Type *VarName" and "Type   *   VarName" all mean the same thing.

Edited by Remy Lebeau

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×