Dialog box background color setting

zhaozj2021-02-16  51

In front of the yellow base (Guangxi Guilin) ​​- I discussed how to change the color of the control in the "Soft News" 2000, but there is a considerable part of the reader letter: A dialog-based MFC AppWizard application How to change the background color of the dialog box? For this problem, it can actually be implemented by several different methods. The specifically (bolded): ---- Method 1: Call the member function setDialogbkcolor of the CWINAPP class. ---- The first parameter of the function specifies the background color, and the second parameter specifies the text color. The following example is to set the application dialog as a blue background and red text, steps below: ---- 1 New Dialog-based MFC AppWizard application ExampleDLG. ---- 2 Add the following code in Cexampledlgapp :: InitInstance (): Bool CexampledlGapp:: InitInstance () {... CexampledLGDLG DLG; M_PMAINWND = & DLG; // Prevent Domodal () call, set the dialog box to blue background , Red text setDialogbkcolor (RGB (0, 0, 255), RGB (255, 0)); int NRESPONSE = DLG.Domodal (); ...} ---- Compile and run, this time the background color and text of the dialog Color has changed. It is worth noting that SETDIALOGBKCOLOR is called before calling Domodal (), and this method is to change all the dialog boxes in the application, and cannot target a specified dialog box. ---- Method 2: Overload OnPaint (), the WM_PAINT message. The relevant code is as follows: Void Cexampledlgdlg :: onpaint () {if (isiconic ()) ... else {create; cpaintdc dc (this); getClientRect (RECT); DC.FillSolidRect (RECT, RGB) 0,255,0)); // Set to green background cdialog :: onpaint ();} - - method 3: Overload OnctLcolor (CDC * PDC, CWND * PWND, UINT NCTLCOLOR), the WM_CTLCOLOR message.

The specific steps are as follows: ---- 1 In the header file of Cexampledlgdlg, add a CBRUSH member variable: Class Cexampledlgdlg: public cdialog {... protected: cdialog {... protected: cdialog {... protected: cdialog {... --- 2 Add the following code in the OnInitDialog () function: BOOL CEXAMPLDLGDLG :: OnItDialog () {... // Todo: add extra initialization herem_brush.createsolidbrush (RGB (0, 255, 0)); // Generate one Green brush ...} ---- 3 Using ClassWizard to overload onctlcolor (...), ie WM_CTLCOLOR message: Hbrush Cexampledlgdlg :: ONCTLCOLOR (CDC * PDC, CWND * PWND, UINT NCTLCOLOR) {/ *** No need to write any Code! ** Downlink code To comment out ** hbrush hbr = cdialog :: onctlcolor (PDC, PWND, NCTLCOLOR); * / return m_brush; // Return green brush} ---- Method 4: Or ONCTLCOLOR (CDC * PDC, CWND * PWND, UINT NCTLCOLOR, is a WM_CTLCOLOR message. The specific steps are as follows (above the above examples): ---- Step 1, 2 in the upper method three in the method three, 2. ---- Step 3 Some differences when using ClassWizard to overm (...) (ie WM_CTLCOLOR message): Hbrush Cexampledlgdlg :: onCTLCOLOR (CDC * PDC, CWND * PWnd, uint nctlcolor) {Hbrush Hbr = CDIALOG :: ONCTLCOLOR PDC, PWND, NCTLCOLOR); // This adds a judgment statement if this adds a dialog box if (nctlcolor == ctlcolor_dlg) return m_brush; // returns the green brush return Hbr;} ---- compile and run. ---- Regarding how to change the background color of the dialog box, there may be many different ways to achieve, and the author only has four common methods. The programming of the method seems to be a bit less specification. The method is more than the method three, and the contrast of the author is to broaden the programming ideas of VC programming enthusiasts, especially beginners, readers can choose one of them according to the actual situation. . If the "Software Report" 2000 No. 5 Change the color color on the dialog box, it is believed that "color" "color" will "color". The other is

Bool CbpCallView :: OneRaseBkGnd (CDC * PDC) {// can background diagram, painting, etc. // Return CscrollView :: OneRaseBkGnd (PDC);

转载请注明原文地址:https://www.9cbs.com/read-28247.html

New Post(0)