Click here to Skip to main content
12,894,593 members (64,749 online)
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 13 Jul 2005

ThePalette Visual Studio Add-in

, 13 Jul 2005
Rate this:
Please Sign up or sign in to vote.
Color picker/dropper with zoom, user-defined multiple palettes, automatic parsing/replacement/insertion into code, and support for RGB, HSV, HLS, CMYK macros as well as HTML and plain (hexa)decimal color formats.


Many of us often need to work with color macros, inserting them into our code one and a million times over while we look for a copasetic combination of alizarin crimson, scheveningen green and indanthrene blue. Catering to this madness, there are scores of color picker utilities out there... and some of them right here, in the CodeProject.

Yet, to my knowledge, there are just a handful of color picker add-ins, and the difference matters. For years, I have used Alex Vallat's ColourPicker Add-in and have come to completely rely on it. This wonderful little add-in grabs the color of the selection I've made or automatically scans for the boundaries of the RGB macro where the caret was. After I've chosen a color from the standard Windows color dialog (or with the dropper), the ColourPicker inserts the RGB macro directly into my code.

Convenient in-friggin'-deed, my friends.

Well, as it happens with software that is used regularly, one often dreams of tweaking it one's own way to suit one's own peculiar conception of it all. And so, the mind departs from the task at hand, floating as it were in zero-g reverie, visiting rarely activated neural assemblies of suspect dendritic affiliation, skipping along ever-recursive paths, whistling outside the rhythm of lucid discourse, and, in short, ineptly collecting gerunds without a single care in the world.

Might it have been on one of those kooky journeys that I unwittingly rendezvoused with ThePalette add-in, a picker/dropper with zoom, user-defined multiple palettes, automatic parsing/replacement/insertion into code, and support for RGB, HSV, HLS, CMYK macros as well as HTML and plain (hexa)decimal color formats?



  1. Download the add-in binaries and unzip the file.
  2. Copy the file 'thepalette.dll' to the folder '{VisualStudio}\Common\MSDev98\AddIns'.
  3. Close all files, projects and workspaces!!!!!! else ThePalette won't work. You've been warned, bold letters and all.
  4. Navigate to the menu Tools/Customize... and click on the tab 'Add-ins and Macro Files'.
  5. If there is no entry for 'ThePalette Add-in', click on 'Browse' and locate it manually.
  6. A toolbar button is available and should be displayed automatically. If not, click on the tab 'Commands', select 'Add-ins' from the 'Category' dropdown, and drag'n'drop ThePalette's icon onto the appropriate toolbar.

How to Use

Once invoked, ThePalette add-in scans the text surrounding the caret and automatically detects boundaries by following the steps below:

  1. Tries to identify one of the color macros (RGB, HSV, HLS, or CMYK).
  2. If unsuccessful, then tries to identify HTML, hexadecimal or decimal formats.
  3. If unsuccessful, then grabs an identifier (useful when replacing variables or defines).

(Note that if a selection has been made by the user, ThePalette skips the scanning and takes the selected text at his/her risk.)

If the chunk of extracted text can be evaluated into a color (i.e., RGB( 123, 0xA0, 255 ) can be evaluated while RGB( rand() % 255, g1, 34 ) cannot), ThePalette inserts the color in the first available white ColorCtrl and, if none is found, in the first (top-left) ColorCtrl in the grid.

While running, ThePalette relies on certain combinations of mouse clicks, CTRL/SHIFT, and ARROW keys, in order to provide quick access to functionality. These combinations suit me but here is the code for you to modify it as it pleases you.

Now, the heart of ThePalette is the 4x5 grid of ColorCtrls. These controls display the colors of the active palette and behave as describe below.

LEFT-CLICKPlaces the focus on the ColorCtrl under the mouse.
Double LEFT-CLICK or
Inserts the corresponding color macro/value into the code (add-in) and/or copies it to the clipboard (standalone).
Brings up the Windows Color Dialog.
UP/DOWN/LEFT/RIGHT arrow keysMove the focus within the ColorCtrl grid in the corresponding direction.
CTRL + UP/LEFT arrow keysActivates the next palette (in alphabetical order).
CTRL + DOWN/RIGHT arrow keysActivates the previous palette (in alphabetical order).
SHIFT + UP/DOWN/LEFT/RIGHT arrow keysSwap the colors of two adjacent ColorCtrls in the corresponding direction.
SHIFT + LEFT-CLICKStarts a drag 'n' drop operation. If the SHIFT key is not pressed at release time, the color of the source ColorCtrl is copied to the target ColorCtrl. If the SHIFT key is pressed while releasing the LEFT mouse button, the source and target ColorCtrls swap colors.
'z' key
Activates the zoom and changes the mouse cursor to the crosshair. Read below for details on this operation.

When the zoom is active, the following applies:

UP/DOWN/LEFT/RIGHT arrow keysMoves the mouse cursor one pixel in the corresponding direction to facilitate precision placing.
SHIFT + UP/DOWN/LEFT/RIGHT arrow keysMoves the mouse cursor five pixels in the corresponding direction.
CTRL + UP arrow key or
rotating the MOUSE-WHEEL backwards
Zoom in.
CTRL + DOWN arrow key or
rotating the MOUSE-WHEEL forward
Zoom out.
Picks the color of the pixel under the crosshair and places it in the color control that triggered the zoom operation.
ESC key
Cancels the zoom operation.

The Options dialog should be self-explanatory.

The Palettes dialog facilitates simple management of palettes (add, rename, delete, duplicate). The listbox enumerates the palettes in alphabetical order and hover tooltips serve to remind us of the contents of each. The FillPalette dialog provides a quick way to (re)set a palette (clicking on the preview shows the original palette).

Differences between the Add-in and the Standalone

Aside from the obvious difference, namely integration with Visual Studio, there is little difference between both versions.

The add-in creates two settings files. The first of these contains the information particular to a given project and is located in each workspace directory that has used ThePalette (the filename takes the form of '{Workspace}.tpl'). The second file contains shared settings (i.e. dialogs' positions) and is located in '{VisualStudio}\Common\MSDev98\Bin\ThePalette.ini'.

The standalone creates a single settings file ('ThePalette.ini') in the directory where ThePalette resides. The standalone also provides the option to inspect the clipboard on startup (the default behavior) and when minimized, it is sent to the SystemTray.

The Source Code

Because ThePalette is a small project, I decided to code it from scratch which, I'm afraid, means that the classes that make up the project are not as clean, tested, portable, documented, general, and fruity-flavored as they could or should be.

Nonetheless, there may be something of interest for you guys. A quick description of some of the classes follows:

CCSC_BT_KeyButtonSimple CButton-derived class that translates arrow-key events into focus changes.
CCSC_ST_ColorCtrlCStatic-derived class that customizes some mouse/keyboard events, implements drag 'n' drop, and triggers the zoom operation.
CCSC_ST_FitToClientSimple CStatic-derived class that displays a given text using the largest font that fits the control's client area.
CCSC_ST_PalettePreviewSimple CStatic-derived class to create and display a palette in the FillPalette dialog.
CCSC_ST_URLSimple CStatic-derived class that displays a hover-sensitive hyperlink.
CCSC_ST_ZoomCStatic-derived class that captures and displays a screenshot of the desktop.
CDAT_ColorCodeA collection of static methods for parsing, evaluation, and color conversions (See WARNING below).
CDAT_IniFileEncapsulates INI file reading/writing.
CWIN_ToolTipManagerCWnd-derived class that displays multiline text and color-grid tooltips.

Warning on the Color Conversions to/from HSV, HLS, and CMYK

I have not been able to find algorithms that convert to/from HSV, HLS and CMYK accurately (although the error may well be in my implementation).

ThePalette works with COLORREFs internally and this requires a double conversion from the values found in your code to COLORREF and then from COLORREF to one of these formats. Therefore, ThePalette will report values that do not match those found in your code.

(Of course, if a color is manufactured - chosen, picked - with ThePalette, only one conversion is needed and what's shown will be inserted.)

Despite this problem, I have decided to include these formats because those of you that use them may still find ThePalette useful and may be able to let me know how to implement better algorithms. In the mean time, you know what to expect.


First and foremost, my gratitude goes to Alex Vallat for his ColourPicker, for that bit of help that made all the difference (mouse_event), and for the unintentional challenge that eventually got me to write ThePalette.

Credit is also due to, at least, the following:

Other praiseworthy mentions must include:

  • Dan Moulding's Visual Leak Detector which I used to check for memory shenanigans. A very, very useful tool.
  • An unrelated objective of this endeavor was to test out Whole Tomato's Visual Assist X of which I've heard a great deal. Well, I installed the trial version and it did make development much easier. Acknowledging this is the least I can do (in return) for the guys at Whole Tomato Software.


  • 1.0 (12/07/2005)
    • Initial release.


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

Louis Armstrong, Count Basie, Chick Corea, Miles Davis, Benny Goodman, Spyro Gyra, Dizzy Gillespie, Keith Jarrett, Leroy Jenkins, Yusef Lateef, Al Di Meola, Glenn Miller, McCoy Tyner, Cecil Taylor, John Coltrane, Duke Ellington, Bill Evans, Ella Fitzgerald, Jean-Luc Ponty, John McLaughlin, Fats Navarro, Tito Puente, Paul Whiteman, Sun Ra, Caravan, Joe Farrell, Paco de Lucia, Weather Report, Charles Mingus, Pat Metheny, Charlie Parker, Charlie Byrd, Mahavishnu Orchestra, Wynton Marsalis, Return to Forever, Julien Loureau, Thelonious Monk, Max Roach , Pharaoh Sanders, Albert Ayler, Ornette Coleman, Sidney Bechet,...

You may also be interested in...

Comments and Discussions

GeneralGood Job! Pin
Mohamed YEA5-Dec-05 22:03
memberMohamed YEA5-Dec-05 22:03 
GeneralRe: Good Job! Pin
Franc Morales7-Dec-05 19:01
memberFranc Morales7-Dec-05 19:01 
GeneralCouldn't install Pin
Zero DeHero19-Jul-05 4:39
memberZero DeHero19-Jul-05 4:39 
GeneralRe: Couldn't install Pin
Franc Morales19-Jul-05 12:56
memberFranc Morales19-Jul-05 12:56 

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.170424.1 | Last Updated 13 Jul 2005
Article Copyright 2005 by Franc Morales
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid