VC++如何用API函数在客户区随便点就话一个圆很难不会

解决方案 »

  1.   

    摘自MSDN:Ellipse
    The Ellipse function draws an ellipse. The center of the ellipse is the center of the specified bounding rectangle. The ellipse is outlined by using the current pen and is filled by using the current brush. BOOL Ellipse(
      HDC hdc,        // handle to DC
      int nLeftRect,  // x-coord of upper-left corner of rectangle
      int nTopRect,   // y-coord of upper-left corner of rectangle
      int nRightRect, // x-coord of lower-right corner of rectangle
      int nBottomRect // y-coord of lower-right corner of rectangle
    );
    Parameters
    hdc 
    [in] Handle to the device context. 
    nLeftRect 
    [in] Specifies the x-coordinate of the upper-left corner of the bounding rectangle. 
    nTopRect 
    [in] Specifies the y-coordinate of the upper-left corner of the bounding rectangle. 
    nRightRect 
    [in] Specifies the x-coordinate of the lower-right corner of the bounding rectangle. 
    nBottomRect 
    [in] Specifies the y-coordinate of the lower-right corner of the bounding rectangle. ===这里是椭圆,如果nLeftRect, nTopRect, nRightRect, nBottomRect构成一个正方形的话就是一个圆
      

  2.   

    #include  <windows.h>  
     
    LRESULT            CALLBACK            WndProc(  HWND,  UINT,  WPARAM,  LPARAM  );  
    void  DrawBezier(  HDC  hdc,  POINT  apt[]  );  
     
    int  WINAPI            WinMain(  HINSTANCE  hInstance,  HINSTANCE  hPrevInstance,  LPSTR  szCmdLine,  int  iCmdShow  )  
    {  
               static  TCHAR  szAppName[]  =  TEXT("Bezier");  
               HWND            hwnd;  
               MSG                        msg;  
               WNDCLASS            wndclass;  
     
               wndclass.style  =  CS_HREDRAW    &brvbar;  CS_VREDRAW    &brvbar;  CS_DBLCLKS;  
               wndclass.lpszClassName  =  szAppName;  
               wndclass.cbClsExtra  =  0;  
               wndclass.cbWndExtra  =  0;  
               wndclass.hbrBackground  =  (HBRUSH)  GetStockObject(WHITE_BRUSH);  
               wndclass.hCursor  =  LoadCursor(NULL,  IDC_ARROW);  
               wndclass.hIcon  =  LoadIcon(NULL,  IDI_APPLICATION);  
               wndclass.lpszMenuName  =  NULL;  
               wndclass.lpfnWndProc  =  WndProc;  
               wndclass.hInstance  =  hInstance;  
                 
                 
               if(  !RegisterClass(&wndclass)  )  
               {  
                           MessageBox(  NULL,  TEXT("Program  require  windows  NT"),  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;  
    }  
     
    LRESULT  CALLBACK            WndProc(  HWND  hwnd,  UINT  message,  WPARAM  wParam,  LPARAM  lParam  )  
    {  
               static  POINT            aptFigure[10]  =  {  10,  70,  50,  70,  50,  10,  90,  10,  90,  50,  
                                                                                                                   30,  50,  30,  90,  70,  90,  70,  30,  10,  30  };  
               static  int  cxClient,  cyClient;  
               static  int  cxLeft,  cxRight,  cyTop,  cyBottom;  
               HDC  hdc;  
               static  BOOL  FirstMove  =  TRUE;  
               PAINTSTRUCT            ps;  
     
               switch(message)  
               {  
               case  WM_SIZE  :  
                           cxClient  =  LOWORD(lParam);  
                           cyClient  =  HIWORD(lParam);  
                           return  0;  
               case  WM_CREATE:  
               case  WM_PAINT:              
                           hdc  =  BeginPaint(hwnd,  &ps);  
                           SelectObject(  hdc,  GetStockObject(GRAY_BRUSH)  );  
                           SetPolyFillMode(  hdc  ,  ALTERNATE  );  
                           Ellipse(  hdc,  cxLeft,  cyTop,  cxRight,  cyBottom  );  
                           TextOut(  hdc,  cxClient/2,  cyClient/2,  TEXT("靠都揭贴了怎么还在未解决区!"),  30  );  
                           EndPaint(hwnd,  &ps);  
                           return  0;  
               case  WM_LBUTTONDBLCLK:  
                                       FirstMove  =  FALSE;  
                                       cxLeft  =  LOWORD(lParam)  -  50  ;  
                                       cxRight  =  LOWORD(lParam)  +  50;  
                                       cyTop  =  HIWORD(lParam)  +  50;  
                                       cyBottom  =  HIWORD(lParam)  -  50;  
                                       InvalidateRect(  hwnd,  NULL,  TRUE  );  
                                       return  0;  
               case  WM_MOUSEMOVE:  
                                       if(FirstMove)  
                                                   return  0;  
                                       cxLeft  =  LOWORD(lParam)  -  50  ;  
                                       cxRight  =  LOWORD(lParam)  +  50;  
                                       cyTop  =  HIWORD(lParam)  +  50;  
                                       cyBottom  =  HIWORD(lParam)  -  50;  
                                       InvalidateRect(  hwnd,  NULL,  TRUE  );  
                                       return  0;  
               case  WM_LBUTTONDOWN:  
                                       FirstMove  =  TRUE;  
                                       return  0;  
               case  WM_DESTROY:  
                           PostQuitMessage(0);  
                           return  0;  
     
     
               }  
               return  DefWindowProc(  hwnd,  message,  wParam,  lParam  );  
     
    }