我建的项目名称是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

解决方案 »

  1.   

    改成如下试试:
    TextOut(10,10,_T("hello")) 
      

  2.   

    msdn中:
    Valid only when the pen width is 1 or less, in device units.意思是只有画笔宽度小于等于1时有效。
      

  3.   

    同意
    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
      

  4.   

    PS_NULL有效,其它不满足条件,且style[i]存在越界(i ==7)