CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Jul 2002
    Location
    England
    Posts
    163

    Lightbulb 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?"

  2. #2
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487

    Thumbs down

    Not possible.. It is a windows common control..
    Busy

  3. #3
    Join Date
    Apr 2003
    Posts
    1,755

    Smile

    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

  4. #4
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    Excellent rxbagain!! Can you share that TreeView WMessages?
    Busy

  5. #5
    Join Date
    Apr 2003
    Posts
    1,755

    Smile

    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.

  6. #6
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    How about the message values??
    Busy

  7. #7
    Join Date
    Apr 2003
    Posts
    1,755

    Smile

    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

  8. #8
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487

    Windows Messages

    Thanks to rxbagain.. We have now the windows messages which are not included in the VB api viewer..

    Cheers!
    Busy

  9. #9
    Join Date
    Jul 2002
    Location
    England
    Posts
    163
    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?"

  10. #10
    Join Date
    Jul 2001
    Location
    maharashtra,india
    Posts
    181
    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

  11. #11
    Join Date
    Jan 2001
    Posts
    486
    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?

  12. #12
    Join Date
    Apr 2003
    Posts
    1,755

    Smile

    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

  13. #13
    Join Date
    Dec 2001
    Posts
    6,332
    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?

  14. #14
    Join Date
    Apr 2003
    Posts
    1,755

    Smile

    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.

  15. #15
    Join Date
    Dec 2001
    Posts
    6,332
    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
  •  





Click Here to Expand Forum to Full Width

Featured