代码改变世界

LineTo画网格

2012-04-03 14:55  youxin  阅读(458)  评论(0编辑  收藏  举报

The following code draws a grid in the client area of a window, spacing the lines 50pixels apart starting from the
upper left corner. The variable hwnd is assumed to be a handle to the window, hdc is a handle to the device
context, and x and y are integers: 

下面的程序代码从窗口的左上角开始,在显示区域中画一个网格,线与线之间相隔50个图素,其中hwnd是窗口句柄,hdc是设备内容句柄,而x和y是整数

 

    int x,y;
RECT rect;
GetClientRect(hwnd,&rect); //该函数获取窗口客户区的坐标,用rect保存
for(x=0;x<rect.right;x+=50)
{
MoveToEx(hDC,x,0,NULL);
LineTo(hDC,x,rect.bottom);
}
for(y=0;y<rect.bottom;y+=50)
{
MoveToEx(hDC,0,y,NULL);
LineTo(hDC,rect.right,y);
}