Print Page | Close Window

How to make the Markup background transparent?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=12770
Printed Date: 26 April 2024 at 1:36am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to make the Markup background transparent?
Posted By: evoX
Subject: How to make the Markup background transparent?
Date Posted: 22 November 2008 at 3:25pm
I have a static control with Markup and I want the background of the static to be transparent as the markup content is placed in a border with rounded corners and I get white space outside of the content.
I have tried to make the static transparent from OnCtlColor but the background is still white. 
Is there a way to make the background of the markupstatic control transparent?
 
Thanks !


-------------
Product: Xtreme ToolkitPro 19.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2019)



Replies:
Posted By: Oleg
Date Posted: 24 November 2008 at 5:08am
Hi,
In CMarkupStatic add
 
void CMarkupStatic::OnPaint()
{
 CPaintDC dcPaint(this);
 CXTPBufferDC dcBuffer(dcPaint);
 CXTPClientRect rc(this);
 
 HBRUSH hBrush = (HBRUSH)GetParent()->SendMessage(WM_CTLCOLORSTATIC, (WPARAM)dcBuffer.GetSafeHdc(), (LPARAM)m_hWnd);
 if (hBrush)
 {
  ::FillRect(dcBuffer.GetSafeHdc(), rc, hBrush);
 }
 else
 {
  dcBuffer.FillSolidRect(rc, GetXtremeColor(COLOR_3DFACE));
 }

...
}


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: evoX
Date Posted: 25 November 2008 at 10:59am
Hi,
   This solution is working only for solid color backgrounds, not for bitmap backgrounds, I have an office 2007 workspace background :(
 
 
as you can see now with your suggestion the margins are black


-------------
Product: Xtreme ToolkitPro 19.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2019)


Posted By: Oleg
Date Posted: 26 November 2008 at 3:10am
Hi,
How do you set background ? You need catch WM_CTLCOLOR in your dialog and return brush to this background.
 


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: evoX
Date Posted: 26 November 2008 at 12:00pm

in the dialog I call OnPaint to paint the background

 
void CPage2FileDisk::OnPaint()
{
 CPaintDC dc(this); // device context for painting
 // TODO: Add your message handler code here
 // Do not call CXTPPropertyPage::OnPaint() for painting messages
 CRect rect;
 CRect rcExclude(0,0,0,0);
 CXTPClientRect rc(this);
 //-------------------
 // Redraw background:
 //-------------------
 CXTPOffice2007Theme ot;
 ot.FillWorkspace(&dc, rc, rcExclude);
 
 rc.top=157;
 XTPDrawHelpers()->GradientFill(&dc, rc, ot.GetImages()->GetImageColor(_T("Workspace"), _T("WorkspaceClientTop")),
  ot.GetImages()->GetImageColor(_T("Workspace"), _T("WorkspaceClientMiddle")), FALSE);
}


-------------
Product: Xtreme ToolkitPro 19.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2019)


Posted By: Oleg
Date Posted: 26 November 2008 at 12:07pm

Hi,

And why Static have to be transparent after this code? ;-)
 
Most easy way for you is just repeat same code with offset for CMarkupStatic::OnPaint.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: evoX
Date Posted: 26 November 2008 at 1:07pm
 
 
Because the static has a different size than the dialog the background will never have the same position, so now after I added the background paint routine to the static control now it looks like this...
 

void CMarkupStatic::OnPaint()

{

CPaintDC dcPaint(this);

CXTPBufferDC dcBuffer(dcPaint);

CXTPClientRect rc(this);

/********* Paint the background *******/

CRect rcExclude(0,0,0,0);

CXTPOffice2007Theme ot;

ot.FillWorkspace(&dcBuffer, rc, rcExclude);

XTPDrawHelpers()->GradientFill(&dcBuffer, rc, ot.GetImages()->GetImageColor(_T("Workspace"), _T("WorkspaceClientTop")),

ot.GetImages()->GetImageColor(_T("Workspace"), _T("WorkspaceClientMiddle")), FALSE);

/**************************************/

if (m_pUIElement)

{

CXTPMarkupDrawingContext dc(dcBuffer);

m_pUIElement->Measure(&dc, rc.Size());

m_pUIElement->Arrange(rc);

m_pUIElement->Render(&dc);

}

}



