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.