Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5833377
  • 博文数量: 671
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 7310
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-14 09:56
文章分类

全部博文(671)

文章存档

2011年(1)

2010年(2)

2009年(24)

2008年(271)

2007年(319)

2006年(54)

我的朋友

分类: C/C++

2008-09-14 19:43:12

Introduction

For many years I have used Chris Maunder's excellent . 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:

Collapse
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

  • by Chris Maunder.

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

阅读(1272) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~