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. help coloring individual listview item instead of all listview item in visual c++ [modified]

help coloring individual listview item instead of all listview item in visual c++ [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++debugginghelp
5 Posts 3 Posters 2 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.
  • M Offline
    M Offline
    method007
    wrote on last edited by
    #1

    Hi all. i am using this code to change color of listview item. But unfortunetly it goes and changes color of all item instead of only changing the color selected listview item. Could an expert look at this and show me how i can only change color of selected listview item instead of coloring all items in listview.Thanks void CColor1Dlg::OnButton1() { HWND hPalWnd = ::FindWindow("my window class", NULL); HWND spilterwindow = FindWindowEx(hPalWnd, 0, "WTL_SplitterWindow", 0); spilterwindow = FindWindowEx(spilterwindow, 0, "WTL_SplitterWindow", 0); HWND ATL = FindWindowEx(spilterwindow, 0, "WTL_SplitterWindow", 0); HWND ATLWIN = FindWindowEx(ATL, 0, "atl:0053c8d0", 0); HWND Dialog = FindWindowEx(ATLWIN, 0, "SysListView32", 0); HWND Rich = FindWindowEx(Dialog, 0, "SysHeader32", 0); CButton *pButton1 = (CButton*)GetDlgItem(IDC_BUTTON1); COLORREF GetBkColor(IDC_BUTTON1); //COLORREF color = m_color.GetColor(); **COLORREF color = 33023;** TRACE("Color of the selected font = %8x\n", color); //CButton *pButton = (CButton*)GetDlgItem(IDC_BUTTON2); //pButton->SetWindowText("Shoot"); **::SendMessage(Dialog, LVM_SETTEXTCOLOR, 0, color);** } -- modified at 12:16 Friday 7th July, 2006

    J 1 Reply Last reply
    0
    • M method007

      Hi all. i am using this code to change color of listview item. But unfortunetly it goes and changes color of all item instead of only changing the color selected listview item. Could an expert look at this and show me how i can only change color of selected listview item instead of coloring all items in listview.Thanks void CColor1Dlg::OnButton1() { HWND hPalWnd = ::FindWindow("my window class", NULL); HWND spilterwindow = FindWindowEx(hPalWnd, 0, "WTL_SplitterWindow", 0); spilterwindow = FindWindowEx(spilterwindow, 0, "WTL_SplitterWindow", 0); HWND ATL = FindWindowEx(spilterwindow, 0, "WTL_SplitterWindow", 0); HWND ATLWIN = FindWindowEx(ATL, 0, "atl:0053c8d0", 0); HWND Dialog = FindWindowEx(ATLWIN, 0, "SysListView32", 0); HWND Rich = FindWindowEx(Dialog, 0, "SysHeader32", 0); CButton *pButton1 = (CButton*)GetDlgItem(IDC_BUTTON1); COLORREF GetBkColor(IDC_BUTTON1); //COLORREF color = m_color.GetColor(); **COLORREF color = 33023;** TRACE("Color of the selected font = %8x\n", color); //CButton *pButton = (CButton*)GetDlgItem(IDC_BUTTON2); //pButton->SetWindowText("Shoot"); **::SendMessage(Dialog, LVM_SETTEXTCOLOR, 0, color);** } -- modified at 12:16 Friday 7th July, 2006

      J Offline
      J Offline
      Justin Tay
      wrote on last edited by
      #2

      That code looks like an absolute nightmare... I think that in order to do what you want you would need to have to do custom draw for your list view.

      M 1 Reply Last reply
      0
      • J Justin Tay

        That code looks like an absolute nightmare... I think that in order to do what you want you would need to have to do custom draw for your list view.

        M Offline
        M Offline
        method007
        wrote on last edited by
        #3

        could u help me how to make a code that custom draw for my list view. I am not very expert in visual c++ so i be happy if u show how this can be done. Furthermore, why u say the code i a nightmare!! it does not crash any thing!!! it just does more then what i wanted it to do!

        PJ ArendsP J 2 Replies Last reply
        0
        • M method007

          could u help me how to make a code that custom draw for my list view. I am not very expert in visual c++ so i be happy if u show how this can be done. Furthermore, why u say the code i a nightmare!! it does not crash any thing!!! it just does more then what i wanted it to do!

          PJ ArendsP Offline
          PJ ArendsP Offline
          PJ Arends
          wrote on last edited by
          #4

          When it comes to doing anything out of the ordinary with a list control then Mike Dunn's article[^] is a must read.


          You may be right I may be crazy -- Billy Joel -- Within you lies the power for good - Use it!

          Within you lies the power for good; Use it!

          1 Reply Last reply
          0
          • M method007

            could u help me how to make a code that custom draw for my list view. I am not very expert in visual c++ so i be happy if u show how this can be done. Furthermore, why u say the code i a nightmare!! it does not crash any thing!!! it just does more then what i wanted it to do!

            J Offline
            J Offline
            Justin Tay
            wrote on last edited by
            #5

            If not crashing is your metric by which you judge a piece of code... then there's nothing much I can say. Why do you have such a long chain of FindWindow() functions? And why aren't you using the RGB macro for generating the COLORREF. I'm sure not many people would know what RGB values make up 33023 offhand. MFC custom draw article http://www.codeproject.com/listctrl/lvcustomdraw.asp[^] WTL custom draw article. http://www.codeproject.com/wtl/customdrawlist_wtl.asp[^]

            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