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

A Gradient Static Control

0.00/5 (No votes)
6 Oct 2003 3  
A Static control with a gradient

Sample Image - gradientstatic.jpg

Introduction

The idea was to have a small piece of code which makes it easy to create a gradient control. I saw a lot of great code, but it was not exactly what I want.  So I decided to create my own CGradientStatic-class.

Usage of CGradientStatic

To use this control in your application:

  • Design the dialog and add the Static control
  • Add the GradientStatic.h header file to your project
  • Assign a CGradientStatic to your static control.
  • In OnInitDialog(), subclass CGradientStatic control to ID using the SubclassWindow method.
#include "CGradientStatic.h"


//...


class CMainDlg : public CDialogImpl<CMainDlg>
{     
    BEGIN_MSG_MAP(CMainDlg)          
       ...          
       MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)          
       REFLECT_NOTIFICATIONS()     
    END_MSG_MAP()
    ...
    LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, 
        LPARAM /*lParam*/, BOOL& /*bHandled*/);
    ...
    CGradientStatic m_GradientBar;     
    ...
}; 

//...


LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, 
      LPARAM /*lParam*/, BOOL& /*bHandled*/) 
{
     ...     
     m_GradientBar.SubclassWindow( ::GetDlgItem( IDC_STATIC1 ) );     
     m_GradientBar.SetColor(RGB(255,0,0));
     m_GradientBar.SetGradientColor(RGB(0,0,0));

     ...
}

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