problem using LVM_SETTEXTBKCOLOR to change color of listview text [modified]
-
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 -
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, 2006Are 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
-
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
-
I am doing this for external listview . I mean in another application that i do not have its source code!
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
-
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
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 ? -
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 ?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, lastItemIndexDave Kreskowiak Microsoft MVP - Visual Basic
-
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, lastItemIndexDave Kreskowiak Microsoft MVP - Visual Basic
-
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
-
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
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
-
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
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
-
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
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!
-
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!
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
-
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
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); }
-
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); }
And the VB6 code??? Dave Kreskowiak Microsoft MVP - Visual Basic