kalala10086 2013-06-20 03:13 采纳率: 0%
浏览 945

求教关于窗口放大,缩小,贝塞尔线相应的放大缩小问题

#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);
}

}

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)