Click here to Skip to main content
11,710,824 members (84,377 online)
Click here to Skip to main content

Draw your control's skin using a pattern brush

, 21 Jun 2001 85.1K 993 29
Rate this:
Please Sign up or sign in to vote.
You can impliment skin control by returning a brush from the OnCtlColor() method
<!-- Download Links --> <!-- Article image -->

Sample Image - brush_skin.jpg

<!-- Main HTML starts here -->

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; 
         
    } 

    // Set brushOrg
    // This is very important!!
    brush.UnrealizeObject(); 
    pDC->SetBrushOrg(pt); 

    // return new skin-brush!
    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

Share

About the Author

Wooseok Seo
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 wooseok.seo@gmail.com

You may also be interested in...

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
membersdfghwdfgagf6-Nov-08 5:49 
QuestionCan i get the mean of "pt.x = -(rect-&gt;left + GetSystemMetrics(SM_CXDLGFRAME) - 1) % 55;" Pin
luoqi28-May-08 21:11
memberluoqi28-May-08 21:11 
RantExcelent concept, but the delivery could be better Pin
John Crenshaw2-Apr-08 16:40
memberJohn Crenshaw2-Apr-08 16:40 
QuestionThe meaning of "SM_CXDLGFRAME" ? Pin
wzh198312216-Dec-06 13:52
memberwzh198312216-Dec-06 13:52 
GeneralQuestion about the background color Pin
goodoljosh198017-Jul-06 5:02
membergoodoljosh198017-Jul-06 5:02 
GeneralProblem, it doesn't work Pin
gabriel.fischer3-Jan-05 13:16
membergabriel.fischer3-Jan-05 13:16 
GeneralSkinMagic Toolkit Pin
jedyking14-Apr-04 5:21
memberjedyking14-Apr-04 5:21 
QuestionHow to do this in a scrollable dialog? Pin
guosheng5-Apr-04 22:00
memberguosheng5-Apr-04 22:00 
GeneralGreat! Pin
X3m7-May-02 5:23
memberX3m7-May-02 5:23 
Generalwww.exontrol.com Pin
Anonymous13-Aug-01 20:44
memberAnonymous13-Aug-01 20:44 
GeneralNot so good Pin
Brian V Shifrin23-Jun-01 1:39
memberBrian V Shifrin23-Jun-01 1:39 
Generalgood! Pin
Anonymous22-Jun-01 19:13
memberAnonymous22-Jun-01 19:13 
GeneralRe: good! Pin
Anonymous24-Jun-01 0:04
memberAnonymous24-Jun-01 0:04 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150819.1 | Last Updated 22 Jun 2001
Article Copyright 2001 by Wooseok Seo
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid