Coloring scrollbar with DrawThemeBackground
-
I am struggling for some while to coloring a control scrollbar, with
DrawThemeBackground
. (any control, no matter what) ... here is the trial:void CMyControl::OnDraw(CDC* pDC)
{
// draw control
HTHEME 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, 0, 0));
HRESULT hResult = DrawThemeBackground(hTheme, pDC->GetSafeHdc(), SBP_LOWERTRACKVERT, SCRBS_NORMAL, &rect, NULL);
if(S_OK == hResult)
TRACE("ok\n");
else
TRACE("not ok !\n");
}
CloseThemeData(hTheme);
}
}And I always get not ok ! ... What I'am doing wrong here ? The scrollbar rectangle are ok, I verified ... can you help me ? Thank you.
-
I am struggling for some while to coloring a control scrollbar, with
DrawThemeBackground
. (any control, no matter what) ... here is the trial:void CMyControl::OnDraw(CDC* pDC)
{
// draw control
HTHEME 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, 0, 0));
HRESULT hResult = DrawThemeBackground(hTheme, pDC->GetSafeHdc(), SBP_LOWERTRACKVERT, SCRBS_NORMAL, &rect, NULL);
if(S_OK == hResult)
TRACE("ok\n");
else
TRACE("not ok !\n");
}
CloseThemeData(hTheme);
}
}And I always get not ok ! ... What I'am doing wrong here ? The scrollbar rectangle are ok, I verified ... can you help me ? Thank you.
Print the
HRESULT
code upon failure. It may help to identify the error source (e.g. by printing the corresponding error message usingFormatMessage
or searching for the code in WinError.h). -
I am struggling for some while to coloring a control scrollbar, with
DrawThemeBackground
. (any control, no matter what) ... here is the trial:void CMyControl::OnDraw(CDC* pDC)
{
// draw control
HTHEME 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, 0, 0));
HRESULT hResult = DrawThemeBackground(hTheme, pDC->GetSafeHdc(), SBP_LOWERTRACKVERT, SCRBS_NORMAL, &rect, NULL);
if(S_OK == hResult)
TRACE("ok\n");
else
TRACE("not ok !\n");
}
CloseThemeData(hTheme);
}
}And I always get not ok ! ... What I'am doing wrong here ? The scrollbar rectangle are ok, I verified ... can you help me ? Thank you.
-
Print the
HRESULT
code upon failure. It may help to identify the error source (e.g. by printing the corresponding error message usingFormatMessage
or searching for the code in WinError.h). -
I cheked:
E_FAIL Unspecified failure 0x80004005
I am stuck :( P.S. But I would try FormatMessage too ...
Flaviu2 wrote:
But I would try FormatMessage too
That would not help because it will print something similar ("Unspecified error") in the current Windows system language. I'm sorry, but I have no other ideas.
-
Flaviu2 wrote:
But I would try FormatMessage too
That would not help because it will print something similar ("Unspecified error") in the current Windows system language. I'm sorry, but I have no other ideas.
-
I would check the exact value of
hResult
, however the documentation page is not encouraging (see the comment at the bottom of the page)[^]. -
Flaviu2 wrote:
But I would try FormatMessage too
That would not help because it will print something similar ("Unspecified error") in the current Windows system language. I'm sorry, but I have no other ideas.
I have tried also:
HTHEME hTheme = OpenThemeData(m\_hWnd, L"SCROLLBAR");
// HTHEME 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));
HRESULT hRes = DrawThemeBackground(
hTheme,
pDC->GetSafeHdc(),
SBP_UPPERTRACKVERT,
SCRBS_NORMAL,
&rect,
NULL);
TRACE("HRESULT: %d|%d: OK ? %d\n", hRes, S_OK, hRes == S_OK);
}
CloseThemeData(hTheme);
}And the result are S_OK now, which is good, however, I have seen nothing colored ... strange ...