Click here to Skip to main content
15,607,633 members
Articles / Desktop Programming / MFC
Posted 21 Jun 2001


30 bookmarked

Draw Your Control's Skin using a Pattern Brush

Rate me:
Please Sign up or sign in to vote.
4.18/5 (5 votes)
21 Jun 2001
You can implement skin control by returning a brush from the OnCtlColor() method.

Sample Image - brush_skin.jpg


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; 
        pt.x = -(rc.left + GetSystemMetrics(SM_CXDLGFRAME) - 1) % 55; 
        pt.y = -( + GetSystemMetrics(SM_CYDLGFRAME) - 1)% 53;          

    // Set brushOrg
    // This is very important!!

    // return new skin-brush!
    return (HBRUSH)brush; 


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.

Written By
Software Developer (Senior)
Korea (Republic of) Korea (Republic of)
Woo Seok Seo have been a Microsoft MVP for 7 years and have translated several books into Korean. Author of C# Programming for Beginner (DevPress, 2001), he is interested in Debugging techniques and .NET technology. Get in touch with Woo Seok Seo at

Comments and Discussions

Generalthats good, but you would also need to handle onerasebackground to set background of static fields transparent... Pin
sdfghwdfgagf6-Nov-08 5:49
sdfghwdfgagf6-Nov-08 5:49 
QuestionCan i get the mean of "pt.x = -(rect->left + GetSystemMetrics(SM_CXDLGFRAME) - 1) % 55;" Pin
luoqi28-May-08 21:11
luoqi28-May-08 21:11 
RantExcelent concept, but the delivery could be better Pin
John Crenshaw2-Apr-08 16:40
John Crenshaw2-Apr-08 16:40 
QuestionThe meaning of "SM_CXDLGFRAME" ? Pin
wzh198312216-Dec-06 13:52
wzh198312216-Dec-06 13:52 
GeneralQuestion about the background color Pin
goodoljosh198017-Jul-06 5:02
goodoljosh198017-Jul-06 5:02 
GeneralProblem, it doesn't work Pin
gabriel.fischer3-Jan-05 13:16
gabriel.fischer3-Jan-05 13:16 
GeneralSkinMagic Toolkit Pin
jedyking14-Apr-04 5:21
jedyking14-Apr-04 5:21 
QuestionHow to do this in a scrollable dialog? Pin
Member 9060985-Apr-04 22:00
Member 9060985-Apr-04 22:00 
GeneralGreat! Pin
Vuvirt7-May-02 5:23
Vuvirt7-May-02 5:23 Pin
13-Aug-01 20:44
suss13-Aug-01 20:44 
GeneralNot so good Pin
Brian V Shifrin23-Jun-01 1:39
Brian V Shifrin23-Jun-01 1:39 
Generalgood! Pin
22-Jun-01 19:13
suss22-Jun-01 19:13 
GeneralRe: good! Pin
24-Jun-01 0:04
suss24-Jun-01 0:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.