求指点CString strNum;
Font font(L"宋体", 10);
strNum = L"0";
graph.DrawString(strNum, -1, &font,
PointF(8, 290), &SolidBrush(Color::Black)); for (int i = 0; i < 256; i += 5)
{
if (i % 50 == 0)
graph.DrawLine(&Pen(Color::Black), 10 + i, 280, 10 + i, 286);
else if (i % 10 == 0)
graph.DrawLine(&Pen(Color::Black), 10 + i, 280, 10 + i, 283);
}
报错:
C:\Users\colefet\Desktop\文件\毕设\image\image\HistogramDlg.cpp(197) : error C2065: 'Font' : undeclared identifier
C:\Users\colefet\Desktop\文件\毕设\image\image\HistogramDlg.cpp(197) : error C2146: syntax error : missing ';' before identifier 'font'
C:\Users\colefet\Desktop\文件\毕设\image\image\HistogramDlg.cpp(197) : error C2065: 'font' : undeclared identifier
C:\Users\colefet\Desktop\文件\毕设\image\image\HistogramDlg.cpp(199) : error C2228: left of '.DrawString' must have class/struct/union type
C:\Users\colefet\Desktop\文件\毕设\image\image\HistogramDlg.cpp(200) : error C2065: 'PointF' : undeclared identifier
C:\Users\colefet\Desktop\文件\毕设\image\image\HistogramDlg.cpp(200) : error C2653: 'Color' : is not a class or namespace name
C:\Users\colefet\Desktop\文件\毕设\image\image\HistogramDlg.cpp(205) : error C2228: left of '.DrawLine' must have class/struct/union typeMFC类GDI双环重绘图
Font font(L"宋体", 10);
strNum = L"0";
graph.DrawString(strNum, -1, &font,
PointF(8, 290), &SolidBrush(Color::Black)); for (int i = 0; i < 256; i += 5)
{
if (i % 50 == 0)
graph.DrawLine(&Pen(Color::Black), 10 + i, 280, 10 + i, 286);
else if (i % 10 == 0)
graph.DrawLine(&Pen(Color::Black), 10 + i, 280, 10 + i, 283);
}
报错:
C:\Users\colefet\Desktop\文件\毕设\image\image\HistogramDlg.cpp(197) : error C2065: 'Font' : undeclared identifier
C:\Users\colefet\Desktop\文件\毕设\image\image\HistogramDlg.cpp(197) : error C2146: syntax error : missing ';' before identifier 'font'
C:\Users\colefet\Desktop\文件\毕设\image\image\HistogramDlg.cpp(197) : error C2065: 'font' : undeclared identifier
C:\Users\colefet\Desktop\文件\毕设\image\image\HistogramDlg.cpp(199) : error C2228: left of '.DrawString' must have class/struct/union type
C:\Users\colefet\Desktop\文件\毕设\image\image\HistogramDlg.cpp(200) : error C2065: 'PointF' : undeclared identifier
C:\Users\colefet\Desktop\文件\毕设\image\image\HistogramDlg.cpp(200) : error C2653: 'Color' : is not a class or namespace name
C:\Users\colefet\Desktop\文件\毕设\image\image\HistogramDlg.cpp(205) : error C2228: left of '.DrawLine' must have class/struct/union typeMFC类GDI双环重绘图
这个我大小写都试过了 直接是没有, 打不开C:\Users\colefet\Desktop\文件\毕设\image\image\HistogramDlg.cpp(10) : fatal error C1083: Cannot open include file: 'Gdip.h': No such file or directory
应该不是这个原因吧,我试了一下没有改变
一开始我以为是要引进某库,
网上馊的几个头文件我都导过了,一般是cannot open
我用的VC6已经配置过GDI+的库了
我用的VC6已经配置过GDI+的库了
那就是 路径设置有问题了。百度搜一下
我用的VC6已经配置过GDI+的库了
那就是 路径设置有问题了。百度搜一下
额,今天晚上照着百度文库里的MFC配置GDI+折腾了一整个晚上,貌似也不是这个问题
目测最根本的问题还是这个:error C2065: 'Graphics' : undeclared identifier
根本识别不出来。。
using namespace Gdiplus;不仅得包含头文件,还得引入Gdiplus的名字空间
调试了2天
error C2664: 'enum Gdiplus::Status __thiscall Gdiplus::Graphics::DrawString(const unsigned short *,int,const class Gdiplus::Font *,const class Gdiplus::PointF &,const class Gdiplus::Brush *)' : cannot convert parameter 1 from 'class CString' to 'const unsigned short *' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called没看到过这种格式的DrawString()函数啊,这是库的问题还是什么呢?换了一个包也没用。
#define ULONG_PTR ULONG
#include <afxdtctl.h> //此处必须添加,否则出错
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib") #include <comdef.h>//初始化一下com口
#ifndef ULONG_PTR
#define ULONG_PTR unsigned long*
#include "GdiPlus.h"
using namespace Gdiplus;
#endif这两段都试一下。第二个问题19楼的方法应该也是对的,不过这个已经解决了。
“主要是UNICODE和ANSI的问题,CString可以是unsigned short*,也可以是char *,关键是编译时是否指定了_UNICODE选项”
解决办法:
从主菜单中选择“Project | Settings”打开工程设置对话框 => 然后选择“C/C++”标签 => 在“Preprocessor definitions”编辑框中添加 UNICODE 或者 _UNICODE 预处理宏指令。