1, Project Properties "Connector" input additional dependencies, add "' Gdiplus.lib '"
2. Introduction of header Files
1 #include <gdiplus.h>23gdiplus::gdiplusstartupinput m_gdiinput; 4 ulong_ptr M_gditoken;
3. Program entry and end remember to initialize and exit
1 bool cgdiplusdrawapp::initinstance () 2 { // gdi+ initialize 4 Gdiplusstartup (&m_gditoken, &m_gdiinput, NULL); 6 8 10 return FALSE; 11 }
4. Some basic GDI + operations
1 voidCgdiplusdrawdlg::onpaint ()2 {3 if(Isiconic ())4 {5CPAINTDC DC ( This);//device context for drawing6 7SendMessage (Wm_iconerasebkgnd, Reinterpret_cast<wparam> (DC). GETSAFEHDC ()),0);8 9 //Center The icon in the workspace rectangleTen intCxicon =GetSystemMetrics (Sm_cxicon); One intCyicon =GetSystemMetrics (Sm_cyicon); A CRect rect; -GetClientRect (&rect); - intx = (rect. Width ()-Cxicon +1) /2; the inty = (rect. Height ()-Cyicon +1) /2; - - //Draw Icon - DC. DrawIcon (x, y, m_hicon); + } - Else + { A cdialogex::onpaint (); at -CCLIENTDC DC ( This); - gdiplus::graphics Grx (DC. GETSAFEHDC ()); - //Get window client area area - CRect RC; -GetClientRect (&RC); in -Gdiplus::image Image (_t ("Res\\main.png")); toGrx. DrawImage (&image, Gdiplus::rect (Rc.left, Rc.top, RC. Width (), RC. Height ())); + - //Vector Drawing theGdiplus::P en hpen (Gdiplus::color (255,255,0,0)); *Grx. DrawRectangle (&hpen, Gdiplus::rect ( -, -, -, -)); $Grx. DrawArc (&hpen, -, -, -, -,0,Ten);Panax Notoginseng - //painting Brushes theGdiplus::hatchbrush Hatch (gdiplus::hatchstylevertical, Gdiplus::color (255,0,255,0)); +Grx. FillRectangle (&hatch, Gdiplus::rect ( -, -, -, -)); A the //Bitmap Paint brush to draw text +Gdiplus::image Txtimage (_t ("Res\\main.png")); -Gdiplus::texturebrush Tbrush (&txtimage); $Gdiplus::fontfamily Family (_t ("Song Body")); $Gdiplus::font Font (&family, -); -CString Strimag = _t ("bit drawing brush, drawing text"); -Grx. DrawString (LPCTSTR) Strimag, Strimag.getlength (), &font, Gdiplus::P ointf ( -, -), &Tbrush); the - //Gradient Paint BrushWuyiGdiplus::lineargradientbrush Lingrbrush (Gdiplus::P oint (0,0), Gdiplus::P oint (Rc.right, Rc.bottom), Gdiplus::color (255,255,0,0), Gdiplus::color (255,0,0,255)); theGdiplus::color clrs[] = { -Gdiplus::color (255,255,0,0), WuGdiplus::color (255,255,255,0), -Gdiplus::color (255,0,0,255), AboutGdiplus::color (255,0,255,0) $ }; -Gdiplus::real pos[] = { - 0.0f, - 0.33f, A 0.66f, + 1.0f the }; -Lingrbrush. Setinterpolationcolors (clrs, POS,4); $Grx. FillRectangle (&lingrbrush, Gdiplus::rect (Rc.left- -, Rc.top- -, RC. Width ()- +, RC. Height ()- +)); the the Grx. RELEASEHDC (DC. GETSAFEHDC ()); the } the}
GDI + Drawing