Professional UI Solutions
Site Map   /  Register
 
 

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.

Forums » Prof-UIS General Discussion » CExtColorCtrl + Background Collapse All
Subject Author Date
Sebstian Leopold Dec 10, 2006 - 7:32 AM

I have a CExtColorCtrl in custom CWnd. Is there a way to give the CExtColorCtrl the same background Color as my window have ?

Best Regards.
S. Leopold

Technical Support Dec 11, 2006 - 12:54 PM

At the moment there are no SetBkColor/GetBkColor methods in the CExtColorCtrl class. We will add them in the next release, but currently you can override the CExtColorCtrl::DoPaint virtual method and paint the background yourself.

For example the following method draws a red background:

void CYourColorCtrl::DoPaint( 
    CDC * pDC,
    CRect & rcClient
    )
{
    ASSERT_VALID( this );
    ASSERT_VALID( pDC );
    if(        rcClient.IsRectEmpty()
        ||    (! pDC->RectVisible( &rcClient ) )
        )
        return;

    // Select and realize the palette
    CPalette * pOldPalette1 = NULL, * pOldPalette2 = NULL;
    if( ( ::GetDeviceCaps( pDC->m_hDC, RASTERCAPS ) & RC_PALETTE ) != 0 )
    {
        pOldPalette1 =
            pDC->SelectPalette( &PmBridge_GetPM()->m_PaletteWide, FALSE );
        pDC->RealizePalette();
    }

    CExtMemoryDC dc(
        pDC,
        &rcClient
        );

    dc.FillSolidRect(
        &rcClient,
        RGB(255,0,0)
        );
    
    if( ( ::GetDeviceCaps( dc.m_hDC, RASTERCAPS ) & RC_PALETTE ) != 0 )
    {
        pOldPalette2 =
            dc.SelectPalette( &PmBridge_GetPM()->m_PaletteWide, FALSE );
        dc.RealizePalette();
    }

    ASSERT(
        MODE_VAL_MIN <= m_eMode
        && m_eMode <= MODE_VAL_MAX
        );
    ASSERT( m_algorithms[m_eMode] != NULL );
    m_algorithms[m_eMode]->OnDraw(
        dc,
        (pOldPalette2 == NULL) ? NULL : &PmBridge_GetPM()->m_PaletteWide
        );

    if( pOldPalette2 != NULL )
        dc.SelectPalette( pOldPalette2, FALSE );
    if( pOldPalette1 != NULL )
        pDC->SelectPalette( pOldPalette1, FALSE );    
}