/////////////////////////////////////////////////////////////////////////////
// CMyView drawingvoid CMyView::OnDraw(CDC* pDC)
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int data[20] = {19, 21, 32, 40, 41, 39, 42, 35, 33, 23, 21, 20, 24, 11, 9, 19, 22, 32, 40, 42};
CRect rc;
GetClientRect(rc); //获取用户区大小
rc.DeflateRect(50, 20); //将矩形大小沿x和y方向各减50
int gridXnums = 10;
int gridYnums = 8;
int dx = rc.Width() / gridXnums;
int dy = rc.Height() / gridYnums; //调整网格矩形的大小
CRect gridRect(rc.left, rc.top, rc.left + dx * gridXnums, rc.top + dy * gridYnums); //绘制网格
CPen gridPen(0, 0, RGB(0, 100, 200));
CPen *oldPen = pDC->SelectObject(&gridPen);
for (int i = 0; i <= gridXnums; i++) //绘制垂直线
{
pDC->MoveTo(gridRect.left + i * dx, gridRect.bottom);
pDC->LineTo(gridRect.left + i * dx, gridRect.top);
}
for (int j = 0; j <= gridYnums; j++) //绘制水平线
{
pDC->MoveTo(gridRect.left, gridRect.top + j * dy);
pDC->LineTo(gridRect.right, gridRect.top + j * dy);
} pDC->SelectObject(oldPen); //恢复原来画笔
gridPen.Detach();
gridPen.CreatePen(0, 0, RGB(0, 0, 200)); //重新创建画笔
pDC->SelectObject(&gridPen);
CBrush gridBrush(RGB(255, 0, 0)); //创建画刷
CBrush * oldBrush = pDC->SelectObject(&gridBrush);
POINT ptRect[4] = {{-3, -3},{-3, 3},{3, 3},{3, -3}};
POINT ptDraw[4];
int deta;
POINT pt[256];
int nCount = 20;
deta = gridRect.Width() / nCount;
for (i = 0; i < nCount; i++)
{
pt[i].x = gridRect.left+ i * deta;
pt[i].y = gridRect.BottomRight - (int)(data[i] / 60 * gridRect.Height); for (j = 0; j < 4; j++)
{
ptDraw[j].x = ptRect[j].x + pt[i].x;
ptDraw[j].y = ptRect[j].y + pt[i].y;
}
pDC->Polygon(ptDraw, 4);
}
pDC->Polyline(pt, nCount); //恢复原来绘图属性
pDC->SelectObject(oldPen);
pDC->SelectObject(oldBrush);
}///////////////////////////////////////////////////////////////
--------------------Configuration: My - Win32 Debug--------------------
Compiling...
MyView.cpp
D:\MY DOCUMENTS\VCWORKS\My\MyView.cpp(102) : error C2297: '*' : illegal, right operand has type 'int (__thiscall CRect::*)(void) const'
Error executing cl.exe.My.exe - 1 error(s), 0 warning(s)

解决方案 »

  1.   

    是不是应该这样
    int x;
    x=变量*变量
    CRect(   ,   , x, )
      

  2.   

    pt[i].y = gridRect.BottomRight - (int)(data[i] / 60 * gridRect.Height);
    这一句错了。gridRect.BottomRight返回的是一个点坐标,而不是一个整数。而且BottomRight是一个函数,因此改为:
    pt[i].y = gridRect.BottomRight().y - (int)(data[i]/60*gridRect.Height());
    就算这样改,程序也有问题。(int)(data[i]/60*gridRect.Height()的结果将始终为0。因为data[i]/60肯定是0。应该改为(int)(data[i]/60.0*gridRect.Height或者(int)(data[i]*gridRect.Height()/60.
    ===========
    pt[i].y = gridRect.BottomRight().y - (int)(data[i]*gridRect.Height()/60);