16,466
社区成员
发帖
与我相关
我的任务
分享
#include <Windows.h>
#include <math.h>
#define NUM 1000
#define TWOPI (2 * 3.1415926)
LRESULT CALLBACK Wndproc(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK Wndproc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
static int cxClient ,cyClient;
HDC hdc;
int i ;
PAINTSTRUCT ps;
POINT apt[NUM];
switch(message)
{
case WM_SIZE:
cxClient = LOWORD(lparam);
cyClient = HIWORD(lparam);
break;
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
MoveToEx(hdc,0,cyClient/2 ,NULL);
LineTo(hdc,cxClient,cyClient/2);
for (i = 0 ; i<NUM ;i++)
{
apt[i].x = i* cxClient /NUM;
apt[i].y = (int)(cyClient/2 * (1 - sin(TWOPI * i /NUM)));
}
Polyline(hdc,apt,NUM);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wparam,lparam);
break;
}
return 0;
}
int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )
{
static TCHAR szappname[] = TEXT("hellowin");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
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 = szappname;
if (!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("this program requies windows7!"),szappname,MB_OK);
return 0 ;
}
hwnd = CreateWindow(szappname,TEXT("the hello program"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}