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.