Click here to Skip to main content
Click here to Skip to main content
Go to top

Draw your control's skin using a pattern brush

, 21 Jun 2001
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

Comments and Discussions

 
Generalthats good, but you would also need to handle onerasebackground to set background of static fields transparent... Pinmembersdfghwdfgagf6-Nov-08 5:49 
QuestionCan i get the mean of "pt.x = -(rect-&gt;left + GetSystemMetrics(SM_CXDLGFRAME) - 1) % 55;" Pinmemberluoqi28-May-08 21:11 
RantExcelent concept, but the delivery could be better PinmemberJohn Crenshaw2-Apr-08 16:40 
QuestionThe meaning of "SM_CXDLGFRAME" ? Pinmemberwzh198312216-Dec-06 13:52 
GeneralQuestion about the background color Pinmembergoodoljosh198017-Jul-06 5:02 
GeneralProblem, it doesn't work Pinmembergabriel.fischer3-Jan-05 13:16 
GeneralSkinMagic Toolkit Pinmemberjedyking14-Apr-04 5:21 
QuestionHow to do this in a scrollable dialog? Pinmemberguosheng5-Apr-04 22:00 
GeneralGreat! PinmemberX3m7-May-02 5:23 
Generalwww.exontrol.com PinmemberAnonymous13-Aug-01 20:44 
GeneralNot so good PinmemberBrian V Shifrin23-Jun-01 1:39 
Generalgood! PinmemberAnonymous22-Jun-01 19:13 
GeneralRe: good! PinmemberAnonymous24-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 | Mobile
Web02 | 2.8.140916.1 | Last Updated 22 Jun 2001
Article Copyright 2001 by Wooseok Seo
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid