Https://msdn.microsoft.com/en-us/library/eeah46xd.aspxTurn from://http://blog.csdn.net/zhuce0001/article/details/9152515.In a dialog-based program, one task is to change the background of the edit box control.The implementation of the idea is as follows, when the child control to draw will be sent to the parent class (here is the main window) wm_ctlcolorMessage, in the parent class (here is the main window) in response to Wm_ctlcolor, according to the message passed over theParameters for the co
, the WM_CTLCOLOR and Ctlcolor functions are mapped in the control class. Add the WM_CTLCOLOR message response function in the main window, with a very familiar sentence:Hbrush HBR = Cdialog::onctlcolor (PDC, PWnd, nCtlColor);This sentence is based on the child window (or child control, nCtlColor to specify) whether there is a ctlcolor, to decide whether to execute the ctlcolor of the child window, you can debug the next step. In addition, csdn a good
Take static text for example to share how to modify text font, size, color, background and other parameters. Other text, controls, etc. can be modified by reference.1. Modify font, sizeThis is simple, first declare a member variable of type CFont in the Dlg class:Then add the following two lines of code to the class's initialization function, OnInitDialog ():1 // set the static text font size 2 M_editfont.createpointfont (_t (" song body ")); 3 M_static.setfont (m_editfont);2. Change
original link: http://blog.sina.com.cn/s/blog_4a470fcc01000406.htmlThere are some mistakes in this article, but the idea is worth drawing on.If you create a CStatic object X in a colored form, and the X changes its text content, then there is an X background that is the default form background, not the background of the color form, because SetWindowText will onerasebkgnd erase the background of the original interface, and then call the default OnPaint to draw the window's default form color. The
How to modify the font size and color (finishing) of the text in CEdit to process the WM_CTRLCOLOR message in the heavy load dialog box.
In the following example, m_edit is a text box object (a member of the dialog box ).
HBRUSH CTestDlg: OnCtlColor (CDC * pDC, CWnd * pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog: OnCtlColor (pDC, pWnd, nCtlColor );
// TODO: Change any attributes of the DC here
If (pWnd = m_edit)
{
PDC-> SetBkMode (TRANSPARENT );
PDC-
prevails ):
Void cexampledlgdlg: onpaint (){If (isiconic ())...Else{Crect rect;Cpaintdc DC (this );Getclientrect (rect );DC. fillsolidrect (rect, RGB (0,255, 0); // set it to a green background
Cdialog: onpaint ();}
Method 3: overload onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor), that is, wm_ctlcolor message. The specific steps are as follows (the above project prevails ):
① In the header file of cexampledlgdlg, add a member variable of cbrush:
Class cexampledlgdlg: Public cdialog{...Pro
structure and defines a color. The rgbquad structure is defined as follows:Typedef struct tagrgbquad {
Bytergbblue; // blue brightness (value range: 0-255)Bytergbgreen; // The brightness of the green color (value range: 0-255)Bytergbred; // The Red brightness (value range: 0-255)Bytergbreserved; // reserved, must be 0} Rgbquad;The number of rgbquad structure data in the color table is determined by bibitcount:When bibitcount is 1, 4, and 8, there are 2, 16, and 256 table items respectively;When
dialog file and set the ID to idc_edit1 and idc_edit2.
Method 1 (corresponding to idc_edit1): according to standard windows programming, the message processing function of its parent window is responsible for processing wm_ctlcolor messages.
1. Add a data member in caboutdlg: hbrush m_brmine;2. Map the wm_ctlcolor message of aboutdlg using the Wizard to generate the function: hbrush caboutdlg: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor );PDC is the device context of aboutdlg, pwnd is th
transparency in onctlcolor. You need to change the font color of the edit control here.
Hbrush ctestdlg: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor){Hbrush HBr = cdialog: onctlcolor (PDC, pwnd, nctlcolor );
If (nctlcolor = ctlcolor_edit) (pwnd-> getdlgctrlid () = idc_edit )){PDC-> setbkmode (transparent); // set the background to transparent. In this way, when the characters are output// It is a so-called hollow word, rather than a white bac
(CDC * PDC, cwnd * pwnd, uint nctlcolor), that is, wm_ctlcolor message. The specific steps are as follows (the above project prevails ):---- Steps ① and ② are the steps ① and ② above in method 3.
---- Step ③ use classwizard to reload onCtlcolor (...) (Wm_ctlcolor message) is somewhat different:
Hbrush cexampledlgdlg: OnCtlcolor(CDC * PDC, cwnd * pwnd, uint nctlcolor){Hbrush HBr = cdialog: OnCtlcolor (PDC, pwnd, nctlcolor );
// Add a judgment statemen
[Program Implementation]Suppose you already have a dialog box project named my. There is an edit control with ID = idc_edit1.Class cmydlg: Public cdialog{Public:Cfont m_font;........};Bool ctmydlg: oninitdialog (){Cdialog: oninitdialog ();
// Todo: add extra initialization here// Cfont m_font;M_font.createfont (-11, 0, 0, 100, false, false, 0, ansi_charset, out_default_precis, clip_default_precis, default_quality, ff_swiss, "Arial ");Cedit * m_edit = (cedit *) getdlgitem (idc_edit1 );M_edit-> se
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.