Color selector similar to Dreamweaver

Source: Internet
Author: User
Tags getcolor dreamweaver

First, the preface

A friend who has used Dreamweaver must be impressed by its color selector, because it does work, and one of the more practical features is the ability to pick any color on the screen. In this way, the author encapsulates a class called Ccolorpicker to implement similar functions and corrects the disadvantage of the Dreamweaver color selector to approximate the colors selected on the screen. This paper introduces the usage of Ccolorpicker class in detail, and provides a sample project for readers ' reference.

The following illustration is an illustration of the execution of the sample code

Ii. Brief introduction of Ccolorpicker

The Ccolorpicker class is derived from CButton and can be used as a generic button. Because of the convenience of encapsulation and use, the mouse Cursor and Color dialog box are dynamically established. This class provides the function of automatic binding, when the color of the selection is changed through the Bn_clicked event to notify the parent window, let us look at the specific use of Ccolorpicker class steps bar!

Third, the specific use of the steps (as an example of the project)

3.1 Preparation work

Create Colorpickerdemo dialog box MFC project.

Copy the Colorpicker.h,colorpicker.cpp two files provided in this article to your engineering directory and add them to the project.

3.2 Using the Resource Editor, add the ID: Idc_button1 button in the main dialog box to set it to the owner draw property in the style. In the Ccolorpickerdemodlg class, add the control category's member variable to Idc_button1, Variables, M_btncolor1, Then, in ColorPickerDemoDlg.h, CButton m_btncolor1 be replaced by Ccolorpicker M_btncolor1;

and add #include "ColorPicker.h" to the ColorPickerDemoDlg.h.

Compile the run to see the effect bar!

3.3 Programs can already be run, but how do I get a notice of color selector changes? The bn_clicked click event for the button here has become a color-changing event. We can add a color change handler function just as you would add a button-click handler.

In the processing function we can get the color value of the COLORREF type through the COLORREF Ccolorpicker::getcolor () function, or through void Ccolorpicker::getcolor (cstring& Strcolor) function to get a string of type such as #ffffff style directly. Please see the following code:

void CColorPickerDemoDlg::OnButton1()
  { COLORREF m_clrBKColor = m_btnColor1.GetColor(); CString strColor; m_btnColor1.GetColor(strColor); }

3.4 Automatic binding function

If you need to automatically write color values to a window after you select a color, you can set a bound window with the void Ccolorpicker::setbuddy (HWND hwnd) function, which is useful when you automatically set the editing box text.

Color Selector Ccolorpicker is introduced here, I would like it to add to your program, see next time!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.