小小梦想 歌词:Windows程序运行出问题

来源:百度文库 编辑:高考问答 时间:2024/04/27 18:18:13
昨天买了求是科技编著的Windows API程序设计参考大全,但里面有些程序运行时得不到想要的结果,比如下面代码:
case WM_LBUTTONDOWN:
//设置定时器为每秒产生一个WM_TIMER事件
SetTimer(hWnd,WM_TIMER,1000,NULL);
break;
case WM_TIMER://接受定时器发出的消息
//以下只是实现画图,这个没有问题
RECT rect;
int x,y;
//获取窗口的客户区大小
GetClientRect(hWnd,&rect);
radius+=10;
if(radius>150)
{
radius=10;
InvalidateRect(hWnd,&rect,TRUE);
UpdateWindow(hWnd);
}
x=(rect.left+rect.right)/2;
y=(rect.top+rect.bottom)/2;

HPEN hPen,hOldPen;
HDC hDC;
hDC=GetDC(hWnd);
hPen=CreatePen(PS_SOLID,1,RGB(5*radius,10*radius,15*radius));
hOldPen=(HPEN)SelectObject(hDC,hPen);
LineTo(hDC,10,10);
Ellipse(hDC,x-radius,y-radius,x+radius,y+radius);
SelectObject(hDC,hOldPen);
DeleteObject(hPen);
break;
运行后根本就没有画图.