具体源程序如下(是一个画图型的程序,一个旋转的风车,但是我没有看见过它的运行界面?那位帮帮忙!非常感谢!):
#include "stdafx.h"
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define Pi 3.1415926long WINAPI WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int nNum=0,nMaxNum=20;
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG Message;
HWND hWnd;
WNDCLASS WndClass;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH));
WndClass.hCursor = LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
WndClass.hInstance = hInstance;
WndClass.lpfnWndProc = WndProc;
WndClass.lpszClassName = "icmean";
WndClass.lpszMenuName = NULL;
WndClass.style = 0; if (!RegisterClass(&WndClass))
{
MessageBeep(0);
return FALSE;
}
hWnd = CreateWindow("iceman",
"icmean",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
600,
450,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
while (GetMessage(&Message,0,0,0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
long WINAPI WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
HBRUSH hBrush;
HPEN hPen;
PAINTSTRUCT PtStr;
int nCentreX,nCentreY;
double fAngle; switch (iMessage)
{
case WM_PAINT:
hDC = BeginPaint(hWnd,&PtStr);
SetMapMode(hDC,MM_ANISOTROPIC);
SetWindowExtEx(hDC,400,300,NULL);
SetViewportExtEx(hDC,600,450,NULL);
SetViewportOrgEx(hDC,300,200,NULL);
hPen = (HPEN)GetStockObject(BLACK_PEN);
SelectObject(hDC,hPen);
Ellipse(hDC,-100,-100,100,100); hBrush = CreateSolidBrush(RGB(255,0,0));
SelectObject(hDC,hBrush);
fAngle = 2*Pi/nMaxNum*nNum;
nCentreX = (int)(50*cos(fAngle));
nCentreY = (int)(50*sin(fAngle));
Pie(hDC,nCentreX-50,nCentreY-50,
nCentreX+50,nCentreY+50,
(int)(nCentreX+50*cos(fAngle)),(int)(nCentreY+50*sin(fAngle)),
(int)(nCentreX+50*cos(fAngle+Pi)),(int)(nCentreY+50*sin(fAngle+Pi)));
hBrush = CreateSolidBrush(RGB(255,255,0));
SelectObject(hDC,hBrush);
nCentreX = (int)(50*cos(fAngle+2*Pi/3));
nCentreY = (int)(50*sin(fAngle+2*Pi/3));
Pie(hDC,nCentreX-50,nCentreY-50,
nCentreX+50,nCentreY+50,
(int)(nCentreX+50*cos(fAngle+2*Pi/3)),(int)(nCentreY+50*sin(fAngle+2*Pi/3)),
(int)(nCentreX+50*cos(fAngle+Pi+2*Pi/3)),(int)(nCentreY+50*sin(fAngle+Pi+2*Pi/3)));
hBrush = CreateSolidBrush(RGB(255,255,0));
SelectObject(hDC,hBrush);
nCentreX = (int)(50*cos(fAngle+4*Pi/3));
nCentreY = (int)(50*sin(fAngle+4*Pi/3));
Pie(hDC,nCentreX-50,nCentreY-50,
nCentreX+50,nCentreY+50,
(int)(nCentreX+50*cos(fAngle+4*Pi/3)),(int)(nCentreY+50*sin(fAngle+4*Pi/3)),
(int)(nCentreX+50*cos(fAngle+Pi+4*Pi/3)),(int)(nCentreY+50*sin(fAngle+Pi+4*Pi/3)));
nNum++;
Sleep(100);
InvalidateRect(hWnd,NULL,1);
EndPaint(hWnd,&PtStr);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
}
#include "stdafx.h"
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define Pi 3.1415926long WINAPI WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int nNum=0,nMaxNum=20;
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG Message;
HWND hWnd;
WNDCLASS WndClass;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH));
WndClass.hCursor = LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
WndClass.hInstance = hInstance;
WndClass.lpfnWndProc = WndProc;
WndClass.lpszClassName = "icmean";
WndClass.lpszMenuName = NULL;
WndClass.style = 0; if (!RegisterClass(&WndClass))
{
MessageBeep(0);
return FALSE;
}
hWnd = CreateWindow("iceman",
"icmean",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
600,
450,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
while (GetMessage(&Message,0,0,0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
long WINAPI WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
HBRUSH hBrush;
HPEN hPen;
PAINTSTRUCT PtStr;
int nCentreX,nCentreY;
double fAngle; switch (iMessage)
{
case WM_PAINT:
hDC = BeginPaint(hWnd,&PtStr);
SetMapMode(hDC,MM_ANISOTROPIC);
SetWindowExtEx(hDC,400,300,NULL);
SetViewportExtEx(hDC,600,450,NULL);
SetViewportOrgEx(hDC,300,200,NULL);
hPen = (HPEN)GetStockObject(BLACK_PEN);
SelectObject(hDC,hPen);
Ellipse(hDC,-100,-100,100,100); hBrush = CreateSolidBrush(RGB(255,0,0));
SelectObject(hDC,hBrush);
fAngle = 2*Pi/nMaxNum*nNum;
nCentreX = (int)(50*cos(fAngle));
nCentreY = (int)(50*sin(fAngle));
Pie(hDC,nCentreX-50,nCentreY-50,
nCentreX+50,nCentreY+50,
(int)(nCentreX+50*cos(fAngle)),(int)(nCentreY+50*sin(fAngle)),
(int)(nCentreX+50*cos(fAngle+Pi)),(int)(nCentreY+50*sin(fAngle+Pi)));
hBrush = CreateSolidBrush(RGB(255,255,0));
SelectObject(hDC,hBrush);
nCentreX = (int)(50*cos(fAngle+2*Pi/3));
nCentreY = (int)(50*sin(fAngle+2*Pi/3));
Pie(hDC,nCentreX-50,nCentreY-50,
nCentreX+50,nCentreY+50,
(int)(nCentreX+50*cos(fAngle+2*Pi/3)),(int)(nCentreY+50*sin(fAngle+2*Pi/3)),
(int)(nCentreX+50*cos(fAngle+Pi+2*Pi/3)),(int)(nCentreY+50*sin(fAngle+Pi+2*Pi/3)));
hBrush = CreateSolidBrush(RGB(255,255,0));
SelectObject(hDC,hBrush);
nCentreX = (int)(50*cos(fAngle+4*Pi/3));
nCentreY = (int)(50*sin(fAngle+4*Pi/3));
Pie(hDC,nCentreX-50,nCentreY-50,
nCentreX+50,nCentreY+50,
(int)(nCentreX+50*cos(fAngle+4*Pi/3)),(int)(nCentreY+50*sin(fAngle+4*Pi/3)),
(int)(nCentreX+50*cos(fAngle+Pi+4*Pi/3)),(int)(nCentreY+50*sin(fAngle+Pi+4*Pi/3)));
nNum++;
Sleep(100);
InvalidateRect(hWnd,NULL,1);
EndPaint(hWnd,&PtStr);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
}
if (!hWnd)
{
MessageBox(NULL, "Can't create window!", NULL, 0);
return 1;
}
加再CreateWindow之後, 再把
ShowWindow(hWnd,nCmdShow);
改成
ShowWindow(hWnd,SW_SHOW);
因為你現在不能確定nCmdShow的值
fatal error C1010: unexpected end of file while looking for precompiled header directive
顺便问一句,stdafx.h这个头文件是干什么的?谢谢!