Click here to Skip to main content
Licence 
First Posted 21 Jun 2001
Views 77,320
Bookmarked 29 times

Draw your control's skin using a pattern brush

By | 21 Jun 2001 | Article
You can impliment skin control by returning a brush from the OnCtlColor() method

Sample Image - brush_skin.jpg

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

About the Author

Wooseok Seo

Software Developer (Senior)

Korea (Republic Of) Korea (Republic Of)

Member

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalthats good, but you would also need to handle onerasebackground to set background of static fields transparent... Pinmembersdfghwdfgagf5:49 6 Nov '08  
QuestionCan i get the mean of "pt.x = -(rect->left + GetSystemMetrics(SM_CXDLGFRAME) - 1) % 55;" Pinmemberluoqi21:11 28 May '08  
RantExcelent concept, but the delivery could be better PinmemberJohn Crenshaw16:40 2 Apr '08  
QuestionThe meaning of "SM_CXDLGFRAME" ? Pinmemberwzh1983122113:52 6 Dec '06  
GeneralQuestion about the background color Pinmembergoodoljosh19805:02 17 Jul '06  
GeneralProblem, it doesn't work Pinmembergabriel.fischer13:16 3 Jan '05  
GeneralSkinMagic Toolkit Pinmemberjedyking5:21 14 Apr '04  
QuestionHow to do this in a scrollable dialog? Pinmemberguosheng22:00 5 Apr '04  
GeneralGreat! PinmemberX3m5:23 7 May '02  
Generalwww.exontrol.com PinmemberAnonymous20:44 13 Aug '01  
GeneralNot so good PinmemberBrian V Shifrin1:39 23 Jun '01  
Generalgood! PinmemberAnonymous19:13 22 Jun '01  
GeneralRe: good! PinmemberAnonymous0:04 24 Jun '01  

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.

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