我建的项目名称是CPen,我用循环来改变画笔的颜色,宽度和样式,前两个都实现了,但样式却没有改变,请高手指教!!!!
其中onDraw的代码如下
void CCPenView::OnDraw(CDC* pDC)
{
CCPenDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return; // TODO: 在此处为本机数据添加绘制代码
int red = 100;
int green = 0;
int blue = 0;
int width = 2;
int row = 20;
int style[7] = {PS_SOLID,PS_DASH,PS_DOT,PS_DASHDOT,PS_DASHDOTDOT,PS_NULL,PS_INSIDEFRAME};
for (int i=0; i<8; i++)
{
CPen newpen(style[i],width,RGB(red,green,blue));
CPen *oldpen = pDC->SelectObject(&newpen);
pDC->MoveTo(20,row);
pDC->LineTo(300,row);
pDC->SelectObject(oldpen);
red += 5;
green += 10;
blue += 20;
width += 4;
row += 100;
}
}另外想了解一下关于LPCTSTR的知识,VC 6.0中可以这样用pDC->TextOut(10,10,"hello") 但是Visual 2005却要报错,就是地3个参数的问题:
错误 1 error C2664: “BOOL CDC::TextOutW(int,int,LPCTSTR,int)”: 不能将参数 3 从“const char [6]”转换为“LPCTSTR” e:\mfc\wm_paint\wm_paint\wm_paintview.cpp 53
其中onDraw的代码如下
void CCPenView::OnDraw(CDC* pDC)
{
CCPenDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return; // TODO: 在此处为本机数据添加绘制代码
int red = 100;
int green = 0;
int blue = 0;
int width = 2;
int row = 20;
int style[7] = {PS_SOLID,PS_DASH,PS_DOT,PS_DASHDOT,PS_DASHDOTDOT,PS_NULL,PS_INSIDEFRAME};
for (int i=0; i<8; i++)
{
CPen newpen(style[i],width,RGB(red,green,blue));
CPen *oldpen = pDC->SelectObject(&newpen);
pDC->MoveTo(20,row);
pDC->LineTo(300,row);
pDC->SelectObject(oldpen);
red += 5;
green += 10;
blue += 20;
width += 4;
row += 100;
}
}另外想了解一下关于LPCTSTR的知识,VC 6.0中可以这样用pDC->TextOut(10,10,"hello") 但是Visual 2005却要报错,就是地3个参数的问题:
错误 1 error C2664: “BOOL CDC::TextOutW(int,int,LPCTSTR,int)”: 不能将参数 3 从“const char [6]”转换为“LPCTSTR” e:\mfc\wm_paint\wm_paint\wm_paintview.cpp 53
解决方案 »
- 请问复杂表达式能用逆波兰表示么?在线等,谢谢
- 急:菜鸟求助:我的VC++的模板类为什么不能用?
- ◎◎◎◎◎◎◎ 关于TCP服务器端口的问题
- 一些概念问题
- MessageBox和AfxMessageBox有什么区别?
- 请问,调用什么API函数可以进行ARP查询获得某已知IP地址的主机的MAC地址
- 什么是Automation自动化?
- 请教一个关于对话框总在最前显示的问题!就像realplay总在最前显示的问题!谢谢!
- 如何在安装Visual Studio .NET 2003时,如何只安装IDE和C++部分,而不安装服务器组件和.NET?
- 小问题,大分数,必给!
- 全屏状态下,如果显示一个弹出式对话框,就会退出全屏,怎么解决?
- installshield express 如何建立由installscript技术驱动的安装程序?
TextOut(10,10,_T("hello"))
Valid only when the pen width is 1 or less, in device units.意思是只有画笔宽度小于等于1时有效。
PS_DASH Creates a dashed pen. Valid only when the pen width is 1 or less, in device units.PS_DOT Creates a dotted pen. Valid only when the pen width is 1 or less, in device units.PS_DASHDOT Creates a pen with alternating dashes and dots. Valid only when the pen width is 1 or less, in device units.PS_DASHDOTDOT Creates a pen with alternating dashes and double dots. Valid only when the pen width is 1 or less, in device units.
PS_NULL Creates a null pen.PS_INSIDEFRAME Creates a pen that draws a line inside the frame of closed shapes produced by the Windows GDI output functions that specify a bounding rectangle (for example, the Ellipse, Rectangle, RoundRect, Pie, and Chord member functions). When this style is used with Windows GDI output functions that do not specify a bounding rectangle (for example, the LineTo member function), the drawing area of the pen is not limited by a frame