Win32 Call System Colors dialog box

Source: Internet
Author: User

Reference website: http://blog.csdn.net/u013242177/article/details/50437358

    • First, include the commdlg.h header file, which is the header file for the common dialog, including the file dialog, the color dialog, the Print dialog box, and so on.
    • It then declares a variable of type Choosecolor, declaring a variable rgblinecolor of type COLORREF, which is used to store the color selected by the user.
Staticstatic colorref Rgblinecolor;

Where Choosecolor is a struct, including some information about initializing the Color dialog box with the Choosecolor function, you can find the structure from MSDN as follows:

typedef struct {

DWORD lStructSize;

HWND hWndOwner;

HWND hinstance;

COLORREF Rgbresult;

colorref* lpcustcolors;

DWORD Flags;

LPARAM Lcustdata;

Lpcchookproc Lpfnhook;

LPCTSTR Lptemplatename;

} Choosecolor;

    • And then assign a value to the contents of the Stchoosecolor.
Stchoosecolor.lstructsize    sizeof(choosecolor); Stchoosecolor.hwndowner      = hWnd; Stchoosecolor.rgbresult      = rgblinecolor; stchoosecolor.lpcustcolors   = (Lpdword) dwcustcolors; stchoosecolor.flags          = cc_rgbinit; stchoosecolor.lcustdata      0 ; Stchoosecolor.lpfnhook        == NULL;
    • Finally, use the Choosecolor function to create a color dialog box for the user to select a color
if (Choosecolor (&= stchoosecolor.rgbresult;}

Get the RGB component values in COLORREF:

COLORREF Colorrrefrgb =rgb (+ = = Getbvalue ( COLORRREFRGB);
code example:
#include"commdlg.h"......................................voidCmydialogt::onbnclickedbuttonpickcolor () {//Todo:add your control notification handler code here    StaticChoosecolor Stchoosecolor; StaticCOLORREF Rgblinecolor; StaticCOLORREF dwcustcolors[ -]; Stchoosecolor.lstructsize=sizeof(Choosecolor); Stchoosecolor.hwndowner= This-m_hwnd; Stchoosecolor.rgbresult=Rgblinecolor; Stchoosecolor.lpcustcolors=(Lpdword) dwcustcolors; Stchoosecolor.flags=Cc_rgbinit; Stchoosecolor.lcustdata=0 ; Stchoosecolor.lpfnhook=NULL; Stchoosecolor.lptemplatename=NULL; if(Choosecolor (&Stchoosecolor)) {Rgblinecolor=Stchoosecolor.rgbresult; BYTE R=Getrvalue (Rgblinecolor); BYTE g=Getgvalue (Rgblinecolor); BYTE b=Getbvalue (Rgblinecolor); }}

Operation Result:

Win32 Call System Colors dialog box

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.