Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Change text color of selected item in a tree control

Change text color of selected item in a tree control

Scheduled Pinned Locked Moved C / C++ / MFC
data-structurestutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TobetheWinner
    wrote on last edited by
    #1

    My requirement is If i select an item in a tree Control that Selected item's color of text should be changed.(or i want to recognize whether it is selected or not--some way to identify)So can you please tell me how to do it. bhw

    H N 2 Replies Last reply
    0
    • T TobetheWinner

      My requirement is If i select an item in a tree Control that Selected item's color of text should be changed.(or i want to recognize whether it is selected or not--some way to identify)So can you please tell me how to do it. bhw

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      See this[^] article.


      WhiteSky


      1 Reply Last reply
      0
      • T TobetheWinner

        My requirement is If i select an item in a tree Control that Selected item's color of text should be changed.(or i want to recognize whether it is selected or not--some way to identify)So can you please tell me how to do it. bhw

        N Offline
        N Offline
        Naveen
        wrote on last edited by
        #3

        Handle the NM_CUTOME draw message and put the following code inside it. void TreeCtrlEx::OnCustomDraw( NMHDR* pNMHDR_i, LRESULT* pResult_o ) { NMTVCUSTOMDRAW* pLVCD = reinterpret_cast( pNMHDR_i ); NMCUSTOMDRAW &nMcd = pLVCD->nmcd; *pResult_o = CDRF_DODEFAULT; switch( nMcd.dwDrawStage ) { case CDDS_PREPAINT: // Item prepaint notification. *pResult_o = CDRF_NOTIFYITEMDRAW; break; case CDDS_ITEMPREPAINT: { // Set the color of the text according to its state. HTREEITEM nRow = reinterpret_cast< HTREEITEM >( nMcd.dwItemSpec ); if( CDIS_SELECTED == ( nMcd.uItemState & CDIS_SELECTED )) { pLVCD->clrText = clrSelText;// Selected text color pLVCD->clrTextBk = clrSelBk;// Selceted backgroung } else { pLVCD->clrText = clrNormal;// text color in normal state pLVCD->clrTextBk = clrBk// bakck ground color in normal state } // Allow it to do the default painting. *pResult_o = CDRF_DODEFAULT; break; } default: *pResult_o = CDRF_DODEFAULT; break; } }

        nave [OpenedFileFinder]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups