Click here to Skip to main content
15,887,350 members
Articles / Mobile Apps / Windows Mobile

Colour Picker Control for Windows CE

Rate me:
Please Sign up or sign in to vote.
4.87/5 (9 votes)
5 Feb 2003CPOL1 min read 111.6K   547   33   13
An implementation of the Office 97 style Colour Picker control for Windows CE.

Sample Image - CeColourPicker.jpg

Introduction

This is a port of Chris Maunder's Office 97 style Colour Picker control[^] to Windows CE (PocketPC 2002). The code was adapted using the preprocessor macro _WIN32_WCE to enable transparent compilation in both eVC++ 3.0 and VC++ 6.0.

Porting

Here are the main points of the port.

Compatibility between CE and Desktop versions has been maintained through the precompiler, using the _WIN32_WCE #define.

The CE version of the popup is statically allocated in CColourPicker because CE does not support the WM_NCDESTROY message, making it impossible to dynamically delete the popup. This required the addition of a number of property set methods.

The popup is dismissed when the user clicks the button a second time, assuming a selection ended with cancel behavior.

The custom text button is not used to show up the CColorDialog. This class is not supported in MFC for the PocketPC 2002 SDK. One can still use the built in ChooseColor API, but the results are not very nice (see comment in the source code). The text changed to "Cancel".

WM_MOUSEMOVE is not used to make the color selection. CE has no mouse support and it would not be intuitive for a user to drag the pen just to start selecting the color. It has been replaced by WM_LBUTTONDOWN, and the handler code is the same.

This code has been tested in the PocketPC 2002 platform, compiles with no errors or warnings in Level 3 of eVC++ 3.0.

Revisions

  • 2003-02-06: Changed the OnKillFocus handler of CColourPopup in order to allow the popup to close when it loses focus.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Frotcom International
Portugal Portugal
I work on R&D for Frotcom International, a company that develops web-based fleet management solutions.

Comments and Discussions

 
Generalthe "X" button Pin
paraGOD26-Dec-05 21:48
paraGOD26-Dec-05 21:48 
GeneralRe: the "X" button Pin
João Paulo Figueira26-Dec-05 23:39
professionalJoão Paulo Figueira26-Dec-05 23:39 
GeneralRe: the "X" button Pin
paraGOD28-Dec-05 19:41
paraGOD28-Dec-05 19:41 
GeneralRe: the "X" button Pin
João Paulo Figueira28-Dec-05 23:08
professionalJoão Paulo Figueira28-Dec-05 23:08 
GeneralRe: the "X" button Pin
paraGOD29-Dec-05 18:59
paraGOD29-Dec-05 18:59 
QuestionCrashes under Windows Mobile 2003? Pin
Gary17NYC25-Aug-04 14:51
Gary17NYC25-Aug-04 14:51 
AnswerRe: Crashes under Windows Mobile 2003? Pin
João Paulo Figueira25-Aug-04 22:17
professionalJoão Paulo Figueira25-Aug-04 22:17 
GeneralSource code for the example Pin
biswa6-Mar-03 23:06
biswa6-Mar-03 23:06 
GeneralRe: Source code for the example Pin
João Paulo Figueira6-Mar-03 23:51
professionalJoão Paulo Figueira6-Mar-03 23:51 
biswa wrote:
Can you pl post an example how to use it.

What is shown in the screenshot is part of a framework for formatting columns in a CListCtrl. I'll present here the code segments that will allow you to recreate that. In order to display the control in a dialog or property page, create a simple pushbutton. Using the class wizard, map the button to a normal CButton control. Go to the dialog header and change the declarations to:
CColourPicker   m_btnText;
CColourPicker   m_btnBack;
CColourPicker   m_btnNegn;

The implementation code is:
void CPropListColColor::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPropListColColor)
	//}}AFX_DATA_MAP
	DDX_Control(pDX, OIDC_CLR_TEXT,  m_btnText);
	DDX_Control(pDX, OIDC_CLR_BACK,  m_btnBack);
	DDX_Control(pDX, OIDC_CLR_NEGN,  m_btnNegn);
}


BEGIN_MESSAGE_MAP(CPropListColColor, CPropertyPage)
	//{{AFX_MSG_MAP(CPropListColColor)
	//}}AFX_MSG_MAP
    ON_MESSAGE(CPN_SELENDOK,     OnSelEndOK)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPropListColColor message handlers


// CPropListColFormat::OnInitDialog
//
//		Initializes the dialog
//
BOOL CPropListColColor::OnInitDialog() 
{
	ASSERT(m_pCol);

	CPropertyPage::OnInitDialog();

	m_btnText.SetDefaultText	(_T("Text"));
	m_btnText.SetSelectionMode	(CP_MODE_TEXT);
	m_btnText.SetColour			(m_pCol->GetColorText());
	m_btnText.SetBkColour		(m_pCol->GetColorBack());

	m_btnBack.SetDefaultText	(_T("Background"));
	m_btnBack.SetSelectionMode	(CP_MODE_BK);
	m_btnBack.SetColour			(m_pCol->GetColorBack());
	m_btnBack.SetTextColour		(m_pCol->GetColorText());

	m_btnNegn.SetDefaultText	(_T("Negatives"));
	m_btnNegn.SetSelectionMode	(CP_MODE_TEXT);
	m_btnNegn.SetColour			(m_pCol->GetColorNeg());
	m_btnNegn.SetBkColour		(m_pCol->GetColorBack());
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


// CPropListColColor::OnSelEndOK
//
//		A color selection changed
//
LRESULT CPropListColColor::OnSelEndOK(WPARAM wParam, LPARAM lParam)
{
	COLORREF	crBack,
				crText,
				crNegn;

	ASSERT(m_pCol);

	crText = m_btnText.GetColour();
	crBack = m_btnBack.GetColour();
	crNegn = m_btnNegn.GetColour();

	m_btnText.SetBkColour(crBack);
	m_btnNegn.SetBkColour(crBack);
	m_btnBack.SetTextColour(crText);

	m_pCol->SetColorText	(crText);
	m_pCol->SetColorBack	(crBack);
	m_pCol->SetColorNeg		(crNegn);

	return TRUE;
}

Hope this helps.
GeneralRe: Source code for the example Pin
biswa7-Mar-03 0:21
biswa7-Mar-03 0:21 
GeneralRe: Source code for the example Pin
bm_masri17-Nov-03 16:55
bm_masri17-Nov-03 16:55 
GeneralRe: Source code for the example Pin
Daniel Jin24-Apr-05 4:06
Daniel Jin24-Apr-05 4:06 
GeneralGreat job! Pin
Daniel Strigl31-Jan-03 5:59
Daniel Strigl31-Jan-03 5:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.