How to make the Markup background transparent? |
Post Reply |
Author | |
evoX
Senior Member Joined: 25 July 2007 Status: Offline Points: 207 |
Post Options
Thanks(0)
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) |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
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 |
|
evoX
Senior Member Joined: 25 July 2007 Status: Offline Points: 207 |
Post Options
Thanks(0)
|
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) |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
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 |
|
evoX
Senior Member Joined: 25 July 2007 Status: Offline Points: 207 |
Post Options
Thanks(0)
|
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) |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
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 |
|
evoX
Senior Member Joined: 25 July 2007 Status: Offline Points: 207 |
Post Options
Thanks(0)
|
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) |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hi, That's why I wrote you need Offset. Calculate rc using coordinates of Parent dialog.
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
evoX
Senior Member Joined: 25 July 2007 Status: Offline Points: 207 |
Post Options
Thanks(0)
|
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) |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
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 |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Ok, here sample ms.zip Hope its clear now :)
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
evoX
Senior Member Joined: 25 July 2007 Status: Offline Points: 207 |
Post Options
Thanks(0)
|
Thanks Oleg !
Now it works, and I got the point
|
|
Product: Xtreme ToolkitPro 19.30
Platform: Windows 10 64bit Language: Visual C++ (VS 2019) |
|
robin_l
Senior Member Joined: 15 October 2006 Status: Offline Points: 117 |
Post Options
Thanks(0)
|
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++) |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hi,
See attached project. It shows all.
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
robin_l
Senior Member Joined: 15 October 2006 Status: Offline Points: 117 |
Post Options
Thanks(0)
|
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++) |
|
zitz
Senior Member Joined: 05 October 2008 Status: Offline Points: 112 |
Post Options
Thanks(0)
|
Hi.
Another way is create other BufferDC - CBufferDCTransparent:
|
|
Xtreme ToolkitPro v13.1.0, static, VC++6
|
|
evoX
Senior Member Joined: 25 July 2007 Status: Offline Points: 207 |
Post Options
Thanks(0)
|
thanks, but this still requires handling the CtlColor brush...
|
|
Product: Xtreme ToolkitPro 19.30
Platform: Windows 10 64bit Language: Visual C++ (VS 2019) |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |