1. Overload onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor), that is, wm_ctlcolor message. ---- ① Add a member variable of cbrush to the header file of cexampledlgdlg: Class cexampledlgdlg: Public cdialog {... Protected: Cbrush m_brush; ... }; ---- ② Add the following to the oninitdialog () function: Code : Bool cexampledlgdlg: oninitdialog () { ... // Todo: add extra initialization here M_brush.createsolidbrush (RGB (0,255, 0); // generate a green brush ... } ---- ③ Use classwizard to overload onctlcolor (...), That is, wm_ctlcolor message: Hbrush cexampledlgdlg: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor) { /* ** No code is required here! ** The downstream code should be commented out. ** Hbrush HBr = cdialog: onctlcolor (PDC, pwnd, nctlcolor ); */ Return m_brush; // Add a green brush } 2. Modify onpaint in the dialog box and add the following code to else: Cpaintdc DC (this ); Crect rect; Getclientrect (rect ); DC. fillsolidrect (rect, RGB (0, 0 )); Cdialog: onpaint (); 3. Add the code to the initinstance () of. cpp of the application class (APP) in the dialog box: // Add int nresponse = DLG. domodal (); Set the background color for the previous RGB image and the font color for the second image. Setdialogbkcolor (RGB (255, 0,255), RGB (, 0 )); 4. 1. Add member variables in the dialog box class: Public: Cbrush m_brushblue;
2. Add the code in oninitdialog () of the dialog box class: M_brushblue.createsolidbrush (RGB (0, 0, 255 ));
3. Use classwizard to add the onctlcollor () member function to the dialog box class and add the code in it: If (nctlcolor = ctlcolor_dlg) Return m_brushblue; |