GDI + Drawing

Source: Internet
Author: User

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

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.