|
|
|
|
Forum
Please
Log In
to post a new message or reply to an existing one. If you are not registered, please
register.
NOTE: Some forums may be read-only if you are not currently subscribed to
our technical support services.
Subject |
Author |
Date |
|
James Hughes
|
Feb 9, 2004 - 1:57 PM
|
Hi I’m trying to create a child window (custom drawn control) on a window (which happens to the child of another). The parent window is filled with a custom gardient, when I create the child it is always filling in the rectangle in white. I am more than likely be silly here. Both windows are derived from a class which extends CWnd. It handles the WM_ERASEBKGRND & WM_PAINT messages. The WM_PAINT function is defined as follows:
void CSEWnd::OnPaint() {
CRect clientRect;
CPaintDC dcPaint( this);
GetClientRect(clientRect);
CExtMemoryDC dc( &dcPaint, &clientRect ); // Exclude the child areas from repaints
CExtPaintManager::stat_ExcludeChildAreas(
dcPaint.GetSafeHdc(),
GetSafeHwnd()
); // Emulate erase background
DefWindowProc( WM_ERASEBKGND, WPARAM( dc.GetSafeHdc() ), LPARAM(0) ); // Store original colour & modes int nOldBkMode = dc.GetBkMode();
COLORREF crOldTxtColour = dc.GetTextColor();
CExtMemoryDC dcsrc;
dcsrc.CreateCompatibleDC( &dc );
// Call the derived classes OnDraw function
OnDraw( dc, clientRect ); // Restore old colours
dc.SetTextColor( crOldTxtColour );
dc.SetBkMode(nOldBkMode);
}
Any ideas what I am doing wrong here?
Cheers
James Hughes
|
|
Technical Support
|
Feb 10, 2004 - 3:43 AM
|
Dear James,
We believe that the WM_PAINT handler is not the best place to process WM_ERASEBKGND messages. To resolve the problem with an invalid background drawing, please modify the WindowProc method of your control (or alternatively you could modify the handlers of the WM_ERASEBKGND and WM_PAINT messages):
virtual LRESULT WindowProc(
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
if( uMsg == WM_ERASEBKGND )
return (!0);
if( uMsg == WM_PAINT )
{
CRect rcClient;
GetClientRect( &rcClient );
CPaintDC dcPaint( this );
CExtMemoryDC dc( &dcPaint, &rcClient );
bool bTransparentBk = false;
if( g_PaintManager->GetCb2DbTransparentMode(this) )
{
// paint gradient backgroung
CExtPaintManager::stat_ExcludeChildAreas(
dc,
GetSafeHwnd(),
CExtPaintManager::stat_DefExcludeChildAreaCallback
);
if( g_PaintManager->PaintDockerBkgnd( dc, this ) )
bTransparentBk = true;
} // if( g_PaintManager->GetCb2DbTransparentMode(this) )
if( !bTransparentBk )
// paint solid backgroung
dc.FillSolidRect( &rcClient, g_PaintManager->GetColor( CExtPaintManager::CLR_3DFACE_OUT) );
// place your painting code here
// .........
g_PaintManager->OnPaintSessionComplete( this );
return 0;
}
return CWnd::WindowProc(uMsg, wParam, lParam);
}
All should work OK after that.
|
|