Six ways to draw brushes (hbrush) 2009- -- at the: 00HBRUSH HBR; the first type: HBR= CreateSolidBrush (RGB (255,0,0));//Monochrome Paint BrushThe second kind: hbr= (hbrush) getstockobject (Black_brush);//can only take a specific color of the brush, such as Black_brush,gray_brush brushThe Third Kind: hbr= CreatePatternBrush (Hbitmap hbmp);//get a bit drawing brushFourth type: HBR = Createhatchbrush (intFnstyle, COLORREF Clrref)//Create a shaded paint brushFifth type: hbr= createbrushindirect (Logbrush);//drawing Brushes by Logbrush structure bodytypedefstructTaglogbrush {UINT lbstyle;//Paint Brush TypeCOLORREF Lbcolor;//ColorLONG Lbhatch;//Shadows} logbrush, *Plogbrush; The sixth type: HBR= Hbrush CreateDIBPatternBrush (//Create a brush with a device-independent bitmapHglobal hglbdibpacked,//Handle to DIBUINT Fucolorspec//Color Table Data); For example: Hbrush cafdview::onctlcolor (CDC* PDC, cwnd*pWnd, UINT nCtlColor) {Hbrush HBR=Cformview::onctlcolor (PDC, PWnd, nCtlColor);//todo:change Any attributes of the DCif(Pwnd->getdlgctrlid () = =Idc_static1) {PDC->settextcolor (RGB ( $,0,0));pD C->setbkcolor (RGB (0,0,255));StaticHbrush hbrush = CreateSolidBrush (RGB (222,0,255));returnHbrush;}//Todo:return A different brush if the default is not desiredElse returnHBR;} Change dialog box background color hbrush cdqfdlg::onctlcolor (CDC* PDC, cwnd*pWnd, UINT nCtlColor) {Hbrush HBR=Cdialog::onctlcolor (PDC, PWnd, nCtlColor);//todo:change Any attributes of the DC//Todo:return A different brush if the default is not desiredif(nCtlColor = =Ctlcolor_dlg) {CBrush*Brush;brush=NewCBrush (RGB (221,221,221));return(Hbrush) (brush->m_hobject);}returnHBR;}
The first method and the second method are self-tested and can be used, followed by no tests.
The method of drawing brush of Win32