[求助]程序无错,可是看不到运行结果
是在VC6的Win Appliaction下结果看到的应该是一圆沿着正弦曲线在运动,编译没错,连接时有如下提示
Linking...
LINK : fatal error LNK1168: cannot open Debug/2333.exe for writing
Error executing link.exe.
代码是如下
#include <windows.h>
#include <stdlib.h>
#include <math.h>
#define Pi 3.1415926
long WINAPI WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam);
double dfTheta = 0,dfRange = 100.0;
long i = 0,j = 0;
long lCentreX = 0,lCentreY = 0,lRadious = (long)(0.2*dfRange);
POINT lpSin[100];
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
char lpszClassName[] = "窗口";
WndClass.style = 0;
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("SIN",
"4_6",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
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));
}
while(GetMessage(&Message,0,0,0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
long WINAPI WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam)
{
HDC hDC;
HBRUSH hBrush;
HPEN hPen;
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_DIAGCROSS,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,255));
hBrush = CreateHatchBrush(HS_CROSS,RGB(0,0,255));
lRadious = (long)(dfRange*0.2+i%25*dfRange*0.4/25);
}
else
{
hPen = CreatePen(PS_DASH,1,RGB(255,255,0));
hBrush = CreateHatchBrush(HS_VERTICAL,RGB(255,255,0));
lRadious = (long)(dfRange*0.2+i%25*dfRange*0.4/25);
}
SelectObject(hDC,hBrush);
SelectObject(hDC,hPen);
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(i < 100)
InvalidateRect(hWnd,NULL,1);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return (DefWindowProc(hWnd,iMessage,wParam,lParam));
}
}