WXHBRUSH wxControl::DoMSWControlColor(WXHDC pDC, wxColour colBg, WXHWND hWnd) { HDC hdc = (HDC)pDC; if ( m_hasFgCol ) { ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour())); } WXHBRUSH hbr = 0; if ( !colBg.Ok() ) { hbr = MSWGetBgBrush(pDC, hWnd); // if the control doesn't have any bg colour, foreground colour will be // ignored as the return value would be 0 -- so forcefully give it a // non default background brush in this case if ( !hbr && m_hasFgCol ) colBg = GetBackgroundColour(); } // use the background colour override if a valid colour is given if ( colBg.Ok() ) { ::SetBkColor(hdc, wxColourToRGB(colBg)); // draw children with the same colour as the parent wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBg, wxSOLID); hbr = (WXHBRUSH)brush->GetResourceHandle(); // if we use custom background, we should set foreground ourselves too if ( !m_hasFgCol ) { ::SetTextColor(hdc, ::GetSysColor(COLOR_WINDOWTEXT)); } //else: already set above } return hbr; }
// helper for OnPaint(): really erase the background, i.e. do it even if we // don't have any non default brush for doing it (DoEraseBackground() doesn't // do anything in such case) void wxStaticBox::PaintBackground(wxDC& dc, const RECT& rc) { // note that we do not use the box background colour here, it shouldn't // apply to its interior for several reasons: // 1. wxGTK doesn't do it // 2. controls inside the box don't get correct bg colour because they // are not our children so we'd have some really ugly colour mix if // we did it // 3. this is backwards compatible behaviour and some people rely on it, // see http://groups.google.com/groups?selm=4252E932.3080801%40able.es wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl(); HBRUSH hbr = MSWGetBgBrush(impl->GetHDC()); // if there is no special brush for painting this control, just use the // solid background colour wxBrush brush; if ( !hbr ) { brush = wxBrush(GetParent()->GetBackgroundColour()); hbr = GetHbrushOf(brush); } ::FillRect(GetHdcOf(*impl), &rc, hbr); }