-- 作者:秦汉昌
-- 发布时间:2009/12/25 21:53:00
--
#include <windows.h> #include <math.h>
#define COUNT 5
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { MSG Message; HWND hWnd = NULL; TCHAR szAppName[] = TEXT("MainMenu"); WNDCLASS WndClass;
WndClass.style = CS_HREDRAW| CS_VREDRAW; 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 = szAppName; WndClass.lpszMenuName = szAppName;
if (!RegisterClass(&WndClass)) { MessageBox(hWnd, TEXT("RegisterClass error"), TEXT("Error"), MB_OK); return 0; }
hWnd=CreateWindow(szAppName, TEXT("菜单测试程序"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 400, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow); if( !UpdateWindow(hWnd)) return 0;
while(GetMessage(&Message,0,0,0)) { TranslateMessage(&Message); DispatchMessage(&Message); } return (int)(Message.wParam); }
void InitPos(POINT *pPos) { int i = 0; int r = 100;
for (i=0; i<COUNT; ++i) { (pPos+i)->x = r * cos((((180 - 2 * (360/COUNT))/2) + ((360/COUNT) * i)) / 360.0 * 2 * 3.14); (pPos+i)->y = r * sin((((180 - 2 * (360/COUNT))/2) + ((360/COUNT) * i)) / 360.0 * 2 * 3.14); (pPos+i)->y *= -1; } (pPos+COUNT)->x = (pPos+0)->x; (pPos+COUNT)->y = (pPos+0)->y; }
LRESULT CALLBACK WndProc(HWND hwnd,UINT iMessage,UINT wParam,LONG lParam) { PAINTSTRUCT ps; HDC hdc; static POINT iPos[COUNT+1]; static int cx, cy;
switch(iMessage) { case WM_CREATE:
InitPos(iPos); return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SetMapMode(hdc, MM_TEXT); SetViewportOrgEx(hdc, cx / 2, cy / 2, NULL); Polyline(hdc, iPos, COUNT+1);
EndPaint(hwnd, &ps);
return 0;
case WM_SIZE:
cx = LOWORD(lParam); cy = HIWORD(lParam);
return 0;
case WM_DESTROY: PostQuitMessage(0); return 0;
default: break; } return DefWindowProc(hwnd,iMessage,wParam,lParam); }
此主题相关图片如下:五边形.jpg
|