Click here to Skip to main content
15,894,405 members
Articles / Multimedia / GDI

Custom Captions (Including Multi-line Captions)

Rate me:
Please Sign up or sign in to vote.
5.00/5 (9 votes)
15 Jul 2000CPOL 241K   6.8K   63  
Simple customised Window captions, including multi-line captions
// ColourPickDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ColorPickDialog.h"

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

/////////////////////////////////////////////////////////////////////////////
// CColorPickDlg dialog

CColorPickDlg::CColorPickDlg(COLORREF& colorTxt, COLORREF& colorBk, CWnd* pParent /*=NULL*/)
    : CDialog(CColorPickDlg::IDD, pParent), m_ColorTxt(colorTxt), m_ColorBk(colorBk)
{
    //{{AFX_DATA_INIT(CColorPickDlg)
	m_nMode = 1;
	//}}AFX_DATA_INIT
    m_crColour = m_ColorBk;
	m_ColourBox.SetTextColour(m_ColorTxt);
	m_ColourBox.SetBkColour(m_ColorBk);
}

void CColorPickDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CColorPickDlg)
    DDX_Control(pDX, IDC_COLOURPICKER, m_ColourBox);
	DDX_Radio(pDX, IDC_MODE1, m_nMode);
	//}}AFX_DATA_MAP
    DDX_ColourPicker(pDX, IDC_COLOURPICKER, m_crColour);
}

BEGIN_MESSAGE_MAP(CColorPickDlg, CDialog)
    //{{AFX_MSG_MAP(CColorPickDlg)
	ON_BN_CLICKED(IDC_MODE1, OnModeChange)
	//}}AFX_MSG_MAP
    ON_MESSAGE(CPN_SELENDOK,     OnSelEndOK)
    ON_MESSAGE(CPN_SELENDCANCEL, OnSelEndCancel)
    ON_MESSAGE(CPN_SELCHANGE,    OnSelChange)
    ON_MESSAGE(CPN_CLOSEUP,      OnCloseUp)
    ON_MESSAGE(CPN_DROPDOWN,     OnDropDown)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CColorPickDlg message handlers

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

	UpdateData(FALSE);
	OnModeChange();
	OnTrackColour();

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


/////////////////////////////////////////////////////////////////////////////
// CColourPicker message handlers

LONG CColorPickDlg::OnSelEndOK(UINT /*lParam*/, LONG /*wParam*/)
{
	UpdateData(TRUE); 
    TRACE0("Selection ended OK\n");

	if (m_nMode)
		m_ColorBk = m_crColour;
	else
		m_ColorTxt = m_crColour;

    return TRUE;
}

LONG CColorPickDlg::OnSelEndCancel(UINT /*lParam*/, LONG /*wParam*/)
{
    TRACE0("Selection cancelled\n");
    return TRUE;
}

LONG CColorPickDlg::OnSelChange(UINT /*lParam*/, LONG /*wParam*/)
{
    TRACE0("Selection changed\n");
    return TRUE;
}

LONG CColorPickDlg::OnCloseUp(UINT /*lParam*/, LONG /*wParam*/)
{
    TRACE0("Colour picker close up\n");
    return TRUE;
}

LONG CColorPickDlg::OnDropDown(UINT /*lParam*/, LONG /*wParam*/)
{
    TRACE0("Colour picker drop down\n");
    return TRUE;
}


void CColorPickDlg::OnModeChange() 
{
	UpdateData(TRUE); 
	m_ColourBox.SetSelectionMode(m_nMode ? CP_MODE_BK : CP_MODE_TEXT);
}

void CColorPickDlg::OnTrackColour() 
{
	UpdateData(TRUE); 
	m_ColourBox.SetTrackSelection();
}

void CColorPickDlg::OnDisable() 
{
	UpdateData(TRUE); 
    m_ColourBox.Invalidate();
}

void CColorPickDlg::OnChangeEdit() 
{
    CString str;

    m_ColourBox.SetDefaultText(str);
    m_ColourBox.SetCustomText(str);
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions