Platforms, Frameworks & Libraries »
Mobile Development »
Controls
Intermediate
Colour Picker Control for Windows CE
By Joao Paulo Figueira
An implementation of the Office 97 style Colour Picker control for Windows CE
|
C++, eVC 3.0, eVC, Windows, CE 3.0, PocketPC 2002, Win Mobile, Mobile, Visual Studio, MFC, Dev
Posted: 30 Jan 2003
Updated: 5 Feb 2003
Views: 63,548
Bookmarked: 19 times
|
|
|
|
|

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.
| You must Sign In to use this message board. |
|
| | Msgs 1 to 14 of 14 (Total in Forum: 14) (Refresh) | FirstPrevNext |
|
|
 |
|
|
hi, I've down the source code and it work perfectly. My question is how to capture the event when the user click the “X” button in the dialog or use other method to create the popup window replacing the “ok” with “X” . I’ ll really appreciate your help,thanks.
Para.
-- modified at 3:51 Tuesday 27th December, 2005
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
paraGOD wrote: I've down the source code and it work perfectly.
Great!
paraGOD wrote: My question is how to capture the event when the user click the “X” button in the dialog or use other method to create the popup window replacing the “ok” with “X” .
The "X" you see there does not belong to the dialog, but to the popup itself. Dialogs will always show an "ok" button unless you tell them to hide it. You handle that button theough the WM_COMMAND messages with IDOK as the command.
Regards, João Paulo Figueira Embedded MVP
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Yes ,you are right and thanks for your souce code and help. And now my question how to capture "X" in the popup itself?
Para
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
Hi,
Excellent code (thanks!), but I am running into a small problem with (possibly) the color picker.
To replicate, insert about 10 CColourPicker instances into a CPropertyPageEx-derived page, and close and open the property sheet a few times. Eventually an access violation exception in MFC shows up:
---> CPlex::FreeDataChain(CPlex * 0x0000ff00) line 44 + 4 bytes CMapPtrToPtr::RemoveAll() line 94 CHandleMap::DeleteTemp(__POSITION * 0x00000000) line 242 AfxUnlockTempMaps(int 1) line 55 CWinThread::OnIdle(long 1) line 615
If the CColourPicker page is never shown (or CColourPicker's are commented out), the problem immediately disappears. Identical code works fine on desktop, so this might be something Windows Mobile-port specific.
Any ideas??
Thanks...
Gary
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
The truth is that I never tested the code under Win Mobile 2003 and this OS is known to reveal bugs that 2002 never bothered to show... Well, I'm queuing this one up!
Regards, João Paulo Figueira Embedded MVP
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
I traced one possible source of the problem to DDX_ColourPicker(). The only deviation from "regular" MFC DDX sources in that function is the cast from temp CWnd instance back to CColourPicker:
CColourPicker* pColourPicker = (CColourPicker*) CWnd::FromHandle(hWndCtrl);
So, I switched getting/setting colors from method-based to message-based:
ColourPicker.h:
#define CPM_GETCOLOUR WM_USER + 1006 #define CPM_SETCOLOUR WM_USER + 1007
afx_msg LRESULT OnGetColour(WPARAM, LPARAM); afx_msg LRESULT OnSetColour(WPARAM, LPARAM);
ColourPicker.cpp:
ON_MESSAGE(CPM_GETCOLOUR, OnGetColour) ON_MESSAGE(CPM_SETCOLOUR, OnSetColour)
LRESULT CColourPicker::OnGetColour(WPARAM wParam, LPARAM) { ASSERT(wParam); *((COLORREF*) wParam) = GetColour(); return 0; }
LRESULT CColourPicker::OnSetColour(WPARAM wParam, LPARAM) { ASSERT(sizeof COLORREF <= sizeof WPARAM); SetColour((COLORREF) wParam);
return 0; }
... and, finally, modified DDX_ColourPicker():
void AFXAPI DDX_ColourPicker(CDataExchange *pDX, int nIDC, COLORREF& crColour) { HWND hWndCtrl = pDX->PrepareCtrl(nIDC); ASSERT (hWndCtrl != NULL); if (pDX->m_bSaveAndValidate) { ::SendMessage(hWndCtrl, CPM_GETCOLOUR, (WPARAM) &crColour, 0); } else // initializing { ::SendMessage(hWndCtrl, CPM_SETCOLOUR, (WPARAM) crColour, 0); } }
So far the mod seems to be working (no more crashes), but I will keep testing.
What do you think?
Gary
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
Can you pl post an example how to use it. It would be great if you post the application shown in screenshot.
Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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.
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
Hi Paulo,
Is it possible to add a demo program for this color picker. i'm still not sure how to add it to my dialog box. Sorry for troubling you.
Thanks

Love for peace on earth
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
In MFC Way:
In Dialog Resource Editor, Put a Button Control onto Dialog. And Name it IDC_TEXTCOLOR or something.
In ClassWizard, Add a Variable to IDC_TEXTCOLOR as m_ctlTextColor, it must be a CButton variable.
In Header file of Dialog Class, Change CButton to CColourPicker as below.
CColourPicker m_ctlTextColor;
Then run it, just you can see This Great Things.
Of course, you must add some codes to set or get color values from control. But you can catch it from Paulo's Source Codes easily.
|
| Sign In·View Thread·PermaLink | 3.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|