Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - How to make the Markup background transparent?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to make the Markup background transparent?

 Post Reply Post Reply
Author
Message
evoX View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 July 2007
Status: Offline
Points: 207
Post Options Post Options   Thanks (0) Thanks(0)   Quote evoX Quote  Post ReplyReply Direct Link To This Post Topic: How to make the Markup background transparent?
    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)
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
evoX View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 July 2007
Status: Offline
Points: 207
Post Options Post Options   Thanks (0) Thanks(0)   Quote evoX Quote  Post ReplyReply Direct Link To This Post 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)
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
evoX View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 July 2007
Status: Offline
Points: 207
Post Options Post Options   Thanks (0) Thanks(0)   Quote evoX Quote  Post ReplyReply Direct Link To This Post 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)
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
evoX View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 July 2007
Status: Offline
Points: 207
Post Options Post Options   Thanks (0) Thanks(0)   Quote evoX Quote  Post ReplyReply Direct Link To This Post 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)
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
evoX View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 July 2007
Status: Offline
Points: 207
Post Options Post Options   Thanks (0) Thanks(0)   Quote evoX Quote  Post ReplyReply Direct Link To This Post 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)
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 27 November 2008 at 2:21pm
 
Ok, here sample  ms.zip Hope its clear now :)
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
evoX View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 July 2007
Status: Offline
Points: 207
Post Options Post Options   Thanks (0) Thanks(0)   Quote evoX Quote  Post ReplyReply Direct Link To This Post 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)
Back to Top
robin_l View Drop Down
Senior Member
Senior Member


Joined: 15 October 2006
Status: Offline
Points: 117
Post Options Post Options   Thanks (0) Thanks(0)   Quote robin_l Quote  Post ReplyReply Direct Link To This Post 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++)
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 01 July 2009 at 8:05am
Hi,
See attached project. It shows  all.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
robin_l View Drop Down
Senior Member
Senior Member


Joined: 15 October 2006
Status: Offline
Points: 117
Post Options Post Options   Thanks (0) Thanks(0)   Quote robin_l Quote  Post ReplyReply Direct Link To This Post 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++)
Back to Top
zitz View Drop Down
Senior Member
Senior Member


Joined: 05 October 2008
Status: Offline
Points: 112
Post Options Post Options   Thanks (0) Thanks(0)   Quote zitz Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
evoX View Drop Down
Senior Member
Senior Member
Avatar

Joined: 25 July 2007
Status: Offline
Points: 207
Post Options Post Options   Thanks (0) Thanks(0)   Quote evoX Quote  Post ReplyReply Direct Link To This Post 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)
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.