#include
#include
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM , LPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCMDLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT("BEZER");
HWND hwnd;
WNDCLASS wndclass;
MSG msg;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpszClassName = szAppName;
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.lpszMenuName = NULL;
wndclass.hIcon = LoadIcon (NULL,IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL,IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
if(!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("BEZER Windows Class Not Register!"), szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName, TEXT ("BEZIER SPLINES"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
void DrawBezier(HDC hdc, POINT apt[])
{
PolyBezier (hdc, apt, 4);
MoveToEx (hdc, apt[0].x, apt[0].y, NULL);
LineTo (hdc, apt[1].x, apt[1].y);
MoveToEx (hdc, apt[2].x, apt[2].y, NULL);
LineTo (hdc, apt[3].x, apt[3].y);
}
LRESULT CALLBACK WndProc (HWND hwnd ,UINT message, WPARAM wParam, LPARAM lParam)
{
static POINT apt[4],bpt[4];
static int NUM=0;
static int cxClient, cyClient;
static int bcxClient, bcyClient;
HDC hdc;
PAINTSTRUCT ps;
int i;
TCHAR tBuffer [255];
switch (message)
{
case WM_SIZE :
cxClient = LOWORD (lParam);
cyClient = HIWORD (lParam);
apt[0].x = cxClient / 4;
apt[0].y = cyClient / 2;
apt[1].x = cxClient / 2;
apt[1].y = cyClient / 4;
apt[2].x = cxClient / 2;
apt[2].y = 3 * cyClient / 4;
apt[3].x = 3 * cxClient / 4;
apt[3].y = cyClient / 2;
NUM++;
if(NUM >1)
{
if(cxClient != bcxClient && cyClient != bcxClient)
{ //求教此处当改变窗口大小的时候 btp 结构数组的值还是apt的值
for(i = 0; i != 4; i++)
{ //此处我想实现窗口放大,缩小,坐标相应的按比例放大缩小
apt[i].x = (bpt[i].x * (float) (cxClient / bcxClient));
apt[i].y = (bpt[i].y * (float) (cyClient / bcyClient));
} //到此处,为何bpt的值和apt一样了呢?
}
else
{
for(i = 0; i != 4; i++)
{
apt[i].x = bpt[i].x;
apt[i].y = bpt[i].y;
}
}
}
return 0;
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[1].x = LOWORD (lParam);
apt[1].y = HIWORD (lParam);
}
if(wParam & MK_RBUTTON)
{
apt[2].x = LOWORD (lParam);
apt[2].y = HIWORD (lParam);
}
SelectObject (hdc, GetStockObject(BLACK_PEN));
DrawBezier (hdc, apt);
ReleaseDC (hwnd, hdc);
for(i = 0; i != 4; i++)
{
bpt[i].x = apt[i].x;
bpt[i].y = apt[i].y;
}
}
return 0;
case WM_PAINT:
InvalidateRect (hwnd, NULL, true);
hdc = BeginPaint (hwnd, &ps);
DrawBezier (hdc, apt);
EndPaint (hwnd, &ps);
bcxClient = cxClient;
bcyClient = cyClient;
return 0;
case WM_DESTROY:
PostQuitMessage (WM_QUIT);
return 0;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
}