Office 97 style Colour Picker control

Environment: VC4, VC5, VC6, Win9x, WinNT

This sample was contributed by Chris Maunder, and extended by Alexander Bischofberger.

Colour Picker image Download source files (13 Kb) or sample project (41 Kb).

Latest updates here. (version 1.3)

In an effort to have the latest and greatest wizz-bang features in my programs I unashamedly ripped of the colour picker from Office 97.

Initially I tried to modify an owner drawn combo box and combine that with a multicolumn combobox, but current multicolumn combo boxes are really just a single column with dividing lines drawn in. I then decided to write the whole thing from scratch based on a button, since it would at least give me a BN_CLICKED notification to get things started.

The colour picker is in two parts: an owner drawn button that reflects the currently selected colour, and a popup colour chooser window to select this colour. When the user clicks on the button the popup window appears and all mouse messages are captured until the left mouse button is clicked, or until the Enter or Escape keys are pressed. The popup window can be navigated using the mouse or the keyboard and includes tooltips explaining what each colour is.

The control can be incorporated into a project like any other Cbutton derived control. Either Create the control manually, subclass an existing CButton or DDX_control it. The control also comes with a DDX_ColourPicker routine to get/set the colour of the control using a variable of type COLORREF.

The Colour Picker is contained in the class CColourPicker. It uses the class CColourPopup for the popup window. These classes are contained in the file colour_picker_src.zip, and a sample project is contained in colour_picker_demo.zip.

CColourPicker only has the following public member functions:

		void     SetColour(COLORREF crColour);
		COLORREF GetColour();

		void     SetDefaultText(LPCTSTR szDefaultText);
		void     SetCustomText(LPCTSTR szCustomText);

		void     SetSelectionMode(UINT nMode); // Either CP_MODE_TEXT or CP_MODE_BK
		UINT     GetSelectionMode();

		void     SetBkColour(COLORREF crColourBk);
		COLORREF GetBkColour();
    
		void     SetTextColour(COLORREF crColourText);
		COLORREF GetTextColour();

SetDefaultText allows you to set the text that will appear in the "Default" area of the colour chooser. If you pass NULL, then the Default area will not be available to the user. If this area is availble and the user selects it, the value CLR_DEFAULT will be returned.

SetCustomText allows you to set the text that will appear in the "Custom" area of the colour chooser. If you pass NULL, then the Custom area will not be available to the user. The Custom area allows the user to select a custom colour using the standard windows colour selection dialog.

You can choose whether the colour chosen using the dropdown colour chooser will affect the text or the background colour using the function SetSelectionMode(int nMode). Possible values for nMode are CP_MODE_TEXT to make colour changes affect the text colour, and CP_MODE_BK to make changes affect the background (default).

SetColour, GetColour and the the DDX-function will set and get the colour according to the current selection mode. To access the text colour and the background colour directly use the Set/GetTextColour and Set/GetBkColour functions.

There are also a number of user messages that may be handled to get more information from the control. These are:
 

Message Description
CPN_SELCHANGE Colour Picker Selection change
CPN_DROPDOWN Colour Picker drop down
CPN_CLOSEUP Colour Picker close up
CPN_SELENDOK Colour Picker end OK
CPN_SELENDCANCEL Colour Picker end (cancelled)

These messages can be handled using ON_MESSAGE(< MESSAGE>, MessageFn) in you message map entries, where MessageFn is of the form


    afx_msg LONG MessageFn(UINT lParam, LONG wParam);

The demo program gives an example of how to do this.




New in Version 1.1

The following changes have been made by Alexander Bischofberger.

The original version did not display a text inside the combo box. The current version now displays the button text (as set in the dialog resource, or via SetWindowText). You can choose whether the colour chosen using the dropdown colour chooser will affect the text or the background colour using the new member function SetSelectionMode:

		#define CP_MODE_TEXT 1		// Colour selection affects text colour
		#define CP_MODE_BK   2		// Colour selection affects background colour (default)

		void     SetSelectionMode(UINT nMode);
		UINT     GetSelectionMode();