-------------
Product: Xtreme ToolkitPro 19.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2019)


Posted By: Oleg
Date Posted: 27 November 2008 at 1:58am

Hi,

That's why I wrote you need Offset. Calculate rc using coordinates of Parent dialog.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: evoX
Date Posted: 27 November 2008 at 6:34am
It's very hard to calculate since the dialog pixels changes for small or large fonts... I think it would be better to read the bitmap behind the static, saved in a buffer then painted back.
 
But I really don't understand how are the rest of the markup controls in the toolkit? they all don't support transparent background ?
...so if I use a simple markup which displays a text on a button with office 2007 theme then I will get a rectangle surrounding the text on the button? :(


-------------
Product: Xtreme ToolkitPro 19.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2019)


Posted By: Oleg
Date Posted: 27 November 2008 at 1:49pm
your CMarkupStatic is Child Window. All Markup elelemnt in this window is windowless elements they can be transparent - but your child window cant.
Child windows in Windows can't be trasparent , all standard controls use WM_CTLCOLOR message to draw part of parent dialog.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: Oleg
Date Posted: 27 November 2008 at 2:21pm
 
Ok, here sample  https://forum.codejock.com/uploads/20081127_142038_ms.zip - ms.zip  Hope its clear now :)


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: evoX
Date Posted: 02 December 2008 at 1:37am
Thanks Oleg !
Now it works, and I got the point


-------------
Product: Xtreme ToolkitPro 19.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2019)


Posted By: robin_l
Date Posted: 30 June 2009 at 6:37pm
I just had to deal with the same problem. My solution is to check to see whether the static control is Transparent or not (set from the resource editor in Visual Studio). If it is I BitBlt the underlying window background to form the backdrop for the control.
 
 

void CMarkupStatic::OnPaint()

{

if (!m_pUIElement)

{

CStatic::OnPaint();

return;

}

CPaintDC dcPaint(this);

CXTPBufferDC dcBuffer(dcPaint);

CXTPClientRect rc(this);

// check for transparency
bool bTransparent = (GetExStyle() & WS_EX_TRANSPARENT) ? true : false;

if (bTransparent)

{

CRect rect = rc;

ClientToScreen(&rect);

GetParent()->ScreenToClient(&rect);

CWindowDC dcWin(GetParent());

BitBlt(dcBuffer, rc.left, rc.top, rc.Width(), rc.Height(),

dcWin, rect.left,rect.top, SRCCOPY );

}

else

{

HBRUSH hBrush = (HBRUSH)GetParent()->SendMessage(WM_CTLCOLORSTATIC, (WPARAM)dcBuffer.GetSafeHdc(), (LPARAM)m_hWnd);

if (hBrush)

{

::FillRect(dcBuffer.GetSafeHdc(), rc, hBrush);

}

else

{

dcBuffer.FillSolidRect(rc, GetXtremeColor(COLOR_3DFACE));

}

}

// minor modification: don't draw if the window is disabled

if (m_pUIElement && IsWindowEnabled())

{

CXTPMarkupDrawingContext dc(dcBuffer);

m_pUIElement->Measure(&dc, rc.Size());

m_pUIElement->Arrange(rc);

m_pUIElement->Render(&dc);

}

}



-------------
Product: Xtreme ToolkitPro 2009 (13.4.1)
Platform: Windows 7 Ultimate(64bit)
Language: Visual Studio 2010 (C++)


Posted By: Oleg
Date Posted: 01 July 2009 at 8:05am
Hi,
See attached project. It shows  all.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: robin_l
Date Posted: 01 July 2009 at 6:50pm
Horses for courses.... My version of CMarkupStatic, which is only a handful of lines different from yours, still draws correctly if partially overlapped with other controls or if the background is not predefined by a bitmap. It also does not require each dialog box/view that uses it to define its own specific OnCtlColor handler. But your background brush method is neat as it handles the markup button controls as well as the markup static control.
 
Either way, however, I still think it is a good idea to test for WS_EX_TRANSPARENT and only generate transparent backgrounds for controls that have this set


-------------
Product: Xtreme ToolkitPro 2009 (13.4.1)
Platform: Windows 7 Ultimate(64bit)
Language: Visual Studio 2010 (C++)


Posted By: zitz
Date Posted: 22 December 2010 at 5:54am
Hi.
Another way is create other BufferDC - CBufferDCTransparent:

void CMarkupStatic::OnPaint()
{
    if ( m_pUIElement == NULL )
    {
        CStatic::OnPaint();
    }
    else
    {
        class CBufferDCTransparent : public CDC
        {
        public:
            CBufferDCTransparent( CPaintDC& paintDC, BOOL bTransparent )
            {
                m_bTransparent = bTransparent;
                m_hDestDC = paintDC.GetSafeHdc();
                m_rect = paintDC.m_ps.rcPaint;
                Attach (::CreateCompatibleDC( m_hDestDC ) );
                if ( m_hDC != NULL )
                {
                    m_bitmap.Attach( ::CreateCompatibleBitmap( m_hDestDC,
                                                               max( 1, m_rect.right ),
                                                               max( 1, m_rect.bottom ) ) );
                    m_hOldBitmap = ::SelectObject( m_hDC, m_bitmap );
                    CRgn rgn;
                    rgn.CreateRectRgnIndirect( &m_rect );
                    SelectClipRgn( &rgn );

                    if ( m_bTransparent == TRUE )
                    {
                        FillSolidRect( m_rect, (COLORREF)-1 );
                    }
                }
            }
            virtual ~CBufferDCTransparent()
            {
                if ( m_hDC != NULL )
                {
                    if ( m_hDestDC != NULL )
                    {
                        if ( m_bTransparent == TRUE )
                        {
                            ::TransparentBlt( m_hDestDC,
                                              m_rect.left,
                                              m_rect.top,
                                              m_rect.Width(),
                                              m_rect.Height(),
                                              m_hDC,
                                              m_rect.left,
                                              m_rect.top,
                                              m_rect.Width(),
                                              m_rect.Height(),
                                              (COLORREF)-1 );
                        }
                        else
                        {
                            ::BitBlt( m_hDestDC,
                                      m_rect.left,
                                      m_rect.top,
                                      m_rect.Width(),
                                      m_rect.Height(),
                                      m_hDC,
                                      m_rect.left,
                                      m_rect.top,
                                      SRCCOPY );
                        }
                    }
                    ::SelectObject( m_hDC, m_hOldBitmap );
                }
            }
        protected:
            HDC     m_hDestDC;    // Handle to the destination device context.
            CBitmap m_bitmap;     // Bitmap in memory device context
            CRect   m_rect;       // Size of the area to paint.
            HGDIOBJ m_hOldBitmap; // Handle to the previously selected bitmap.
            BOOL    m_bTransparent;
        };

        BOOL bTransparent = ( GetExStyle() & WS_EX_TRANSPARENT ) != 0;
        CPaintDC dcPaint( this );
        CBufferDCTransparent dcBuffer( dcPaint, bTransparent );
        CXTPClientRect rc( this );

        if ( m_clrBackground == COLORREF_NULL )
        {
            if ( bTransparent == FALSE )
            {
                HBRUSH hBrush = NULL;
                CWnd* pParent = GetParent();
                if ( pParent != NULL )
                {
                    hBrush = (HBRUSH)pParent->SendMessage( WM_CTLCOLORSTATIC,
                                                           (WPARAM)dcBuffer.GetSafeHdc(),
                                                           (LPARAM)m_hWnd );
                }
                if ( hBrush != NULL )
                {
                    ::FillRect( dcBuffer.GetSafeHdc(), rc, hBrush );
                }
                else
                {
                    dcBuffer.FillSolidRect( rc, GetXtremeColor( COLOR_3DFACE ) );
                }
            }
        }
        else
        {
            dcBuffer.FillSolidRect( rc, m_clrBackground );
        }

        CXTPMarkupDrawingContext dc( dcBuffer );
        CSize szAvailableSize = rc.Size();
        m_pUIElement->Measure( &dc, szAvailableSize );
        m_pUIElement->Arrange( rc );
        CRect rcClip = dc.GetClipBox();
        Render( m_pUIElement, &dc, rc.EqualRect( rcClip ) );
    }
}



-------------
Xtreme ToolkitPro v13.1.0, static, VC++6


Posted By: evoX
Date Posted: 22 December 2010 at 10:22am
thanks, but this still requires handling the CtlColor brush...

-------------
Product: Xtreme ToolkitPro 19.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2019)



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net