Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

A Gradient Static Control

, 26 Apr 2004
A Static control will gradient
cgradientstatic.zip
Gradient
Gradient.clw
Gradient.dsp
Gradient.dsw
Release
Gradient.exe
res
Gradient.ico
gradient_static_demo.zip
Gradient.clw
Gradient.dsw
Gradient.ico
Gradient.dsp
Gradient.plg
Gradient.exe
// GradientDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Gradient.h"
#include "GradientDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGradientDlg dialog

CGradientDlg::CGradientDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGradientDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGradientDlg)
	//}}AFX_DATA_INIT
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_pBoldFont = NULL;
}

void CGradientDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGradientDlg)
	DDX_Control(pDX, IDC_EXAMPLE2, m_cExample2);
	DDX_Control(pDX, IDC_TH, m_cTH);
	DDX_Control(pDX, IDC_EXAMPLE, m_cExample);
	DDX_Control(pDX, IDC_TITLE, m_cTitle);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGradientDlg, CDialog)
	//{{AFX_MSG_MAP(CGradientDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_TH, OnTh)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGradientDlg message handlers

BOOL CGradientDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	m_pBoldFont = new CFont;
	m_pBoldFont->CreateFont(25,0,0,0,900,0,0,0,0,0,0,ANTIALIASED_QUALITY,0,"Arial");

	//Use big font and standard colors
	m_cTitle.SetFont(m_pBoldFont);
	m_cTitle.SetWindowText("This is CGradientStatic example :)");

	//Use font of dialog controls, centered text and default colors
	m_cExample.SetFont(m_cTH.GetFont()); //this is a small trick to obtain default font of this dialog
	m_cExample.SetWindowText("This text is in the center !");
	m_cExample.SetCenterText();

	//Use big font, custom colors and centered text
	m_cExample2.SetFont(m_pBoldFont);
	m_cExample2.SetWindowText("RED - CENTERED - BLACK");
	m_cExample2.SetCenterText();
	m_cExample2.SetColor(RGB(255,0,0));
	m_cExample2.SetGradientColor(RGB(0,0,0));
	m_cExample2.SetTextColor(RGB(255,255,255));


	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CGradientDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

HCURSOR CGradientDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CGradientDlg::OnTh() 
{
	ShellExecute(NULL,"open","http://www.trayhelper.com",NULL,NULL,SW_SHOWNORMAL);
}

CGradientDlg::~CGradientDlg()
{
	delete m_pBoldFont;
	m_pBoldFont = NULL;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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

Irek Zielinski
Web Developer
United Kingdom United Kingdom
Irek works as a C++ senior software developer.
He runs also his own small shareware bussines (He is author of few quite popular applications like: Tray Helper or Time Adjuster).
 
Occasionaly he posts articles to Codeguru or Codeproject. Besides C++ he likes motorcycles and paragliding.
Check out his software at: http://www.ireksoftware.com

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 27 Apr 2004
Article Copyright 2002 by Irek Zielinski
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid