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
Label: C ++ MFC bitmap
Add public to the DLG header file:
Cbrush m_bkbrush;Afx_msg hbrush onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor );
// In oninitdialog ()
Create a yellow background brushM_bkbrush.createsolidbrush (RGB (255,180,100 ));
Set dialog box transparency: Setwindowlong (m_hwnd, gwl_exstyle, getwindowlong (m_hwnd, gwl_exstyle) | ws_ex_layered );: Setlayeredwindowattributes (m_hwnd, 0,200, lwa_alpha); // 120 is the transparency in the range of 0 ~ 255
Edit the
(. (tchar) nchar)
Nchar =: charupper (nchar );
// Bypass default onchar processing and directly call
// Default Window Proc.
Defwindproc (wm_char, nchar, makelparam (nrepcnt, nflags ));
}
44. How to change the color of controls
There are two methods. First, you can specify the color of the control in the parent class, or use the new message reflection of mfc4.0 to specify the color in the control class. When the control needs to be re-colored, The workbox calls the cwnd: oncrtlcolor of the pare
the following code (red background) to OnInitDialog () in the. cpp file of the dialog box:M_brush. CreateSolidBrush (RGB (255,0,0));c) Overload OnCtlColor (cdc* PDC, cwnd* pWnd, UINT nctlcolor), the code is as follows:Hbrush Ctestdlg::onctlcolor (cdc* PDC, cwnd* pWnd, UINT nctlcolor) { = cdialogex::onctlcolor (PDC, PWnd, nCtlColor); // TODO: Change any of the properties of the DC here if Ctlcolor_dlg) return M_brush; // Add Red Brush // TODO: If the defaul
C + + codeCImageList Imglist; Set an image list for CListCtrl to set the row heightImglist.create (IDB_BITMAP4, 1, RGB (255, 255, 255)); IDB_BITMAP4 is 16*16, so it's 16 pixels high.CListCtrl listctrl= (clistctrl) GetListCtrl ();Listctrl.setimagelist (imglist,lvsil_small);I have only used this method at present, there may be other ways, it is more trouble to estimate
Own method Summary
In oninitial:
M_clistresult.setitemheight (0,30);
Hbrush Cate1368manufocusdlg::onctlcolor (cdc* PDC, cwnd* pwnd
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