Two new member functions have been introduced to set the text colour and the background colour directly:
		void     SetBkColour(COLORREF crColourBk);
		COLORREF GetBkColour();
    
		void     SetTextColour(COLORREF crColourText);
		COLORREF GetTextColour();

SetColour, GetColour and the the DDX-function will set and get the colour according to the current selection mode.

Some minor changes were made in the drawing routine (now faster and able to show a pressed combo box button), the messaging (CPN_SELCHANGE now sent to the parent).

The following changes have been made by Chris Maunder.

The button now stays pressed while colour choosing is in progress, and the initial colour sent to the drop down colour chooser is highlighted as in Office 97. Oh - and a line now separates the Custom Text area from the colours. weee!

Palette support is now included so things don't look so bad in 256 colours.

See the updated sample how to use the new functionality.

New in Version 1.2

The following changes have been made by Chris Maunder.

The picker now looks a little more like the office 97 version, although it does not as yet support the "cool" look. Any number of colours can now be used in the picker (although these are still hardwired in).

Two new functions were added:

		void SetDefaultText(LPCTSTR szDefaultText);
		void SetCustomText(LPCTSTR szCustomText);

These specify the text (if any) that will appear in the "Default" selection area and the "Custom colour" selection area. See main section of this doc for details.

New in Version 1.21

Minor bug fix when losing focus to another application. Fix suggested by Paul Wilkerson.

New in Version 1.3

Colour cells now drawn with thin border (thanks to Geir Arne Trillhus). If cancel is hit in the custom colour picker popup, a CPN_SELENDOK is no longer sent. Also compiles clean under VC6

Updated 9 January 1999



