Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BackColor property in Treeview control 2

Status
Not open for further replies.
Hi Chris,

Try this:

Declare Long SendMessage in User32 ;
Long nhWnd, Integer Msg, Long wParam, Long lParam
SendMessage(ThisForm.TreeView1.hWnd, 4381, 0, RGB(0,0,0))

HTH

-- AirCon --
 
AirCon,

When I said it couldn't be done, I should've said that it couldn't be done easily. I never thought of using an API call. Well done.

However, I think your code will show the background of the tree in the specified colour, but not the background of the individual nodes. So Chris will have to also set the nodes' Backcolor property to the same colour to get the desired effect.

Mike


Mike Lewis
Edinburgh, Scotland
 
Mike, sorry I didn't see your message earlier :)

Yes you are right. But I think that is what Chris wants, because he mentioned not on the nodes. Am i misunderstood about this ?

-- AirCon --
 
Mike, AirCon

Thanks for your responses.

AirCon - the complication I have is that the treeview control is in a page in a pageframe and the code as suggested does not work using the path to the control such as :-

THISFORM.pgfFrame1.Page1.oleTreeView.Hwnd

I suspect the only workaround is to remove the control from the pageframe and reference the control directly in the form.

Any ideas?

FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
try this:

DECLARE INTEGER SendMessage IN user32;
INTEGER hWnd, INTEGER Msg,;
INTEGER wParam, INTEGER lParam

DECLARE INTEGER SetWindowLong IN user32.DLL ;
INTEGER hWnd, INTEGER nIndex, INTEGER dwNewLong

DECLARE INTEGER GetWindowLong IN user32.DLL ;
INTEGER hWnd, INTEGER nIndex

GWL_STYLE = -16
TVM_SETBKCOLOR = 4381
TVM_SETTEXTCOLOR = 4382
TVM_GETBKCOLOR = 4383
TVM_GETTEXTCOLOR = 4384
TVM_SETINSERTMARKCOLOR=4389
TVM_GETINSERTMARKCOLOR=4390
TVS_HASLINES = 2

colore=RGB(255,251,240)

FOR EACH node IN thisform.oletreeview.Nodes
* thisform.oletreeview.Nodes(x).BackColor =colore
node.backcolor = colore
NEXT




*cambio il colore di fondo
=SendMessage(thisform.oletreeview.hWnd, TVM_SETBKCOLOR, ;
0,colore)
=SendMessage(thisform.oletreeview.hWnd, TVM_GETTEXTCOLOR , ;
0,RGB(0,255,0))

* ora sistemo le linee che se no appaiono male
lngStyle = GetWindowLong(thisform.oletreeview.hWnd, GWL_STYLE)
=SetWindowLong(thisform.oletreeview.hWnd, GWL_STYLE, ;
lngStyle - TVS_HASLINES)
=SetWindowLong(thisform.oletreeview.hWnd, GWL_STYLE, lngStyle)

thisform.oletreeview.Refresh()
thisform.Refresh()


 
Chris,

the complication I have is that the treeview control is in a page in a pageframe

When I ran AirCon's code, I put the code in the Init of the tree, and referenced the control as THIS:

SendMessage(THIS.hWnd, 4381, 0, 255)

That worked for me.

Mike



Mike Lewis
Edinburgh, Scotland
 
In my haste I had not changed the .BackColor of the nodes, so it was basically working.

What's now left is the white area to the left of the tree, which, if you click on it, will set focus to the node on the right of the tree.

If you take the Treeview out of the pageframe then the white area dissapears, so the pageframe remains as the problem.

I've substituted the MS TabStrip for the pageframe to maintain the original functionality.

FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
I have tried to change the color of my treeview using the examples given above but i keep getting the the error message 'Cannot find entry point Sendmessage in the DLL' . Any idea what i am doing wrong.


 
found the problem - i had used 'Sendmessage' instead of 'SendMessage' - apparently it is case sensitive and you have to have to use a capital 'M'

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top