Get CListCtrl scrollbar rectangle
-
How can I get the CListCtrl scrollbar rectangle ? Whether the scrollbar is visible or not, I tested in following way:
if(GetStyle() & WS\_VSCROLL) { }
but, in order to change the scrollbar background by DrawThemeBackground[^], I need the scrollbar rectangle ... how can I retrieve the scrollbar rectangle ?
-
How can I get the CListCtrl scrollbar rectangle ? Whether the scrollbar is visible or not, I tested in following way:
if(GetStyle() & WS\_VSCROLL) { }
but, in order to change the scrollbar background by DrawThemeBackground[^], I need the scrollbar rectangle ... how can I retrieve the scrollbar rectangle ?
Just call GetScrollBarInfo[^] passing
OBJID_VSCROLL
as idObject parameter. -
Just call GetScrollBarInfo[^] passing
OBJID_VSCROLL
as idObject parameter.Thank you Jochen ... the rectangle is retrieve it ... :) I have to dig in, because it seems that something is wrong in my code, because though rectangle is correct now, the color of scrollbar is not drawn ...
void CGridCtrlExt::OnDraw(CDC* pDC)
{
// draw the gridHTHEME hTheme = OpenThemeData(m\_hWnd, L"WINDOW");
// HTHEME hTheme = OpenThemeData(m_hWnd, L"MFCGridCtrl");
if(NULL != hTheme)
{
if(WS_VSCROLL & GetStyle())
{
SCROLLBARINFO si;
si.cbSize = sizeof(SCROLLBARINFO);
GetScrollBarInfo(OBJID_VSCROLL, &si);
CRect rect(si.rcScrollBar);
pDC->FillSolidRect(&rect, RGB(255, 255, 0));
DrawThemeBackground(hTheme, pDC->GetSafeHdc(), WP_VERTSCROLL, VSS_NORMAL, &rect, NULL);
}
CloseThemeData(hTheme);
}
} -
Thank you Jochen ... the rectangle is retrieve it ... :) I have to dig in, because it seems that something is wrong in my code, because though rectangle is correct now, the color of scrollbar is not drawn ...
void CGridCtrlExt::OnDraw(CDC* pDC)
{
// draw the gridHTHEME hTheme = OpenThemeData(m\_hWnd, L"WINDOW");
// HTHEME hTheme = OpenThemeData(m_hWnd, L"MFCGridCtrl");
if(NULL != hTheme)
{
if(WS_VSCROLL & GetStyle())
{
SCROLLBARINFO si;
si.cbSize = sizeof(SCROLLBARINFO);
GetScrollBarInfo(OBJID_VSCROLL, &si);
CRect rect(si.rcScrollBar);
pDC->FillSolidRect(&rect, RGB(255, 255, 0));
DrawThemeBackground(hTheme, pDC->GetSafeHdc(), WP_VERTSCROLL, VSS_NORMAL, &rect, NULL);
}
CloseThemeData(hTheme);
}
}This may be because the scroll bar is redrawn by the system. You may use a custom drawn scroll bar or handle
WM_CTLCOLOR
when you only need to change the background. Searching the web may give you some solutions. The article http://www.drdobbs.com/windows/developing-a-custom-windows-scrollbar-in/184416659[^] is rather old but contains a good introduction and shows how to implement a custom drawn scroll bar. -
This may be because the scroll bar is redrawn by the system. You may use a custom drawn scroll bar or handle
WM_CTLCOLOR
when you only need to change the background. Searching the web may give you some solutions. The article http://www.drdobbs.com/windows/developing-a-custom-windows-scrollbar-in/184416659[^] is rather old but contains a good introduction and shows how to implement a custom drawn scroll bar."You may use a custom drawn scroll bar or handle WM_CTLCOLOR when you only need to change the background" I already tried that ... if I override WM_CTLCOLOR I could color everything, except scrollbars ... :) "Searching the web may give you some solutions. The article http://www.drdobbs.com/windows/developing-a-custom-windows-scrollbar-in/184416659\[^\] is rather old but contains a good introduction and shows how to implement a custom drawn scroll bar." I saw that article, but is about replacing the original scrollbar with CScrollBarEx control ... well, in this case I will front with 2 issues: hiding the original scrollbar, and second, synchronize the listctrl with CScrollbarEx control ... I think that is the longest road ... and the hardest ... I thought that trying to use
DrawThemeBackground
I could change the scrollbars colors ... :( I am working on that for weeks ... I have to dig in ... -
This may be because the scroll bar is redrawn by the system. You may use a custom drawn scroll bar or handle
WM_CTLCOLOR
when you only need to change the background. Searching the web may give you some solutions. The article http://www.drdobbs.com/windows/developing-a-custom-windows-scrollbar-in/184416659[^] is rather old but contains a good introduction and shows how to implement a custom drawn scroll bar. -
"This may be because the scroll bar is redrawn by the system" I wonder if I put properly the scrollbar coloring code ... inside of
CMyControl::OnDraw
is ok ? I guess not ...OnDraw
is aCView
member function. You probably mean some kind of custom / owner draw. But this won't work for the scroll bars of list controls because only the list control content can be changed by this method. The scroll bar is still drawn by the system when necessary and your drawing vanishes. If handlingWM_CTLCOLOR
did not work (and I believe meanwhile that it does not work with list controls), the only solution is using a complety custom drawn control or another GUI framework like Qt. -
OnDraw
is aCView
member function. You probably mean some kind of custom / owner draw. But this won't work for the scroll bars of list controls because only the list control content can be changed by this method. The scroll bar is still drawn by the system when necessary and your drawing vanishes. If handlingWM_CTLCOLOR
did not work (and I believe meanwhile that it does not work with list controls), the only solution is using a complety custom drawn control or another GUI framework like Qt.Thank you so much for your attention Jochen ! In the real situation, I used an CGridCtrl, and this control has
CGridCtrl::OnDraw
to drawing itself ... but there is no difference between this kind of control or CListCtrl, or CListBox ... I had tried to change the color of the scrollbars of these last ones and I didn't succeded ... After all, CGridCtrl is derived from CWnd, so is the same matter ... Should be a chance to move that code on some handler that is called after the system is redrawing the scrollbars ? ... who knows ... I should dig in ...