Comments

  • All første kvalitet af Dr. Dre hovedtelefoner

    Posted by rfjjtb636 on 07/16/2013 08:26pm

    Give indsigt i LOCOG tænkning, og måske om ikke dets juridiske team vil reagere forskelligt på Dr Dre har Beats hovedtelefoner stunt, en talsmand sagde dengang: “Vores tilgang til håndhævelse i 2006 loven har altid været fornuftig, pragmatisk og forholdsmæssige.”Vi er nødt til at beskytte rettighederne for vores sponsorer, der har betalt for at få eksklusive associationer til legene i deres sponsorater kategorier. Vi er hård på kommercielt misbrug, men vi ønsker ikke at gøre noget for at dæmpe ægte begejstring og spænding om Games . [url=http://beatsbydrdredan.ucoz.com/]beats by dre billigt[/url] monster beats hovedtelefoner tendens til at være på det aspekt af en fremragende synes høj kvalitet og vidunderlige overordnede udseende. Efter min mening, hvis du ofte har en god fan vedrørende lyd til eller gå med sange af en stringent tilgang, eller du bare brug for at få din arbejdsplads med fremragende afslapning, så er du måske nødt din bil beruset med sin perfekte lydkvalitet fremragende. [urlhttp://beatsbydredanmark.webspawner.com/]Beats by Dre[/url] i hvert fald set er en god musik altid være påkrævet, og hovedtelefonerne som Dre beats forbedrer sådan musik, så du har lyst til himlen. I denne artikel vil vi diskutere, hvor langt disse bemærkelsesværdige hovedtelefoner (Dre beats hovedtelefoner) er i stand til, og hvordan strålende det kan støtte dig til at få essensen af musikken. For din korte viden – Monster har formået at kombinere stil med funktionalitet i Dr. Dre udvalg af hovedtelefoner understøtter disse ikke blot at se godt, men også at gøre lydkvaliteten endnu bedre. Hvis du kigger ind i dens specifikationer så du kan indse det, at de beats fra Dre hovedtelefoner lyd er altid velafbalanceret med en varm mellemtone og dunkende bas.

    Reply
  • Høy kvalitet, ghd rettetang billig er favoritten av unge mennesker

    Posted by carpinteyrofma on 06/14/2013 03:50am

    [url=http://www.rettetangnorgenews.net/]ghd rettetang pris[/url] Varmen går lettere gjennom tynt hår enn tykt hår. Derfor har Satin Hair 7 Colour rettetang en intuitiv varmejustering som lar deg forhåndsinnstille temperaturen nøyaktig etter hårtypen (tynt, normalt, tykt hår). Og selv om du bruker effektknappen for å temme uregjerlige hårlokker, så vil du ikke utsette håret ditt for temperaturer på over 200 °C. Få flotte stylingresultater uten fare for for høye temperaturer og nyt den flotte hårfargen din lenger.Tvert imot: de hindrer fuktighetstap fra stylingen ved å påføre unike satengioner til håret ditt! Disse negativt ladde ionene fester seg til det positivt ladde håret ditt og reduserer tørt, krusete hår og tiltrekker fuktighetspartikler fra lufta og sender dem dit hvor håret trenger det mest. [url=http://www.rettetangnorgenews.net/beste-ghd-rettetang/beste-ghd-rettetang.html]beste ghd rettetang[/url] GHD Mk4 IV kysse er de beste ghd-rettetang ennå strålende rosa Kiss edition vil være for en kort periode bare tilgjengelig så ikke gå glipp av din sjanse på verktøyet, perfekte krøller, bevegelse, volum – gir tilgang og caremic rettetang udisiplinerte… og henne sexiest ennå i glans het lyserød og som Hvis dette var ikke nok, £ 10 fra hvert salg går gjennombrudd brystkreft! [url=http://www.rettetangnewsnorge.com/falske-ghd]rettetang ghd[/url] GHD rettang 7 børste med aktive ioner er en revolusjonerende nyvinning innen hårpleie, og er utviklet for at kvinner til enhver tid skal kunne ta seg best mulig ut.Du kan innstille denne spesielle varmejusteringen etter som håret ditt er tynt, normalt eller tykt, mens den fleksible platen minimerer for mye trykk. Resultatet er vakre, elegante hårfrisyrer med minimalt med falming av fargen.

    Reply
  • Welke koptelefoon moet ik kopen

    Posted by mrswanzi on 06/05/2013 06:42pm

    [url=http://monsterkoptelefoon.npage.de/]beats by dre kopen[/url] Nog voor de headphones voor de consument op de markt verschenen, liepen verschillende grote artiesten uit de Amerikaanse hip hop- en rapscene al met een Beats by Dr. Dre rond. Zo is Lady GaGa in de clip van Pokerface uit 2008 te zien met een Beats by Dr. Dre. Het is slechts een paar tellen, maar na de introductie van de muziekvideo stellen vele fans diezelfde twee vragen: van welk merk is toch die hoofdtelefoon met die rode B en hoe kom ik daaraan Steeds meer artiesten volgden het voorbeeld van LeBron James en Lady GaGa. Niet omdat de hoofdtelefoons significant beter waren dan andere merken, maar puur vanwege de uitstraling: mode. [url=http://koptelefoon-monsterbeats.webs.com/]Goedkope Beats by dre[/url] Elke hooftelefoon die is gekocht bij een Monster is voorzien van een krasbestendige hoogglans afwerking die er voor zorgt dat de hoofdtelefoon er prefect uit blijft zien, ondanks intensief gebruik. De wereldwijde Monster Beats verkoop cijfers zijn het bewijs voor de superioriteit van het merk. De Beats By Dre hoofdtelefoons kunnen gemakkelijk gebruikt worden met verschillende draagbare apparaten zoals de iPhone en de Blackberry. De Beats by Dr. Dre hoofdtelefoons hype van de [url=http://koptelefoon-monsterbeats.manifo.com/]beats by dre[/url] Beats by Dr Dre breidt gamma uit een draagbare muziekspeler, De voorbije zomer kenden de koptelefoons van Beats by Dr Dre een grote populariteitsgroei. De toestellen richtten zich vooral op actieve jongelui die op een stijlvolle manier hun muziek overal willen meenemen. Met de nieuwe Executive-koptelefoon denkt het merk nu ook aan de professionele zakenlui.Dit apparaat komt met een ingebouwde microfoon, waardoor je telefoongesprekken kan voeren zonder je hoofdtelefoon af te doen. De hoofdtelefoon heeft in vergelijking met zijn voorgangers een strak en volwassen design meegekregen en komt enkel in combinatie van grijs en zwart.

    Reply
  • Fans, der kan lide at fÃ¥ deres hænder og hovedtelefoner

    Posted by wherewanzi on 06/05/2013 06:42pm

    [url=http://beatsbydrdredanmark.weebly.com/]Beats by dre danmark[/url] On classical tracks, like John Adams’ “The Chairman Dances,” high-register strings, brass, and percussion take center stage. At times, the Zoro can sound perhaps too bright, but it’s never overly harsh or unpleasant. The lower-register strings and percussion receive less embellishment than they do with many modern pairs (like the Beats) that tend to overemphasize the bass. Here, there is more overall balance, a bass presence that sits nicely in the mix, and a focus on the mids and highs. [url=http://beatsbydrdredanmark.moonfruit.com/]beats by dre tilbud[/url] at undlade lyd i høretelefonerne for en stund, hvis der skulle dukke noget uventet op i din tilværelse.Kassen indeholder naturligvis Beats by Dr. Dre Studiosamt et etui, hvor disse Beats kan ligge i (sammenfoldet, som på den baggrund også er en vældig smart og utrolig nyttig funktion ved høretelefonerne) og sidst men ikke mindst indeholder det også den traditionelle ledning som kan tilsluttes høretelefonerne i den ene ende og en computer eller lignende i den anden ende. Ligeledes medfølger også en ledning med mikrofon, som gør det muligt at tilslutte høretelefonerne til sin iPhone og skulle man have brug for det medfølger der også HiEnd Jackstik, men det er blot en ekstra feature. [url=http://beatsbydrehretelefoner.weebly.com/]beats by dre høretelefoner[/url] This focus brings a nice clarity to vocal performances. On Bill Callahan’s “Drover,” the vocals are delivered with an extra bit of treble edge that only adds to Callahan’s unique baritone delivery. The vocals also standout nicely on Jay-Z and Kanye West’s “No Church in the Wild”—the mix still features plenty of low-end resonance, but the emphasis on mids and highs helps the vocals shine, rather than get lost by the intense production, which can happen pretty easily with hip hop and electronic tracks on lesser headphones.

    Reply
  • Las planchas se usan ya en casi todos los desfiles de moda

    Posted by wanzilucky on 06/05/2013 06:42pm

    [url=http://www.planchasespanaghdtop.net/plancha-pelo-ghd/]ghd outlet[/url] Usando una combinación de la más alta de calor y ajuste de la velocidad y el botón de aire frío, el pelo se seca en menos de 5 minutos. El secador de pelo es ligero y de diseño ergonómico que se sienta muy bien en su mano, para no mencionar el hecho de que es más tranquilo y mi pelo se seca y rápidos. Me tomó un poco de tiempo para acostumbrarse a los botones en la parte posterior del secador de pelo – que fue diseñado para que sea accesible para los zurdos entre nosotros. [url=http://www.planchasespanaghdtop.net/plancha-pelo-ghd/]plancha pelo ghd[/url] Va a estar tan contento con uno mismo. Los alisadores de pelo ghd se calientan rápidamente y simplemente se deslizan sobre el cabello en la primera pasada. Ellos trabajan tan rápido que usted se sorprenderá. Son caros, pero cuando lo reciba usted verá por qué.Ellos realmente son el Rolls Royce de las planchas para el pelo. ghd son rápidos y fáciles de usar. Las placas grandes son perfectas para el cabello más largo y grueso. El ghd IV salon styler es absolutamente brillante y aún más eficiente en el pelo grueso y largo que los originales. Las placas de ancho han reducido el estilo de 15 minutos cada mañana con facilidad. [url=http://planchas-ghd.manifo.com/]planchas ghd[/url] Tanto 10€ de cada venta de la styler ghd PINK Cherry Blossom, como 6€ de la venta de ghd air PINK Cherry Blossom serán destinados a proyectos de investigación del Cáncer de mama a través de las Fundaciones FERO y Sandra Ibarra de Solidaridad Frente al Cáncer.

    Reply
  • GHD MK4 sort

    Posted by cheneason on 05/30/2013 03:20am

    [url=http://www.auriculares-beats.webstarts.com/]Auriculares beats[/url] Til personlige kommer tilbage igen inde i det vilde hår direkte gør et forsøg på GHD låser hår-styling metalliske, skal du gøre brug af et par tiltalende tiltrækkende ønskeligt, forstørre spejle og også masser af svip i et forsøg på at område af dit vilde hår. Det er vigtigt at har tendens til at arbejde med i specifikke biceps samt hænder og håndled kontrolelementet håndled og hænder fingre side afspejler ud over din aktuelle toilet eller måske dybest set blot kun madras model kontrol hænder og håndled palms side hånd spejl, beliggende i du faktisk finde ud til at i masser af situationer er inden for din egen ejendom for alle der har hairstyling frizzy hår. Modtage den GHD Straightner klar til at udføre generelt region dit vilde hår derfor den førende funktionalitet klassen bliver faktisk helt forskellige under position tilbage lige så som foran. Efterfølgende tage i betragtning 3 facetter fra den specifikke kick ud placering hår generelt video hver bestemt én af disse typer, så de kan ofte være en række. [url=http://www.auricularesbeats.weebly.com/]auriculares beats[/url] Ghd glattejern er populære, ikke kun på grund af sin funktionalitet, men også af dens smukke pakker. Vi anbefaler dig til ghd Storbritannien i løbet af internettet for at spare dig en masse. [url=http://www.beatsbydre777.weebly.com/]auriculares beats[/url] En fremragende “øjeblikkelig conditioner” er almindeligvis en bestemt dette specifikke præcise klæder din gode hår dage krøllet hår glatning klubber samt giver disse fysik foruden glimt. Speedy hår hårbalsam minimere den faktiske unikke forbedrede neglebånd, oprette dine distinkte god Ghd Tilbud Tresses gør dig hår jern moderat desuden opnås, med hinanden ved hjælp af assistance sikre den faktiske tydelig indre design i de ekstraordinære vilde hår tidsperioder basis via skade gennem betyder at involvere medvirken såsom en filtrering. Denne form for afhjælpning vilde hår emne vil rutinemæssigt blive gengivet anytime ens personlige Ghd hår styling jern vil blive skyllet ud.

    Reply
  • Fansatic

    Posted by Ajay Vijay on 11/20/2004 06:00am

    Great and amazing work!

    Reply
  • How can I using ColorPicker in my Toolbar?

    Posted by Legacy on 01/09/2004 12:00am

    Originally posted by: Eugene Kim

    I tried , and using Create function of CButton.
    It looks like to work , but always in disabled mode.

    I have no idea how to change or, I think in creation period, something needed or some option to include ..

    Anyway, color Picker does not work . plz. help me.


    Code.. Like this. !!!

    m_ColorText.Create(_T(""), WS_CHILD|WS_VISIBLE, Colorrect, this, ID_FONT_COLOR);

    Reply
  • cannot open file "mfc42u.lib"

    Posted by Legacy on 05/11/2003 12:00am

    Originally posted by: arnold

    complie error is "cannot open file "mfc42u.lib""

    Reply
  • doesn't show right color

    Posted by Legacy on 05/25/2001 12:00am

    Originally posted by: new user

    If you click on ColorPicker, it doesn't show the the selected color of ColorPicker. Instead it just displays all colors unselected. When MORE COLORS is clicked, it does not show color of ColorPicker, instead it selects black color each time.

    I think this control will be more desirable when it correctly identifies the color of ColorPicker.

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

  • The latest release of SugarCRM's flagship product gives users new tools to build extraordinary customer relationships. Read an in-depth analysis of SugarCRM's enhanced ability to help companies execute their customer-facing initiatives from Ovum, a leading technology research firm.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds