/*-----------------------------
BEZIER.C -- Bezier Splines Demo
(c) Charles Petzold, 1998
-----------------------------*/ #include <Windows.h> LRESULT CALLBACK WndPorc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain( __in HINSTANCE hInstance
, __in_opt HINSTANCE hPrevInstance
, __in LPSTR lpCmdLine
, __in int nShowCmd )
{
static TCHAR szAppName[] = TEXT("Bezier");
HWND hwnd;
MSG msg;
WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndPorc;
wndclass.cbClsExtra = ;
wndclass.cbWndExtra = ;
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("Program requires Windows NT!")
, szAppName, MB_ICONERROR);
return ;
} hwnd = CreateWindow(szAppName, TEXT("Bezier Splines")
, WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT, CW_USEDEFAULT
, CW_USEDEFAULT, CW_USEDEFAULT
, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, nShowCmd);
UpdateWindow(hwnd); while (GetMessage(&msg, NULL, , ))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} return msg.wParam;
} void DrawBezier(HDC hdc, POINT apt[])
{
PolyBezier(hdc, apt, ); MoveToEx(hdc, apt[].x, apt[].y, NULL);
LineTo(hdc, apt[].x, apt[].y); MoveToEx(hdc, apt[].x, apt[].y, NULL);
LineTo(hdc, apt[].x, apt[].y);
} LRESULT CALLBACK WndPorc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static POINT apt[];
HDC hdc;
int cxClient, cyClient;
PAINTSTRUCT ps; switch (message)
{
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam); apt[].x = cxClient / ;
apt[].y = cyClient / ; apt[].x = cxClient / ;
apt[].y = cyClient / ; apt[].x = cxClient / ;
apt[].y = * cyClient / ; apt[].x = * cxClient / ;
apt[].y = cyClient / ; return ; case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MOUSEMOVE:
if (wParam & MK_LBUTTON || wParam & MK_RBUTTON)
{
hdc = GetDC(hwnd);
SelectObject(hdc, GetStockObject(WHITE_PEN)); DrawBezier(hdc, apt); if (wParam & MK_LBUTTON)
{
apt[].x = LOWORD(lParam);
apt[].y = HIWORD(lParam);
} if (wParam & MK_RBUTTON)
{
apt[].x = LOWORD(lParam);
apt[].y = HIWORD(lParam);
} SelectObject(hdc, GetStockObject(BLACK_PEN)); DrawBezier(hdc, apt); ReleaseDC(hwnd, hdc);
}
return ; case WM_PAINT:
InvalidateRect(hwnd, NULL, TRUE);
hdc = BeginPaint(hwnd, &ps); DrawBezier(hdc, apt); EndPaint(hwnd, &ps);
return ; case WM_DESTROY:
PostQuitMessage();
return ;
} return DefWindowProc(hwnd, message, wParam, lParam);
}
BEZIER.C
BEZIER程序的显示结果