-
May 13th, 2003, 11:48 AM
#1
Changing Background Colours
Is it at all possible to change the background colour of the TreeView control provided in the mscomctl library?
I have read about and tried to implement various API calls to do this, but I can't seem to get them to work. Is there a trick that I am missing, or can this simply not be done?
Cheers in advance.
Finite
"If a cat always lands on its feet, and a peice of bread always lands butter side down, if you strap a peice of bread butter side up to the back of a cat, will it hover?"
-
May 13th, 2003, 09:00 PM
#2
Not possible.. It is a windows common control..
Busy
-
May 13th, 2003, 10:21 PM
#3
You can change it simply by sending a message TVM_SETBKCOLOR
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd&, ByVal wMsg&, ByVal wParam&, lParam As Any) As Long
Const TVM_SETBKCOLOR = 4381
Private Sub Form_Load()
Dim newColor As Long
newColor = RGB(255, 0, 0)
Call SendMessage(Me.TreeView1.hwnd, TVM_SETBKCOLOR, 0, ByVal newColor&)
End Sub
Hope it will help you
-
May 13th, 2003, 10:31 PM
#4
Excellent rxbagain!! Can you share that TreeView WMessages?
Busy
-
May 13th, 2003, 10:53 PM
#5
There are many messages. In my MSDN, they are located in
Platform SDK ->
User Interface Services ->
Windows Common Controls ->
Tree View Controls ->
Tree View Control Messages
You can also find other common controls there.
-
May 13th, 2003, 11:03 PM
#6
How about the message values??
Busy
-
May 13th, 2003, 11:39 PM
#7
They are in COMMCTRL.H. They are defined for example as
Code:
#define TVM_SETBKCOLOR (TV_FIRST + 29)
So you have to add the value 29 to the value of TV_FIRST. But to simplify your job. Just make a simple win32 or console application in C++ and return the value.
Code:
#include "commctrl.h"
int main(void) {
return TVM_SETBKCOLOR;
}
It will place the process's return value in the Debug output window.
Hope it will help you
-
May 14th, 2003, 12:15 AM
#8
Windows Messages
Thanks to rxbagain.. We have now the windows messages which are not included in the VB api viewer..
Cheers!
Busy
-
May 15th, 2003, 09:40 AM
#9
Ok, thats great, nearly perfect.
Do you know how I change the color of the text as well? I can't get it to work using the same method, nothing happens.
Finite
"If a cat always lands on its feet, and a peice of bread always lands butter side down, if you strap a peice of bread butter side up to the back of a cat, will it hover?"
-
May 15th, 2003, 12:11 PM
#10
Private Sub Form_Load()
Const PBM_SETBARCOLOR = 4381
Dim NEWCOLOR As Long
NEWCOLOR = RGB(250, 0, 0)
Call SendMessage(Me.ProgressBar1.hwnd, PBM_SETBARCOLOR, 0, ByVal NEWCOLOR)
ProgressBar1.Value = 55
End Sub
hi rxbagain
this is how i am trying to change color of progressbar's bar
but it is not working
Const TVM_SETBKCOLOR = 4381
can u explain me this line, i mean y r u using this line
-
May 15th, 2003, 02:13 PM
#11
What is meant by:
In my MSDN, they are located in
Platform SDK ->
User Interface Services ->
Windows Common Controls ->
Tree View Controls ->
Tree View Control Messages
If kids were left to their own devices, would they ever come up with a thing like war?......The Wheel / Todd Rundgren
Do canibals not eat clowns because they taste funny?
-
May 15th, 2003, 06:28 PM
#12
Do you know how I change the color of the text as well? I can't get it to work using the same method, nothing happens.
You can simply change the ForeColor using the node's ForeColor property. Here is my sample that adds 2 nodes and set the forecolor to red
Code:
With Me.TreeView1
.Nodes.Add(Text:="Node1").ForeColor = RGB(255, 0, 0)
.Nodes.Add(Text:="Node2").ForeColor = RGB(255, 0, 0)
End With
Const PBM_SETBARCOLOR = 4381
this is how i am trying to change color of progressbar's bar
but it is not working
PBM_SETBARCOLOR should be 1033, not 4381. If you want to know the values of the constants for common controls. U can use your VC6 to make just a simple console project. and add this code
Code:
#include "stdio.h"
#include "conio.h"
#include "commctrl.h"
void main(void) {
printf("%d", PBM_SETBARCOLOR); //to get the value of PBM_SETBARCOLOR
getch();
}
Run your program and you can see in the console window the value of the constant.
Const TVM_SETBKCOLOR = 4381
can u explain me this line, i mean y r u using this line
The value 4381 is the constant value that is recognized by the TreeView control as a command of setting its backcolor. You cannot just use the value to any other controls. You can get the values of constants as I showed above.
What is meant by:In my MSDN, they are located in
Platform SDK ->
User Interface Services ->
Windows Common Controls ->
Tree View Controls ->
Tree View Control Messages
This are the nodes hierarchy in the Contents Tab of the MSDN
Hope this will help you all
-
May 16th, 2003, 06:21 AM
#13
Does this mean we can also set the color for highlighted text in a textbox?
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
May 16th, 2003, 06:54 AM
#14
Does this mean we can also set the color for highlighted text in a textbox?
I don't know how to change the color of the higlited text in individual windows. To change the color of the selected text in an textbox, I have to change the system color. The effect of this is system wide and it will affect not only textboxes but all highlighted text). Be be sure to set the color back when your done. If you want to try, you can use this code.
Code:
Option Explicit
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex&) As Long
Private Declare Sub SetSysColors Lib "user32" (ByVal nChanges&, lpSysColor&, lpColorValues&)
Const COLOR_HIGHLIGHTTEXT = 14
Dim oldsysColor As Long
Private Sub Form_Load()
Dim colorIndex As Long, colorvalue As Long
colorIndex = COLOR_HIGHLIGHTTEXT
colorvalue = RGB(255, 0, 0)
oldsysColor = GetSysColor(COLOR_HIGHLIGHTTEXT)
Call SetSysColors(1, colorIndex, colorvalue)
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim colorIndex As Long, colorvalue As Long
colorIndex = COLOR_HIGHLIGHTTEXT
colorvalue = oldsysColor
Call SetSysColors(1, colorIndex, colorvalue)
End Sub
Hope this will help you
Last edited by rxbagain; May 16th, 2003 at 07:03 AM.
-
May 16th, 2003, 08:25 AM
#15
rxbagain
Yes, I know that, but I just want to do it with one textbox. However, this gives me an idea. Suppose we change the windows color, and capture the window messages going to the textbox? Won't that tell us what the correct message is?
I tried all message values up to 65535 and it never worked
I found a few interesting ones though.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|