Using a Dialog Bar with a Rebar Control
As mentioned in Rebar Controls and Bands, each band can contain only one child window (or control). This might be a limitation if you want to have more than one child window per band. A convenient workaround is to create a dialog bar resource with multiple controls and then add a rebar band (containing the dialog bar) to the rebar control.
Normally, if you wanted the dialog bar band to appear transparent, you would set the WM_EX_TRANSPARENT extended style for the dialog bar object. However, because WM_EX_TRANSPARENT has some issues with properly painting the background of a dialog bar, you will need to do a little extra work to achieve the desired effect.
The following procedure details the steps necessary to achieve transparency without using the WM_EX_TRANSPARENT extended style.
To implement a transparent dialog bar in a rebar band
Using ClassWizard, add a new class (for example,
CMyDlgBar
) that implements your dialog bar object.Add a handler for the WM_ERASEBKGND message.
In the new handler, modify the existing code to match the following example:
BOOL CMyDlgBar::OnEraseBkgnd( CDC* pDC ) { CWnd* pParent = GetParent(); ASSERT_VALID(pParent); CPoint pt(0, 0); MapWindowPoints(pParent, &pt, 1); pt = pDC->OffsetWindowOrg(pt.x, pt.y); LRESULT lResult = pParent->SendMessage(WM_ERASEBKGND, (WPARAM)pDC->m_hDC, 0L); pDC->SetWindowOrg(pt.x, pt.y); return lResult; }
Add a handler for the WM_MOVE message.
In the new handler, modify the existing code to match the following example:
BOOL CMyDlgBar::OnMove( int cx, int cy ) { Invalidate(); }
The new handlers simulate the transparency of the dialog bar by forwarding the WM_ERASEBKGND message to the parent window and forcing a repaint every time the dialog bar object is moved.