window API的函数 RectangleThe Rectangle function draws a rectangle. The rectangle is outlined by using the current pen and filled by using the current brush. BOOL Rectangle(    HDC hdc, // handle of device context 
    int nLeftRect, // x-coord. of bounding rectangle's upper-left corner 
    int nTopRect, // y-coord. of bounding rectangle's upper-left corner 
    int nRightRect, // x-coord. of bounding rectangle's lower-right corner  
    int nBottomRect  // y-coord. of bounding rectangle's lower-right corner  
   );
 ParametershdcIdentifies the device context. nLeftRectSpecifies the logical x-coordinate of the upper-left corner of the rectangle. nTopRectSpecifies the logical y-coordinate of the upper-left corner of the rectangle. nRightRectSpecifies the logical x-coordinate of the lower-right corner of the rectangle. nBottomRectSpecifies the logical y-coordinate of the lower-right corner of the rectangle.  Return ValuesIf the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError. ResThe current position is neither used nor updated by Rectangle. 

解决方案 »

  1.   

    你是要源程序? 去查一下计算机图形学方面的书.
    通常先用Bresenham算法实现画直线函数,
    对矩形的填充还是很简单的吧.
      

  2.   

    Why don't you use CDC?
      

  3.   

    不好意思,CDC是什么?谢谢各位朋友的关心
      

  4.   

    你不是用VC的吗?
    CDC是MFC的一个专用于绘图的类,它基于Windows的Device context(关联设备),封
    装了许多绘图用WIndows API,还提供了一些比较复杂的绘图方法,如画B样曲线等。
    在MFC的窗口中,你可以用GetDC等有关DC的函数取得窗口关联的CDC对象,然后就可以
    使用CDC提供的功能强大的(对一般应用而言^_^)绘图方法了。
    有一点要注意的是,CDC的使用有一定的规则,你可以参考一下MSDN中的说明,而且
    MSDN中有许多有关的例子可以看一下。
    如果你不用MFC的话,就只有用Windows API了。首先你要取得你的窗口句柄hWnd,然
    后用GetDC或GetDCEx取得关联设备hDC,就可以用Rectangle来画矩形了。
    颜色的填充只需要改变画刷的颜色就可以了。