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 » ActiveX control with transparent background Collapse All
Subject Author Date
R Toellner Oct 27, 2006 - 8:14 AM

Hi,

I’m currently designing an ActiveX control which should be used in an application with Prof-UIS skin. My ideas was to capture the part of the parent window directly under my control, BitBlt it into an in-memory DC, drag some graphics and text and BitBlt in into the DC of my control, so it would create the illusion of transparency. This method seems to work on normal windows but not on Prof-UIS skinned windows.

To see an example, create a new ActiveX control with the Visual Studio 6 wizard and replace the OnDraw() method with this one:


void CActiveXCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
CDC* pPaDC = GetParent()->GetDC(); // DC of parent window
CDC vdc; // my in-memory DC

vdc.CreateCompatibleDC( pdc );

CBitmap vbm;
CBitmap* pOldvBmp;
vbm.CreateCompatibleBitmap( pdc, rcBounds.Width(), rcBounds.Height() );
pOldvBmp = vdc.SelectObject( &vbm );

RECT r;
GetRectInContainer( &r );

// copy the part from the parent window under this control to the memory DC
vdc.BitBlt(0, 0, rcBounds.Width(), rcBounds.Height(), pPaDC, r.left, r.top, SRCCOPY);

vdc.Ellipse(10, 10, 40, 40); // draw the white circle

// actually draw the control
pdc->BitBlt( 0, 0, rcBounds.Width(), rcBounds.Height(), &vdc, 0, 0, SRCCOPY);
vdc.SelectObject( pOldvBmp );

}


Then compile the project and put in a a Prof-UIS skinned window (I use the Office2007_R1 style with the gradient background). The expected result is a white circle with tranparent background. Unfortunaltely this doesn work, instead the circle plus a part of an underlying window is shown in the control.

Technical Support Oct 30, 2006 - 6:40 AM

This approach cannot be used to draw the Prof-UIS themed background in your ActiveX control. You should define some registered Windows message both in your ActiveX project and your control container project:

static UINT g_nMsgPaintMyConsistentBackground = ::RegisterWindowMessage( _T("MyUniqueStringWhichIsTheNameOfTheRegisteredMessage") );
We can assume that the returned LRESULT from this message is non equal to zero if the message is handled and themed background is drawn. The WPARAM message parameter is the HDC handle to draw the background to and the LPARAM message parameter is an HWND handle to the ActiveX control. The CActiveXCtrl::OnDraw() method should send this message to its parent window and analyze whether the background is drawn:
void CActiveXCtrl::OnDraw( CDC * pdc, const CRect & rcBounds, const CRect & rcInvalid )
{
    if( GetParent()->
            SendMessage(
                g_nMsgPaintMyConsistentBackground,
                WPARAM( pdc->GetSafeHdc() ),
                LPARAM( GetSafeHwnd() )
                )
        == 0 )
    {
        // DRAW SOME DEFAULT BACKGROUND HERE
        . . .
    }
    // DRAW YOUR ACTIVE-X CONTROL’S CONTENT HERE
    . . .
Your control container project should implement a container window which is parent for your ActiveX control’s window and which handles the g_nMsgPaintMyConsistentBackground registered Windows message. This container window can be based on any kind of window including CExtResizableDialog and CExtControlBar. The container window should have the following message map entry and handler method:
ON_REGISTERED_MESSAGE( g_nMsgPaintMyConsistentBackground, OnMsgPaintMyConsistentBackground )
 
LRESULT CYourClass::OnMsgPaintMyConsistentBackground( WPARAM wParam, LPARAM lParam )
{
    AFX_MANAGE_STATE( . . . ); // PERFORM MFC STATE MANAGING FIRST
HDC hDC = (HDC)wParam;
    if( hDC == NULL )
        return 0L;
HWND hWnd = (HWND)lParam;
    if( hWnd == NULL || ( ! ::IsWindow( hWnd ) ) )
        return 0L;
    if( ! g_PaintManager->PaintDockerBkgnd(
            true,
            *( CDC::FromHandle( hDC ) ),
            CWnd::FromHandle( hWnd )
            )
        )
        return 0L;
    return 1L;
}
Now your ActiveX control is able to draw the Prof-UIS themed background if its container window is able to provide it with this feature. You can define any additional messages for providing your ActiveX control with information about the preferable text color and etc.

R Toellner Oct 30, 2006 - 6:46 AM

Thank you very much, I’ll try out your sample code as soon as possible.