HBRUSH CMyPropertyPage1::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CPropertyPage::OnCtlColor(pDC, pWnd, nCtlColor);
static CBrush s_brush(RGB(0,255,255));
// Change text color.
pDC->SetTextColor(RGB(255,0,0));
// Change Background color.
pDC->SetBkColor(RGB(255,255,0));
return s_brush; // return background brush
}
"Feng" <fli...@raesystems.com> wrote in message
news:u9u33rAHAHA.253@cppssbbsa05...
>
> Hi, there,
>
> I don't want the property sheet looks gray, so, I changed every page to
> Black
> by overriding the OnPaint(); change most part of the propertysheet to
black
> by overriding the EraseBkGnd(). But the part in the Tab controls doesn't
> change, how can I change there to black too?
>
> See the following jpg.
>
> Thanks
> Feng
>
>
>
>
Here's a plan...
1. Use ClassWizard to derive your own class from CTabCtrl.
2. Use ClassWizard to add an OnEraseBkgnd handler to this class.
3. Fill it in something like this...
BOOL CMyTabCtrl::OnEraseBkgnd(CDC* pDC)
{
static CBrush brush(RGB(0,0,0));
CRect rc;
pDC->SaveDC();
pDC->GetClipBox(&rc);
pDC->SelectObject(brush);
pDC->PatBlt(rc.left, rc.top, rc.Width(), rc.Height(), PATCOPY);
pDC->RestoreDC(-1);
return TRUE;
}
4. Use ClassWizard to add a member variable of this class type to your CPropertySheet class.
5. Use ClassWizard to add an override for the virtual OnInitDialog function to your CPropertySheet
class.
6. Add a line like this (after the call to the base class) to your OnInitDialog override...
m_yourTabCtrl.SubclassWindow(GetTabControl()->m_hWnd);
Where m_yourTabCtrl is the name you gave the member variable in step 4. Your margin area will now be
painted black, but your tabs will remain the default grey. Do you want to color these black too?
HTH,
Jeff...
--
Please post all follow-ups to the newsgroup only.
Feng wrote in message ...
Thanks a lot, it works!
> Where m_yourTabCtrl is the name you gave the member variable in step 4.
Your margin area will now be
> painted black, but your tabs will remain the default grey. Do you want to
color these black too?
If I want to make the tabs black with white text in it, how to?
And if I want to add this property sheet in a FormView, and a static Frame
was used as its holder. How can I make its holder black too? There is always
a default gray margin in the holder.
Thank again,
Feng
Sorry, I am too stupid to ask the above question, I figure it out easily.
But I do want to know how to change the color of each tab?
Thank you for your time.
Feng
>But I do want to know how to change the color of each tab?
Okay, but there's two things: 1) I think it requires going owner-draw, and 2) Ownerdraw is not one
of my strengths. Having said that here's a quick example...
1. Use ClassWizard to add an override for the PreSubclassWindow function in your derived CTabCtrl.
void CMyTabCtrl::PreSubclassWindow()
{
ASSERT(::IsWindow(m_hWnd));
ModifyStyle(0,TCS_OWNERDRAWFIXED);
}
2. ClassWizard won't help so manually add the declaration for the DrawItem override to your CTabCtrl
class's header, and then add the function definition to the *.cpp file (something like this)...
void CMyTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
CDC* pDC = CDC::FromHandle(lpDIS->hDC);
CRect rc(lpDIS->rcItem);
CString strTabText;
TC_ITEM tci;
ZeroMemory(&tci,sizeof(tci));
tci.mask = TCIF_TEXT;
tci.cchTextMax = 254;
tci.pszText = strTabText.GetBufferSetLength(tci.cchTextMax+1);
GetItem(lpDIS->itemID, &tci);
strTabText.ReleaseBuffer();
pDC->SaveDC();
pDC->SetTextColor(RGB(255,255,255));
pDC->SetBkColor(RGB(0,0,0));
if (lpDIS->itemState & ODS_SELECTED)
pDC->FillSolidRect(&rc, RGB(0,0,0));
pDC->TextOut(rc.left+5, rc.top+5, strTabText);
pDC->RestoreDC(-1);
}
Anyway, that seems to work for me. Just to share the credit (or blame) this was all based on the
MSDN Article Q206626, "HOWTO: Change the Text Color of the Selected Property Sheet Tab", and a
couple of articles by Paul DiLascia from his C++ Q&A column in the March and the August 1998 issues
of MSJ.