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. Visual Basic
  4. problem using LVM_SETTEXTBKCOLOR to change color of listview text [modified]

problem using LVM_SETTEXTBKCOLOR to change color of listview text [modified]

Scheduled Pinned Locked Moved Visual Basic
helptutorial
14 Posts 2 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.
  • M Offline
    M Offline
    method007
    wrote on last edited by
    #1

    I am using this code to change text color of listview selected item. But it never works.Could an expert look at it and tell me what i am doing wrong. The hwnd is corect since the line : [code=vb]lItemPos = 0& ' first item SendMessage hwnd, LVM_SETITEMSTATE, lItemPos, ByVal lxprocLVITEM[/code] is working perfectly and is selecing the zero position item for me and highlighting it corectly. Some people suggest i need to send a refresh using LVM_REDRAWITEMS to listview after setting a color for it. But i do not know how to use LVM_REDRAWITEMS. I be happy if an expert help me fix there problems.Thanks not working call to LVM_SETITEMSTATE Private Const LVM_SETTEXTBKCOLOR = (LVM_FIRST + 38) lItemPos = 0& ' first item SendMessage hwnd, LVM_SETITEMSTATE, lItemPos, ByVal lxprocLVITEM 'SendMessage hwnd, LVM_SETTEXTBKCOLOR, 0, hexdec(16711935) 'SendMessage hwnd, LVM_SETTEXTBKCOLOR, 0, 16711935 'SendMessage hwnd, LVM_SETTEXTBKCOLOR, 0&, 0& **SendMessage hwnd, LVM_SETTEXTBKCOLOR, 0, 16711935** -- modified at 12:20 Friday 7th July, 2006

    D 1 Reply Last reply
    0
    • M method007

      I am using this code to change text color of listview selected item. But it never works.Could an expert look at it and tell me what i am doing wrong. The hwnd is corect since the line : [code=vb]lItemPos = 0& ' first item SendMessage hwnd, LVM_SETITEMSTATE, lItemPos, ByVal lxprocLVITEM[/code] is working perfectly and is selecing the zero position item for me and highlighting it corectly. Some people suggest i need to send a refresh using LVM_REDRAWITEMS to listview after setting a color for it. But i do not know how to use LVM_REDRAWITEMS. I be happy if an expert help me fix there problems.Thanks not working call to LVM_SETITEMSTATE Private Const LVM_SETTEXTBKCOLOR = (LVM_FIRST + 38) lItemPos = 0& ' first item SendMessage hwnd, LVM_SETITEMSTATE, lItemPos, ByVal lxprocLVITEM 'SendMessage hwnd, LVM_SETTEXTBKCOLOR, 0, hexdec(16711935) 'SendMessage hwnd, LVM_SETTEXTBKCOLOR, 0, 16711935 'SendMessage hwnd, LVM_SETTEXTBKCOLOR, 0&, 0& **SendMessage hwnd, LVM_SETTEXTBKCOLOR, 0, 16711935** -- modified at 12:20 Friday 7th July, 2006

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Are you doing this so you can change that appearance of a listview in your own app or another one?? If your doing this in your own ass, you're going about it the hard way. search the articles for "ownerdraw listview" and you'll come up with a few good examples. Dave Kreskowiak Microsoft MVP - Visual Basic

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Are you doing this so you can change that appearance of a listview in your own app or another one?? If your doing this in your own ass, you're going about it the hard way. search the articles for "ownerdraw listview" and you'll come up with a few good examples. Dave Kreskowiak Microsoft MVP - Visual Basic

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

        I am doing this for external listview . I mean in another application that i do not have its source code!

        D 1 Reply Last reply
        0
        • M method007

          I am doing this for external listview . I mean in another application that i do not have its source code!

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          OK. Well, the docs on the LVM_REDRAWITEMS[^] message are pretty straight forward. You already have the mechanism to send the message. All you need to do is supply the listviews first and last item numbers that need to be redrawn. Now, you have a second, more serious problem, that you can't get around. If this was your own ListView and your were ownerdrawing it, your code would have to be written to specifically handle this message. I have yet to see an ownerdrawn ListView that does this. If the app your trying to control like this ownerdraws its ListView control, you're S.O.L, and none of this will ever matter. Dave Kreskowiak Microsoft MVP - Visual Basic

          M 1 Reply Last reply
          0
          • D Dave Kreskowiak

            OK. Well, the docs on the LVM_REDRAWITEMS[^] message are pretty straight forward. You already have the mechanism to send the message. All you need to do is supply the listviews first and last item numbers that need to be redrawn. Now, you have a second, more serious problem, that you can't get around. If this was your own ListView and your were ownerdrawing it, your code would have to be written to specifically handle this message. I have yet to see an ownerdrawn ListView that does this. If the app your trying to control like this ownerdraws its ListView control, you're S.O.L, and none of this will ever matter. Dave Kreskowiak Microsoft MVP - Visual Basic

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

            could u tell me what should i put for the parameters in my case : SendMessage( // returns LRESULT in lResult (HWND) hWndControl, // handle to destination control (UINT) LVM_SETTEXTCOLOR, // message ID (WPARAM) wParam, // = 0; not used, must be zero (LPARAM) lParam // = (LPARAM) (COLORREF) clrText; ); I have no idea what should put and replace what ?

            D 1 Reply Last reply
            0
            • M method007

              could u tell me what should i put for the parameters in my case : SendMessage( // returns LRESULT in lResult (HWND) hWndControl, // handle to destination control (UINT) LVM_SETTEXTCOLOR, // message ID (WPARAM) wParam, // = 0; not used, must be zero (LPARAM) lParam // = (LPARAM) (COLORREF) clrText; ); I have no idea what should put and replace what ?

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Don't tell me you copy-paste-and-prayed the code you posted?? LVM_REDRAWITEMS is (LVM_FIRST + 21) The wParam value should be the index number of the first ListView item that needs to be redrawn. The lParam value should be the index of the last item. So, you're code would be something like:

              Private Const LVM_REDRAWITEMS = (LVM_FIRST + 21)
              .
              .
              .
              SendMessage hwnd, LVM_REDRAWITEMS, firstItemIndex, lastItemIndex

              Dave Kreskowiak Microsoft MVP - Visual Basic

              M 1 Reply Last reply
              0
              • D Dave Kreskowiak

                Don't tell me you copy-paste-and-prayed the code you posted?? LVM_REDRAWITEMS is (LVM_FIRST + 21) The wParam value should be the index number of the first ListView item that needs to be redrawn. The lParam value should be the index of the last item. So, you're code would be something like:

                Private Const LVM_REDRAWITEMS = (LVM_FIRST + 21)
                .
                .
                .
                SendMessage hwnd, LVM_REDRAWITEMS, firstItemIndex, lastItemIndex

                Dave Kreskowiak Microsoft MVP - Visual Basic

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

                It does not work !!! SendMessage hwnd, LVM_REDRAWITEMS, 0, 12

                D 1 Reply Last reply
                0
                • M method007

                  It does not work !!! SendMessage hwnd, LVM_REDRAWITEMS, 0, 12

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  Then it's entirely possible that the ListView you're trying to control is ownerdrawn by the other application. In which case, there's nothing you can do to get the effect you want. This is because the ownerdraw code will always paint the items exactly how its written to, ignoring the attributes that your injecting into the items list. Dave Kreskowiak Microsoft MVP - Visual Basic -- modified at 16:16 Friday 7th July, 2006

                  M 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    Then it's entirely possible that the ListView you're trying to control is ownerdrawn by the other application. In which case, there's nothing you can do to get the effect you want. This is because the ownerdraw code will always paint the items exactly how its written to, ignoring the attributes that your injecting into the items list. Dave Kreskowiak Microsoft MVP - Visual Basic -- modified at 16:16 Friday 7th July, 2006

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

                    That is not true that the listview is overdrwan by diffrent application. Since i got visual c++ version of same code and it is corectly changing the color!! I think there is problem in calling refresh and redraw ! -- modified at 16:17 Friday 7th July, 2006

                    D 1 Reply Last reply
                    0
                    • M method007

                      That is not true that the listview is overdrwan by diffrent application. Since i got visual c++ version of same code and it is corectly changing the color!! I think there is problem in calling refresh and redraw ! -- modified at 16:17 Friday 7th July, 2006

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      method007 wrote:

                      is working perfectly and is selecing the zero position item for me and highlighting it corectly. Some people suggest i need to send a refresh using LVM_REDRAWITEMS to listview after setting a color for it. But i do not know how to use LVM_REDRAWITEMS. I be happy if an expert help me fix there problems.Thanks

                      Then I'm failing to see what your problem is or what your intended effect is... You're original post said the code is working, but in the next sentence, says that people are suggesting sending other messages. What's broken?? Are you saying that you have C++ code that is working, but when you try to convert it to VB.NET it isn't?? Dave Kreskowiak Microsoft MVP - Visual Basic -- modified at 16:21 Friday 7th July, 2006

                      M 1 Reply Last reply
                      0
                      • D Dave Kreskowiak

                        method007 wrote:

                        is working perfectly and is selecing the zero position item for me and highlighting it corectly. Some people suggest i need to send a refresh using LVM_REDRAWITEMS to listview after setting a color for it. But i do not know how to use LVM_REDRAWITEMS. I be happy if an expert help me fix there problems.Thanks

                        Then I'm failing to see what your problem is or what your intended effect is... You're original post said the code is working, but in the next sentence, says that people are suggesting sending other messages. What's broken?? Are you saying that you have C++ code that is working, but when you try to convert it to VB.NET it isn't?? Dave Kreskowiak Microsoft MVP - Visual Basic -- modified at 16:21 Friday 7th July, 2006

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

                        i mean i have visual c++ version of code and it is working but i try to convert it to visual basic 6 and it is not working. they suggest the redraw methond and non works!! It was mentiioned that some other application is sending redraw so that is why it is not working the give code and i said no because the visual c++ is working corectly Now all i want to make this work . It is visual basic 6 code!

                        D 1 Reply Last reply
                        0
                        • M method007

                          i mean i have visual c++ version of code and it is working but i try to convert it to visual basic 6 and it is not working. they suggest the redraw methond and non works!! It was mentiioned that some other application is sending redraw so that is why it is not working the give code and i said no because the visual c++ is working corectly Now all i want to make this work . It is visual basic 6 code!

                          D Offline
                          D Offline
                          Dave Kreskowiak
                          wrote on last edited by
                          #12

                          We'll have to see the C++ code you're using and the VB6 code came up with from it. There's obviously something missing... Dave Kreskowiak Microsoft MVP - Visual Basic

                          M 1 Reply Last reply
                          0
                          • D Dave Kreskowiak

                            We'll have to see the C++ code you're using and the VB6 code came up with from it. There's obviously something missing... Dave Kreskowiak Microsoft MVP - Visual Basic

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

                            Here is the visual c++ version : 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); }

                            D 1 Reply Last reply
                            0
                            • M method007

                              Here is the visual c++ version : 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); }

                              D Offline
                              D Offline
                              Dave Kreskowiak
                              wrote on last edited by
                              #14

                              And the VB6 code??? Dave Kreskowiak Microsoft MVP - Visual Basic

                              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