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
(cdc* PDC, cwnd* pwnd, UINT nCtlColor){Hbrush HBR = Cdialog::onctlcolor (PDC, pwnd, nCtlColor);return HBR;return m_brush;}
Of course, the function is also predefined in the. h file, where the background color of the dialog box is all blue.
2, if we want to set a dialog box control background and text color, as long as the above return m_brush;
if (Pwnd->getdlgctrlid () ==idc_line_style){Pdc->settextcolor (
As needed, the background color of the GroupBox control and the text control static is set to match.
Set GroupBox background color in Onctrlcolor:
if (Pwnd->getdlgctrlid () ==idc_g) {//groupbox background colorCRect RC;GetDlgItem (Idc_g)->getclientrect (RC);Pdc->fillsolidrect (Rc,rgb (70,219,182));}
if (Pwnd->getdlgctrlid () ==idc_static1) {//static background colorPdc->setbkcolor (RGB (70,219,182));}
Set the effect after:
There is a white background does not meet the requirements:
Need to add
The MFC 4.2 (Visual Studio 6) is easy to implement by simply processing the WM_CTLCOLOR message under the dialog box class, and then the following code:
Copy Code code as follows:
Hbrush Calphaeditboxdlg::onctlcolor (cdc* PDC, cwnd* pwnd, UINT nCtlColor)
{
Hbrush HBR = Cdialog::onctlcolor (PDC, pwnd, nCtlColor);
Todo:change any attributes to the DC here
Pdc->setbkmode (Transparent);
release is not necessarily a matter of concern to them.
Coaching and Mentoring: In most software development projects, coaching and mentoring are often not valued and team members are not getting the support they need. While technical leadership is a guide to the entire project, individuals often need help. In addition, coaching and mentoring provide a way to
that a successful release is not necessarily a matter of concern to them.3. Coaching and Mentoring: in most software development projects, coaching and mentoring are often not valued and team members are not getting the support they need. While technical leadership is a guide to the entire project, individuals often need help. In addition, coaching and mentoring
The MFC class library providesCwnd::OnctlcolorFunction. This member function is called when the child window of the working framework is re-painted.Wm_ctlcolorMessage response function. prototype of this function:Afx_msg hbrush onctlcolor (CDC * PDC, cwnd* Pwnd, uint nctlcolor );
ParametersNctlcolor Used to specify the control type, which can be:. Ctlcolor_btn Button Control. Ctlcolor_dlg Dialog Box. Ctlcolor_Edit Edit box. Ctlcolor_listbox List controls. Ctlcolor_msgbox Message Control.
Recently, when I made a checkbox transparent, I encountered a cbutton re-painting. There were many posts on the Internet about this problem and there were many implementation methods.
Here we will only talk about some problems and solutions I have encountered in actual operations.
1. When the wm_ctlcolor is reloaded in the form to achieve transparency, in some systems that use the XP style, the checkbox has a dark background color and does not really achieve the transparency effect, the specific
OnCtlColorThe specific is:1. Set a background brush in the header file
Public
CBrush M_BRUSHBK;
2, add the following sentence in the OnInitDialog
Todo:add Extra initialization here
CBitmap bmp;
Bmp. LoadBitmap (IDB_BITMAP_TEMPBK);
M_brushbk.createpatternbrush (bmp);
M_brushbk.createsolidbrush (RGB (0,255,0)); Use solid color as background
Bmp. DeleteObject ();
3. Return background brush in OnCtlColor function
Hbrush Cxxxxxdlg::onctlcolor (
Here are three ways to implement the default background color for changing dialog boxes: (1) You can set the background color of the update dialog box in Clotteryapp::initinstance () Call SetDialogBkColor (RGB (160,32,240)) That is, you can change the background color Note that the color drawn here is for all dialog boxes in the program SetDialogBkColor (RGB (0,0,255), RGB (255,0,0)); Previous RGB is the background color, the latter RGB is the text colors (2) You can also clotteryd
respond to the actual request, or a message that needs to be pushed to the client.handle_sync_event ({send_xml,packet},_from,statename, #state {http_receiver= undefined} = statedata)Output= [Packet |Statedata#state.output], Reply=OK, {reply, reply, statename, Statedata#state{output=Output}}; Handle_sync_event ({send_xml, Packet}, _from, StateName, Statedata)-Output= [Packet |Statedata#state.output], Cancel_timer (statedata#state.timer), Timer=Set_inactivity_timer (Statedata#state.pause, stateda
The MFC Class Library provides the Cwnd::onctlcolor function, which is called when the child window of the working frame is redrawn. Therefore, you can overload the response function of the wm_ctlcolor message. The prototype of this function:afx_msg hbrush OnCtlColor (CDC *pdc,cwnd *pwnd,uint nCtlColor);The parameter nctlcolor is used to specify the type of control, which can be:. ctlcolor_btn Button controls. ctlcolor_dlg dialog box. Ctlcolor_ edit box. ctlcolor_listbox List control. ctlcolor_m
Overrider onctlcolor for wm_ctlcolor for your dialog like following to Set background and text color:
E.g.
Hbrush cmydlg: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor){Hbrush HBr = cdialog: onctlcolor (PDC, pwnd, nctlcolor );If (pwnd-> m_hwnd = getdlgitem (idc_text)-> m_hwnd) // use static ID of your static text Control{PDC-> setbkcolor (RGB (255, 0, 0); // red backgroundPDC> settextcolor (RGB (255,255,255); // white textReturn
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.