5,696,038 members and growing! (14,343 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » Lists, Menus, Choosers     Intermediate

CColorChooser an IDE style Color Picker

By Norm .net

CColorChooser an IDE style Color Picker
VC6, C++, Windows, MFC, Visual Studio, VS6, Dev

Posted: 4 Oct 2001
Updated: 4 Oct 2001
Views: 36,921
Bookmarked: 16 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
18 votes for this Article.
Popularity: 5.21 Rating: 4.15 out of 5
1 vote, 14.3%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
2 votes, 28.6%
4
4 votes, 57.1%
5

Motivation

Visual Basic is certainly not my cuppa tea, but the Visual Basic IDE does have some good ideas which applications can benefit from. One these is the Color Chooser popup window which allows the user to select a desired color. I've extended the control to include the Web Colors which are found on the new Visual Studio .NET IDE.

During a recent project I needed to design a color chooser and I turned to the VB IDE for 'help'.

Design

The window components contained in the project are show below:

Due to the lose coupling of the design CPaletteWnd, CSysColorWnd or CWenColorWnd can be used in isolation if so required in another project. The CColorChooser contains all the functionality and routes specific user messages back to the parent via PostMessage. Custom colors are persistent to the application and are serialized during CColorChooser construction and destruction (stored in the registy).

The project covers owner draw controls and have to create a custom control.

Implementation

  1. Include the add the following files to the project.
  2. ColorChooser.h & ColorChooser.cpp
    PaletteWnd.h & PaletteWnd.cpp
    WebColorWnd.h & WebColorWnd.cpp
    SysColorWnd.h & SysColorWnd.cpp
    
  3. Where the CColorChooser is to be implemented add the include file.
    #include "ColorChooser.h"
  4. Create a placeholder for the CColorChooser in the class
    class CYourView : public CView...
    {
    public:
    	CColorChooser*	m_pWndColorChooser;
  5. Initialize in the constructor
    CYourView:: CYourView()
    {
    	m_pWndColorChooser = NULL;
    
  6. My example pops the chooser up when the user right mouse clicks.
    void CPaletteTestView::OnRButtonUp(UINT nFlags, CPoint point) 
    {
    	if (m_pwndChooser == NULL)
    	{
    		ClientToScreen(&point);
    		m_pwndChooser = new CColorChooser(point, this, m_crCurr);
    
    	}
    
  7. When the user selects or loses focus I destroy the window and 'catch' the selected color respectively.
    LRESULT CPaletteTestView::OnColorChanged(WPARAM wParam, LPARAM lParam)
    {
    	m_crCurr = lParam; // Color is contained in lParam
    
    	delete m_pwndChooser;
    	m_pwndChooser = NULL;
    
    	RedrawWindow();
    	return 0;
    }
    
    LRESULT CPaletteTestView::OnColorChooserClose(WPARAM wParam, LPARAM lParam)
    {
    	delete m_pwndChooser;
    	m_pwndChooser = NULL;
    	return 0;
    }
    

This article forms a small part of the future article covering a property list control.

Any bugs,  enhancements or suggestions please don't hesitate to contact me.

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

About the Author

Norm .net



Occupation: Architect
Company: Software Kinetics
Location: United Kingdom United Kingdom

Other popular Miscellaneous articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
GeneralHow can I...memberDarren Schroeder7:18 29 Mar '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 4 Oct 2001
Editor: Chris Maunder
Copyright 2001 by Norm .net
Everything else Copyright © CodeProject, 1999-2008
Web20 | Advertise on the Code Project