ControlWm_ctlcolorlistbox list box ControlWm_ctlcolorscrollbar scroll bar ControlWm_ctlcolorstatic text Control
For compatibility considerations, MFC still uses onctlcolor to respond to these messages, but uses the nctlcolor parameter to differentiate them. In this function, we can change the drawing of the control by changing the attribute of the PDC parameter, and return the corresponding paint brush handle to the control. The control uses this paint brush to draw its own background. Here is
Six ways to draw brushes (hbrush) 2009- -- at the: 00HBRUSH HBR; the first type: HBR= CreateSolidBrush (RGB (255,0,0));//Monochrome Paint BrushThe second kind: hbr= (hbrush) getstockobject (Black_brush);//can only take a specific color of the brush, such as Black_brush,gray_brush brushThe Third Kind: hbr= CreatePatter
1 /// 2 /// Whether the vertex is in the circle (or in the circle on the edge) 3 /// 4 /// Center Coordinate 5 /// Circle radius 6 /// Current point 7 /// 8 Public Static Bool Whether the vertex is in the circle (vector2d cpoint,Double Cradius, vector2d point) 9 { 10 Double Distance = math. SQRT (math. Pow (math. Abs (point. X-cpoint. X ), 2 ) + Math. Pow (math. Abs (p
;
}
}
// Todo: return a different brush if the default is not desired
ReturnHBr;
}
//// M_font1 and m_font2 are members of ctestdlg. The type is cfont // bool ctestdlg: oninitdialog (){...... // todo: add extra initialization here m_font1.createpointfont (120, text ("impact"); m_font2.createpointfont (120, text ("Arial "));......} hbrush ctestdlg: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor) {hbrush HBr = cdialog: onctlcolor
CDialog 2 {... 3 protected: 4 CBrush m_brush; 5 ... 6 };
② Add the following code to the oninitdialog () function:
1 bool cexampledlgdlg: oninitdialog () 2 {3... 4 // todo: add extra initialization here 5 m_brush.createsolidbrush (RGB (0,255, 0); // generate a green brush 6... 7}
③ Use classwizard to overload onctlcolor (...), That is, wm_ctlcolor message:
1 hbrush cexampledlgdlg: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor) 2 {3/* 4 ** no code i
the button is still flushed out with a gray brush, and the button background must be transparent.
2. First, I want to implement SekBkMode IN THE WM_DRAWITEM message, which has no effect. Then I want to change the registered WNDCLASS, so I find the SetClassLong and GetClassLong functions, and the INDEX parameter provides the GCL_HBRBACKGROUND type. Everything looks wonderful. So I wrote this code.HBRUSH hbr = GetStockObject (NULL_BRUSH );Int nReturn =
Adjust the control background color by programming
Su Jin Guo
In VC, the background color of the editing control can be adjusted because there is no direct property setting. Therefore, we need to use operations related to the graphic device interface to achieve this goal.
First, use the Class Wizard to construct the corresponding message ing for the wm_ctlcolor message. The following message processing functions are obtained:
Hbrush cmydlg: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlco
= LAT1 * Math. PI/180.0;LAT2 = LAT2 * Math. PI/180.0;Double SA2 = math. Sin (LAT1-LAT2)/2.0 );Double sb2 = math. Sin (lon1-lon2) * Math. PI/180.0)/2.0 );Return 2 * r * Math. asin (math. SQRT (SA2 * SA2 + math. Cos (LAT1) * Math. Cos (LAT2) * sb2 * sb2 ));}
/// /// Whether the vertex is in the circle (it is also considered in the circle on the edge)/// /// /// /// /// Whether the public static bool point is in the circle (vector2d cpoint, vector2d onpoint
Method One: Call the member function of the CWinApp class SetDialogBkColor to implement. (This function is deprecated)1void SetDialogBkColor (COLORREF CLRCTLBK = RGB (192, 192, 192), COLORREF clrctltext = RGB (0, 0, 0));Where the first parameter of the function specifies the background color, the second parameter specifies the text color.Add the following code in InitInstance ():1SetDialogBkColor (RGB (0,0,255), RGB (255,0,0));It is important to note that SetDialogBkColor must be called before c
In VC development, there are times when you are editing resources, such as the size of a control on a dialog box, the font change, the font color change, and the color change of the controls themselves, and so on.
Only the changes to the color of the control are discussed here, and the control does not contain a font. However, this method does not work on the button control, but it still has some referential significance.
Hypothetical condition: There is a static text control, placed on the dial
Process wm_ctlcolor messages
Hbrush caboutdlg: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor){Hbrush HBr = cdialog: onctlcolor (PDC, pwnd, nctlcolor );
If (nctlcolor = ctlcolor_static){PDC-> setbkmode (transparent );Return m_backhbrush;}Return HBr;}M_backhbrush is defined as a member variable of the hbrush type and initialized in oninitdialog:M_backhbrush = createsolidbrush (RGB (0,255,255 ));
Void cx
control background.
Then, we place two static controls in the dialog box, with IDs: idc_stccolor and idc_stctwo. Then add member variables to the class in the dialog box (don't tell me you don't know how to add ......), Two variables are required. Each member variable corresponds to one control ~PS: select the control variable for the variable type ~ The type of the required control variable is generally cstatic ~Then we write the following code in the message ing function just now:
Quote:
H
Some time ago, I used the slider control to write a program, but when I changed the background, the slider background did not change as I thought. Baidu finally solved the problem. However, a new problem occurs. After the image is used in the dialog box window, the slider control still has a problem and Baidu does not get the result.
During the day, I thought of a very stupid method. You can make an urgent request, and then find a good way to despise it.
First look
If it is a pure background,
Hbrush cstadus: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor)
{
Hbrush HBr = cdialog: onctlcolor (PDC, pwnd, nctlcolor );
// Todo: change any attributes of the DC here
If (nctlcolor = ctlcolor_static)
{
PDC-> settextcolor (RGB (0, 0, 0); // set it to the color of your background.
PDC-> setbkmode (0); // transparent
Return (hbrush): getstockobject (null_brush );
}
// Todo: return a different brush if the default is not desired
Return
Before each control starts drawing, a WM_CTLCOLOR advertisement message is sent to its parent window, in which you can set the foreground color, background color, and font for the control's display text. The message handler also requires that the handle of a brush be returned to erase its client area before the control's specific drawing.Hbrush Ctestdlg::onctlcolor (cdc* PDC, cwnd* pWnd, UINT nCtlColor){Hbrush HBR = Cdialog::onctlcolor (PDC, PWnd, nCt
1. Change the background color of the dialog box and add a member variable PRIVATE: cbrush m_brush; to the class of the dialog box. Add the following code to the class constructor: m_brush.createsolidbrush (RGB (255,); // initialize to Blue to add a wm_ctlcolor message response function to the dialog box, message response function specially colored for controls. The Code is as follows: hbrush csettingdlg: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor)
{
Hbrush
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.