Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Draw Your Control's Skin using a Pattern Brush

0.00/5 (No votes)
21 Jun 2001 1  
You can implement 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.

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