程序的源代码
#include<windows.h>
#include<math.h>
#include<stdio.h>
#define MAX_NUM 10000
#define NET  100
#define PI 3.1415926LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(
  HINSTANCE hInstance,  
  HINSTANCE hPrevInstance,  
  LPSTR lpCmdLine,      
  int nCmdShow         
)
 
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[]="line simple";
char lpszTitle[]="Drawing_line simple"; wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=lpszClassName; if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
hwnd=CreateWindow(
               lpszClassName,
                   lpszTitle,
                   WS_OVERLAPPEDWINDOW,
                   CW_USEDEFAULT,
                   CW_USEDEFAULT,
                       CW_USEDEFAULT,
                   CW_USEDEFAULT,
                   NULL,
                   NULL,
                       hInstance,
                   NULL
                  );
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{   
    HDC hdc,
static int cxClient,cyClient;
PAINTSTRUCT ps;
POINT point[MAX_NUM];
static HPEN hpen1,hpen2;
int i;
int x,y;
switch(message)
{
case WM_CREATE:
hpen1=CreatePen(PS_SOLID,3,RGB(0,0,0));
hpen2=CreatePen(PS_SOLID,2,RGB(255,0,0));
break;
case WM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
for(x=cxClient/NET;x<cxClent;x+=cxClient/NET)
{MoveToEx(hdc,x,0,NULL);
LineTo(hdc,x,cyClient);
}
for(y=cyClient/NET;y<cyClient;y=+cyClient/NET)
{MoveToEx(hdc,0,y,NULL);
LineTo(hdc,cxClient,y);
}
SelectObject(hdc,hpen1);
MoveToEx(hdc,0,cyClient/2,NULL);
LineTo(hdc,cxClient,cyClient/2);
SelectObject(hdc,hpen2);
for(i=0;i<MAX_NUM;i++)
{
point[i].x=i*cxClient/MAX_NUM;
    point[i].y=(int)(cyClient/2*(1-sin(PI*2*i/MAX_NUM)));
}
Polyline(hdc,point,MAX_NUM);
SelectObject(hdc,GetStockObject (BLACK_PEN));
EndPaint(hwnd,&ps);
case WM_DESTROY:
DeleteObject(hpen1);
DeleteObject(hpen2);
PostQuitMessage(0);
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return(0);}
这个简单的程序再编译时出现了不少问题,有些还是一样的,
程序编译时的错误:
--------------------Configuration: 基窗口 - Win32 Debug--------------------
Compiling...正弦曲线练习.cpp(72) : warning C4518: 'static int ' : storage-class or type specifier(s) unexpected here; ignored
正弦曲线练习.cpp(72) : warning C4228: nonstandard extension used : qualifiers after comma in declarator list are ignored
正弦曲线练习.cpp(90) : error C2296: '/' : illegal, left operand has type 'struct HDC__ *'
正弦曲线练习.cpp(90) : error C2065: 'cxClent' : undeclared identifier
正弦曲线练习.cpp(90) : error C2296: '/' : illegal, left operand has type 'struct HDC__ *'
正弦曲线练习.cpp(92) : error C2664: 'LineTo' : cannot convert parameter 3 from 'struct HDC__ *' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
正弦曲线练习.cpp(94) : error C2296: '/' : illegal, left operand has type 'struct HDC__ *'
正弦曲线练习.cpp(94) : error C2446: '<' : no conversion from 'struct HDC__ *' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
正弦曲线练习.cpp(94) : error C2040: '<' : 'int' differs in levels of indirection from 'struct HDC__ *'
正弦曲线练习.cpp(94) : error C2296: '/' : illegal, left operand has type 'struct HDC__ *'
正弦曲线练习.cpp(96) : error C2664: 'LineTo' : cannot convert parameter 2 from 'struct HDC__ *' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
正弦曲线练习.cpp(99) : error C2296: '/' : illegal, left operand has type 'struct HDC__ *'
正弦曲线练习.cpp(100) : error C2296: '/' : illegal, left operand has type 'struct HDC__ *'
正弦曲线练习.cpp(100) : error C2664: 'LineTo' : cannot convert parameter 2 from 'struct HDC__ *' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
正弦曲线练习.cpp(104) : error C2297: '*' : illegal, right operand has type 'struct HDC__ *'
正弦曲线练习.cpp(105) : error C2296: '/' : illegal, left operand has type 'struct HDC__ *'
Error executing cl.exe.
查了些资料还是搞不懂!请各位帮帮忙!谢谢!
小弟还有些问题,就是自己学习vc++时,肯定会遇见不少错误,有时就是编译无错,运行时却会出错,很是郁闷!这是怎么回事,是链接出现问题了吗?各位可以提供一些,自己在长期的编程中总结的易发的错误和解决方法,告诉一下吗?
最后感谢浏览和帮助我解决问题的各位,谢谢!!