问题描述
- 刚刚抄的一个c++画图程序,编译通过无法运行,感谢各位指教,虚心学习
-
#include
#include
#include
#include
#define pi 3.1415926long WINAPI WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam);
bool InitWindowsClass(HINSTANCE hIntance);
bool InitWindows(HINSTANCE hInstance,int nCmdShow);double deTheta=0,dfRange=100.0;//正弦曲线的角度变量
long i=0,j=0;
long lCentreX=0,lCenterY=0,lRadious=(long)(0.2*dfRange);
POINT lpSin[100];
HWND hWndMain;int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{MSG Message;
if(!InitWindowsClass(hInstance))
return FALSE;
if(!InitWindows(hInstance,nCmdShow))
return FALSE;
//..........消息循环
while(GetMessage(&Message,0,0,0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}//............消息循环}
return Message.wParam;
}//......定义WinProc函数........
long WINAPI WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam)
{
HDC hDC;//定义设备环境句柄
HBRUSH hBrush;
HPEN hPen;
for(int j=0;j<100;j++)
{
lpSin[j].x=(long)(j*2*pi/100*60);
lpSin[j].y=(long)(dfRange*sin(j*2*pi/100));
}
PAINTSTRUCT PtStr;//定义包含绘图信息的结构体变量
switch(iMessage)
{
case WM_PAINT:{ //处理绘图信息
hDC=BeginPaint(hWnd,&PtStr);//获取设备环境指针
SetWindowOrgEx(hDC,-200,-200,NULL);//设置原点
hPen=CreatePen(PS_DASH,1,RGB(255,0,0));
SelectObject(hDC,hPen);
Polyline(hDC,lpSin,100);//绘制正弦曲线
//第一个四分之一周期
if(i<=25)
{
hPen=CreatePen(PS_DASH,1,RGB(255,0,0));
hBrush=CreateHatchBrush(HS_BDIAGONAL,RGB(255,0,0));
lRadious=(long)(dfRange*0.2+i%25*dfRange*0.4/25);
}
//第二个四分之一周期
else if(i<=50)
{
hPen=CreatePen(PS_DASH,1,RGB(0,255,0));
hBrush=CreateHatchBrush(HS_BDIAGONAL,RGB(0,255,0));
lRadious=(long)(dfRange*0.2+i%25*dfRange*0.4/25);
}
//第三个四分之一周期
else if(i<=75)
{
hPen=CreatePen(PS_DASH,1,RGB(0,0,225));
hBrush=CreateHatchBrush(HS_BDIAGONAL,RGB(0,0,225));
lRadious=(long)(dfRange*0.2+i%25*dfRange*0.4/25);
}
//第四个周期
else if(i<=100)
{
hPen=CreatePen(PS_DASH,1,RGB(255,255,0));
hBrush=CreateHatchBrush(HS_BDIAGONAL,RGB(255,255,0));
lRadious=(long)(dfRange*0.2+i%25*dfRange*0.4/25);
}
SelectObject(hDC,hBrush);//选入画刷
SelectObject(hDC,hPen);
long lCentreX=0,lCentreY=0;
lCentreX=lpSin[i].x;
lCentreY=lpSin[i].y;
Ellipse(hDC,lCentreX-lRadious,lCentreY-lRadious,lCentreX+lRadious,lCentreY+lRadious);//画图
i++;
DeleteObject(hPen);
DeleteObject(hBrush);
EndPaint(hWnd,&PtStr);//删除设备指针
Sleep(100);
if(1<100)InvalidateRect(hWnd,NULL,1);//刷新用户区
return 0;
}
case WM_DESTROY:{
PostQuitMessage(0);
return 0;
}
default:
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}}bool InitWindows(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;
hWnd=CreateWindow("WinFill","填充程序",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);
if(!hWnd)
return FALSE;
hWndMain=hWnd;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return true;
}
bool InitWindowsClass(HINSTANCE hInstance) //定义窗口类
{WNDCLASS WndClass;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)(GetStockObject(WHITE_BRUSH));
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,"END");
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=WndProc;
WndClass.lpszClassName="WinFill";
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW|CS_VREDRAW;
return RegisterClass(&WndClass);
}