Announcement

Collapse
No announcement yet.

Treeview text color

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Treeview text color

    Is it possible to set the text color of an individual treeview item after it's creation.

    Why? I'd like to set black available programs and a light gray for disabled programs based on the user's clearance level. Also a third color for programs that are available but not licensed..

    Bob Mechler

  • #2
    Yes, using custom draw.

    The common controls (ie. Treeview) send the NM_CUSTOMDRAW notification message through the WM_NOTIFY message.

    The parent dialog processes the WM_NOTIFY message and tests for the NM_CUSTOMDRAW notification message.

    In the WM_NOTIFY message the lParam value contains a pointer to the NMHDR structure.

    It contains 3 members:

    Code:
    TYPE NMHDR
      hwndFrom AS DWORD   ' handle of control sending message
      idfrom AS DWORD        ' ID of same control
      code AS LONG            ' notification message or code
    END TYPE
    When the common controls send the WM_NOTIFY message to the parent dialogs dialog procedure, they often pass a pointer to a larger structure than NMHDR, but the structure always has the NMHDR structure members at the beginning.

    The NM_CUSTOMDRAW message constant is tested in the code member of the NMHDR structure (via a pointer).

    When the NM_CUSTOMDRAW notification message occurs for the treeview, the pointer in lParam points to the NMTVCUSTOMDRAW structure. Notice that structure starts with the NMCUSTOMDRAW structure and that structure starts with the NMHDR structure (which all WM_NOTIFY messages use).

    Code:
     
    '
    TYPE NMCUSTOMDRAW
        hdr         AS NMHDR
        dwDrawStage AS DWORD
        hdc         AS DWORD
        rc          AS RECT
        dwItemSpec  AS DWORD  ' this is control specific, but it's how to specify an item. valid only with CDDS_ITEM bit set
        uItemState  AS DWORD
        lItemlParam AS LONG
    END TYPE
    '
    TYPE NMTVCUSTOMDRAW
        nmcd      AS NMCUSTOMDRAW
        clrText   AS DWORD
        clrTextBk AS DWORD
        iLevel    AS LONG
    END TYPE
    At this point I would suggest reading the API docs about using these messages. You can actually set the text color for each item in a treeview control using this message, but it is a little more complicated that what I have discusses so far. You have to test for events in NM_CUSTOMDRAW like CDDS_PREPAINT.

    Search the forums for NM_CUSTOMDRAW to find some code examples.
    Chris Boss
    Computer Workshop
    Developer of "EZGUI"
    http://cwsof.com
    http://twitter.com/EZGUIProGuy

    Comment


    • #3
      Thanks,

      I appreciate the detailed answer. I'm a little familiar with NMHDR but not NMCUSTOMDRAW.

      I have win32.hlp but it doesn't seem to list some of the items and topics I've asked questions about recently. Should I just use msdn's help or is there a more up to date api docs somewhere.

      Bob Mechler

      Comment


      • #4
        Bob,

        When working with the Windows API, I find the win32 help file a bit useless, since it is not an extensive document.

        I strongly recommend that anyone who wants to learn the API, purchase the latest Windows SDK CD from Microsoft. The CD is usually free, but you just pay a small charge for shipping and handling. I paid $10 for mine.

        It can be found at the Microsoft MSDN web site.
        Chris Boss
        Computer Workshop
        Developer of "EZGUI"
        http://cwsof.com
        http://twitter.com/EZGUIProGuy

        Comment


        • #5
          Bob,

          You can read the online version of the API docs at MSDN (Microsoft Developers Network):

          Here is info about custom draw and the treeview:

          http://msdn.microsoft.com/en-us/libr...17(VS.85).aspx
          Chris Boss
          Computer Workshop
          Developer of "EZGUI"
          http://cwsof.com
          http://twitter.com/EZGUIProGuy

          Comment

          Working...
          X