1 定义全局变量
static POINT pt[4]; //存储贝塞尔曲线的四个点
2 消息处理
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);// TODO: 在此添加任意绘图代码...
PolyBezier(hdc,pt,4);
MoveToEx(hdc,pt[0].x,pt[0].y,NULL);
LineTo(hdc,pt[1].x,pt[1].y);
MoveToEx(hdc,pt[2].x,pt[2].y,NULL);
LineTo(hdc,pt[3].x,pt[3].y);
EndPaint(hWnd, &ps);
break;
case WM_CREATE:
return 0 ;
case WM_LBUTTONDOWN: //左键按下
pt[1].x=LOWORD(lParam);
pt[1].y=HIWORD(lParam);
InvalidateRect(hwnd,NULL,TRUE);
return 0 ;
case WM_RBUTTONDOWN: //右键按下
pt[2].x=LOWORD(lParam);
pt[2].y=HIWORD(lParam);
InvalidateRect(hwnd,NULL,TRUE);
return 0 ;
case WM_MOUSEMOVE: //鼠标移动
//获取左右键是否按下了
if(wParam==MK_LBUTTON) //按下了左键
{
pt[1].x=LOWORD(lParam);
pt[1].y=HIWORD(lParam);
InvalidateRect(hwnd,NULL,TRUE);
}
else if(wParam==MK_RBUTTON) //按下了右键
{
pt[2].x=LOWORD(lParam);
pt[2].y=HIWORD(lParam);
InvalidateRect(hwnd,NULL,TRUE);
}
return 0 ;
case WM_SIZE:
GetClientRect(hwnd,&clientRect);
//初始化bezier曲线参数
pt[0].x=clientRect.right/4;
pt[0].y=clientRect.bottom/2;
pt[3].x=clientRect.right*3/4;
pt[3].y=clientRect.bottom/2;
pt[1].x=clientRect.right/4;
pt[1].y=clientRect.bottom/4;
pt[2].x=clientRect.right*3/4;
pt[2].y=clientRect.bottom*3/4;
return 0 ;