菜鸟问题,求大神解决~~~~~~
编了一个创建窗口的程序,编译能通过,但是在运行时窗口一闪而过!!!自己想了一个很笨得方法,用sleep函数,能延迟一会,但是还是达不到自己想要的效果!
代码是:#include<windows.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define PI 3.1415926535898
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
POINT pt[5][3];
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG Message;
HWND hWnd;
WNDCLASS WndClass;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL,IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH));
WndClass.hInstance = hInstance;
WndClass.lpfnWndProc = WndProc;
WndClass.lpszClassName = "Pentagon";
WndClass.lpszMenuName = NULL;
WndClass.style = 0;
if(!RegisterClass(&WndClass))
{
MessageBeep(0);
return FALSE;
}
hWnd = CreateWindow("Pentagon",
"五边形",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
NULL,
NULL,
hInstance,
NULL);
pt[0][0].x = 400; //第一块区域相关的坐标
pt[0][0].y = 200 - (long)50 / (cos(PI / 5));
pt[0][1].x = 400 - (long)((50 / cos(PI / 5)) * cos(PI / 10));
pt[0][1].y = 200 - (long)(50 / cos(PI / 5) * sin(PI / 10));
pt[0][2].x = 400;
pt[0][2].y = 200;
pt[1][0].x = 400 - (long)((50 / cos(PI / 5)) * cos(PI / 10)); //第二块区域相关的坐标
pt[1][0].y = 200 - (long)(50 / cos(PI / 5) * sin(PI / 10));
pt[1][1].x = 400 - (long)(50 * tan(PI / 5));
pt[1][1].y = 250;
pt[1][2].x = 400;
pt[1][2].y = 200;
pt[2][0].x = 400 - (long)(50 * tan(PI / 5)); //第三块区域相关的坐标
pt[2][0].y = 250;
pt[2][1].x = 400 + (long)(50 * tan(PI / 5));
pt[2][1].y = 250;
pt[2][2].x = 400;
pt[2][2].y = 200;
pt[3][0].x = 400 + (long)(50 * tan(PI / 5)); //第四块区域相关的坐标
pt[3][0].y = 250;
pt[3][1].x = 400 + (long)((50 / cos(PI / 5)) * cos(PI / 10));
pt[3][1].y = 200 - (long)(50 / cos(PI / 5) * sin(PI / 10));
pt[3][2].x = 400;
pt[3][2].y = 200;
pt[4][0].x = 400 + (long)((50 / cos(PI / 5)) * cos(PI / 10)); //第五块区域相关的坐标
pt[4][0].y = 200 - (long)(50 / cos(PI / 5) * sin(PI / 10));
pt[4][1].x = 400;
pt[4][1].y = 200 - (long)50 / (cos(PI / 5));
pt[4][2].x = 400;
pt[4][2].y = 200;
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,
UINT wParam,
LONG lParam)
{
HDC hDC;
HBRUSH hBrush;
HPEN hPen;
PAINTSTRUCT PtStr;
switch(iMessage)
{
case WM_PAINT:
hDC = BeginPaint(hWnd, &PtStr);
hPen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0)); //绘制红色的边
hBrush = CreateSolidBrush(RGB(0, 255, 0)); //使用绿色画刷填充
SelectObject(hDC, hPen);
SelectObject(hDC, hBrush);
Polyline(hDC, pt[0], 3);
Polygon(hDC, pt[0], 3);
DeleteObject(hPen); //绘制红色的边结束,释放画笔
hPen = CreatePen(PS_SOLID, 1, RGB(0, 255, 0)); //绘制绿色的边
hBrush = CreateSolidBrush(RGB(255, 255, 0)); //使用黄色画刷填充
SelectObject(hDC, hPen);
SelectObject(hDC, hBrush);
Polyline(hDC, pt[1], 3);
Polygon(hDC, pt[1], 3);
DeleteObject(hPen); //绘制绿色的边结束,释放画笔
hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 255)); //绘制蓝色的边
hBrush = CreateSolidBrush(RGB(255, 0, 0)); //使用红色画刷填充
SelectObject(hDC, hPen);
SelectObject(hDC, hBrush);
Polyline(hDC, pt[2], 3);
Polygon(hDC, pt[2], 3);
DeleteObject(hPen); //绘制蓝色的边结束,释放画笔
hPen = CreatePen(PS_SOLID, 1, RGB(255, 0, 255)); //绘制紫色的边
hBrush = CreateSolidBrush(RGB(0, 0, 255)); //使用蓝色画刷填充
SelectObject(hDC, hPen);
SelectObject(hDC, hBrush);
Polyline(hDC, pt[3], 3);
Polygon(hDC, pt[3], 3);
DeleteObject(hPen); //绘制紫色的边结束,释放画笔
hPen = CreatePen(PS_SOLID, 1, RGB(0, 255, 255)); //绘制青色的边
hBrush = CreateSolidBrush(RGB(255, 0, 255)); //使用紫色画刷填充
SelectObject(hDC, hPen);
SelectObject(hDC, hBrush);
Polyline(hDC, pt[4], 3);
Polygon(hDC, pt[4], 3);
DeleteObject(hPen); //绘制青色的边结束,释放画笔
EndPaint(hWnd, &PtStr);
Sleep(10000);
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return(DefWindowProc(hWnd, iMessage, wParam, lParam));
}
}
期待大神们给力的解答~~~