Screen color picker (VC ++)

Source: Internet
Author: User
Tags knowledge base

System Environment: Windows 7

Software environment: Visual C ++ 2008 SP1

Objective: To compile a color picker

Refer to an article in the VC knowledge base.ArticleFor information on the Internet. I tried it myself. The following is the running interface:

First, create a project based on the dialog box and add the control;

Then, add ontimer () event processing for the dialog box, as shown below:

Add the followingCode:

Void cgetrgbdlg: ontimer (uint_ptr nidevent) <br/>{< br/> // todo: add the <SPAN class = 'wp _ keywordlink '> Program </span> code and/or call the default value <br/> If (nidevent! = 1) <br/> return; </P> <p> cpoint pt; <br/> getcursorpos (& pt ); // obtain the cursor position <br/> HDC =: getdc (null); // obtain the screen DC <br/> colorref CLR =: getpixel (HDC, PT. x, PT. y); </P> <p> cstring clrtext; <br/> clrtext. format (_ T ("% d"), getrvalue (CLR); // break down the red value <br/> Red = getrvalue (CLR ); <br/> setdlgitemtext (idc_red, clrtext); <br/> clrtext. format (_ T ("% d"), getgvalue (CLR); // break down the green value <br/> Green = getgvalue (CLR ); <br/> setdlgitemtext (idc_green, clrtext); <br/> clrtext. format (_ T ("% d"), getbvalue (CLR); // break down the blue value <br/> Blue = getbvalue (CLR ); <br/> setdlgitemtext (idc_blue, clrtext); <br/> onpaint (); <br/>: releasedc (null, HDC ); // release the screen DC <br/> cdialog: ontimer (nidevent); <br/>}

For the "pick up" button

Void cgetrgbdlg: onbnclickedbutton1 () <br/>{< br/> // todo: add the control notification handler code here <br/> settimer (1, 80, null ); <br/>}

For the "stop" button

Void cgetrgbdlg: onbnclickedbutton2 () <br/>{< br/> // todo: add the control notification handler code here <br/> killtimer (1 ); // stop get color <br/>}

For more detailed code, seeHttp://download.csdn.net/source/1849794

View.

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.