VS2010 用GDI+编程为什么using System.Drawing;提示system未定义呢?RectangleF tmprect;提示RectangleF是否是因为system.drawing不行的关系?

解决方案 »

  1.   


    [code=C/C++]
    #include "stdafx.h"
    #include <string>
    #include <windows.h>
    #include <objidl.h>
    #include <gdiplus.h>
    #include<afxwin.h>
    using namespace Gdiplus;
    using namespace std;
    //using System.Drawing;
    #pragma comment (lib,"Gdiplus.lib")class workman
    {
    public:
    workman(void);
    ~workman(void);int workman::display(CDC* pDC) {/* 设定要显示笔顺的汉字、字体、字号、起始位置、显示部件的间隔等参数*/ WCHAR* str=L"我";
    WCHAR* fname=L"楷体_GB2312 ";                                    
          
    int fsize= 32;
        int x=0; 
    int y=0; 
    int spx=5; 
    int spy=5; 
    int dx=0; 
    int dy=0;
    int order[7];//设定控制笔画(子路径)显示次序的数组order
        
    order[ 0 ] = 1; order[ 1] = 3; order[ 2 ] = 2; order[ 3] = 6;
        order[ 4 ] = 4; order[ 5] = 7; order[ 6] = 5;//设定绘制汉字轮廓、矩形边框(田字格)及填充的颜色    Pen tmppen1(Color Red);
    Pen tmppen2(Color Blue);
    Pen tmppen3(Color Green);

        SolidBrush tmpbrush( Color Blue);/* 通过窗口句柄构建GDI+ 绘图对象graphics, 并设定字体的坐标单位, 保证绘制精度*/

        Graphics graphics(pDC->m_hDC);
        FontFamily  tmpfontFamily(fname);
        Font tmpfont(& tmpfontFamily, fsize, FontStyleRegular) ;
        Unit unit=tmpfont.GetUnit( );
        graphics.SetPageUnit( unit) ;
        graphics.SetSmoothingMode(SmoothingModeHighQuality) ;//构建对应汉字字形轮廓的路径对象tmppath   GraphicsPath tmppath;
       tmppath.AddString(str,-1,&tmpfontFamily,FontStyleRegular,fsize,PointF(x,y),NULL) ;/* 基于汉字路径对象tmppath 来构建路径迭代器对象iterator, 用于管理其中的子路径*/   GraphicsPathIterator iterator(&tmppath);/* 获取路径的外接矩形数据用于绘制汉字的背景矩形(或田字格)*/   RectangleF tmprect;            //此处报错,为何?
       tmppath.GetBounds(&tmprect);
       hcx1= tmprect.GetLeft();
       hcy1 =(tmprect.GetTop()+tmprect.GetBottom())/2;
       hcx2= tmprect.GetRight( ) ; 
       hcy2= hcy1;
       vcx1= (tmprect.GetLeft( ) + tmprect.GetRight ( ) ) /2;
       vcy1 = tmprect. GetTop( ) ;
       vcx2= vcx1;
       vcy2 = tmprect.GetBottom ( );
       dx= tmprect.Width + spx; //设置笔顺序列每步水平移动的间距   //获取汉字路径中的子路径总数, 即笔画数    INT count= iterator.GetSubpathCount( ) ;   //按每步只显示一笔的方式显示汉字的笔顺序列   GraphicsPath subpath;
       
       for( int i=0;i<count;i++)
       { 
       //绘制汉字的背景矩形(或田字格)
      tmppen3.SetDashStyle(DashStyleSolid) ;
      

  2.   

    如果将using System.Drawing反注释同样报错,说System未定义,本人为菜鸟,实不知为何,求指点
      

  3.   

    试一试在解决提方案的引用中添加system.drawing这一项,或者在加入system.drawing.design,应该可以解决的
      

  4.   

    你用的是vs201阿,我电脑没装呵,不过问题大概就出在这地方,在百度下吧,找下2010的引用在哪,我用的是vs2008呵,
      

  5.   

    PROJECT-ADD REFERENCE
    System.Drawing
      

  6.   

    拜托……你这程序是典型的C++的MFC程序(包含了afxwin.h)。那么就必须按照纯正的C++编程方法,不能使用using System.Drawing这种C#或者C++.NET的语法。#include <gdiplus.h>
    using namespace Gdiplus;
    #pragma comment (lib,"Gdiplus.lib")这三句已经保证了可以使用GDI+的C++接口了。
      

  7.   

    using System.Drawing;应该是C#或者使用.NET托管的C++时才用的,那样的话,你就不需要afxwin.h、windows.h、gdiplus.h这些头文件,也不需要using namespace std了。