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
Collapse
Copy
Code
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;
}