Introduction
This article shows how to use a pattern brush to give your controls a similar look and feel.
When you use a brush, you can specify the origin of the brush. So, if all your controls use the same brush, your controls have same feature. If you handle the OnCtlColor()
and return a pattern brush, then you can do this. This is very simple method.
I used code similar to the following functions in my source code:
UnrealizeObject()
: The UnrealizeObject
function resets the origin of a brush or resets a logical palette. CDC::SetBrushOrg()
: This method specifies the origin that the GDI assigns to the next brush that the application selects for the device context.
The Main Function
HBRUSH CPatternDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
CPoint pt(0,0);
if (this != pWnd)
{
CRect rc;
pWnd->GetWindowRect(&rc);
ScreenToClient(&rc);
pt.x = -(rc.left + GetSystemMetrics(SM_CXDLGFRAME) - 1) % 55;
pt.y = -(rc.top + GetSystemMetrics(SM_CYDLGFRAME) - 1)% 53;
}
brush.UnrealizeObject();
pDC->SetBrushOrg(pt);
return (HBRUSH)brush;
}
License
This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.
A list of licenses authors might use can be found here.