Color Button Control
Site Map Feedback

Download:

Up Calendar ColorButton CListCtrl DragBar Icons Subclassing

This example is useful for setting colours for things. Clicking the button brings up the standard Colour Picker Dialog Box (CColorDialog) with an extra button to un-set colour. When you choose a colour, the button face becomes the colour that was chosen, or a spectrum of colour if the new [Default] button was clicked (which could tell objects to inherit their colour from their parent).

So, where would you use this? If you've used a painting or drawing package, you'll know that objects (such as lines) can assume the colour of the Layer they are in: you could use this button to set the colour of the Layers or the Lines. If the line and the layer both are colourless, you'll need to decide what default colour to use. Other than that, use the Line colour, if it has one - and if it doesn't, use the Layer colour.

The Colour Picker Dialog has an additional button to go back to using Default Colours rather than the User Layer's colour. In the following image, the top (spectrum / rainbow) button indicates a layer using default Layer Colour; The lower button indicates a Green Layer:

The Spectrum is generated by Colors.h which is described in the Colour Conversion Algorithms section.


THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.