Click here to Skip to main content
12,950,099 members (63,353 online)
Click here to Skip to main content
Add your own
alternative version

Stats

48.7K views
656 downloads
30 bookmarked
Posted 10 Jan 2006

XColourPicker - yet another colour picker control

, 9 Jan 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
XColourPicker is a simple drop-in colour picker.

Introduction

For many years I have used Chris Maunder's excellent colour picker control. I have extended this control with the following features:

  • Custom colours - added functions to allow setting and retrieving 16 custom colours.
  • Window colours - added 16 commonly used Windows colours to popup (Window, WindowText, ActiveCaption, InactiveCaption, etc.).
  • Colours sorted by hue - popup now displays colours arranged more or less by hue.

This is what the new colour picker looks like:

screenshot

How To Use

To integrate XColourPicker into your app, you first need to add the following files to your project:

  • XColourPicker.cpp
  • XColourPicker.h
  • XColourPopup.cpp
  • XColourPopup.h

Then use the resource editor to add a button control to your dialog, and use the Class Wizard to attach a member variable to that control.

Next, include the header file XColourPicker.h in the dialog's header file. Then replace the CButton definition with CXColourPicker. Now you are ready to start using XColourPicker.

Demo App

The XColourPickerTest.exe demo shows how to use CXColourPicker.

screenshot

The demo dialog processes color changes in the OnColourChange handler:

LRESULT CXColourPickerTestDlg::OnColourChange(WPARAM, LPARAM lParam)
{
    if (lParam == IDC_TEXT_COLOUR)
    {
        TRACE("IDC_TEXT_COLOUR\n");
    }
    else if (lParam == IDC_BACKGROUND_COLOUR)
    {
        TRACE("IDC_BACKGROUND_COLOUR\n");
    }

    if (m_ctlTextColour.GetColor() == m_ctlBackgroundColour.GetColor())
    {
        ::MessageBox(m_hWnd,
                    "The text and background colours are identical.\r\n"
                    "The text will not be readable.",
                    "Unreadable Colours",
                    MB_ICONEXCLAMATION);
    }
    else
    {
        m_rgbText = m_ctlTextColour.GetColor();
        m_rgbBackground = m_ctlBackgroundColour.GetColor();
    }

    m_ctlTextColour.SetColor(m_rgbText);
    m_ctlBackgroundColour.SetColor(m_rgbBackground);
    m_stcColourSample.SetTextColor(m_rgbText);
    m_stcColourSample.SetBackgroundColor(m_rgbBackground);

    return 0;
}

Acknowledgments

Revision History

Version 1.1 - 2006 January 10

  • Initial public release.

Usage

This software is released into the public domain. You are free to use it in any way you like, except that you may not sell this source code. If you modify it or extend it, please consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.

License

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

Share

About the Author

Hans Dietrich
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see www.hdsoft.org.






You may also be interested in...

Comments and Discussions

 
GeneralXellent article about XColourPicker :-) Pin
DrABELL16-Sep-09 15:45
memberDrABELL16-Sep-09 15:45 
GeneralSweet! Pin
Shaun Harrington25-Jun-06 8:14
memberShaun Harrington25-Jun-06 8:14 
QuestionHans, any chance you could answer an OT question? Pin
matt200021-Feb-06 19:10
membermatt200021-Feb-06 19:10 
GeneralLooks great, but... Pin
Geert van Horrik12-Jan-06 4:04
memberGeert van Horrik12-Jan-06 4:04 
GeneralRe: Looks great, but... Pin
Hans Dietrich12-Jan-06 11:50
memberHans Dietrich12-Jan-06 11:50 
GeneralRe: Looks great, but... Pin
Geert van Horrik12-Jan-06 11:51
memberGeert van Horrik12-Jan-06 11:51 
GeneralRe: Looks great, but... Pin
Herbert Sauro16-Jan-06 15:20
memberHerbert Sauro16-Jan-06 15:20 
GeneralRe: Looks great, but... Pin
Damir Valiulin19-Jan-06 10:30
memberDamir Valiulin19-Jan-06 10:30 
GeneralSimple and clean! Pin
zabivan10-Jan-06 22:44
memberzabivan10-Jan-06 22:44 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 10 Jan 2006
Article Copyright 2006 by Hans Dietrich
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid