title: Win32 GDI Drawing a circle?
body: <p>I am trying to draw a circle and I am currently using the Ellipse() function. </p>
  
  <p>I have the starting mouse coordinates - x1 and y1 and the ending coordinates x2 and y2. As you can see, I am forcing the y2(temp_shape.bottom) to be = y1+(x2-x1). This doesn't work as intended. I know the calculation is completely wrong but any ideas on what is right? </p>
  
  <p>Code Below.</p>
  
  <pre><code>case WM_PAINT:
          {
  
              hdc = BeginPaint(hWnd, &amp;ps);
              // TODO: Add any drawing code here...
              RECT rect;
              GetClientRect(hWnd, &amp;rect);
  
              HDC backbuffDC = CreateCompatibleDC(hdc);
  
              HBITMAP backbuffer = CreateCompatibleBitmap( hdc, rect.right, rect.bottom);
  
              int savedDC = SaveDC(backbuffDC);
              SelectObject( backbuffDC, backbuffer );
              HBRUSH hBrush = CreateSolidBrush(RGB(255,255,255));
              FillRect(backbuffDC,&amp;rect,hBrush);
              DeleteObject(hBrush);
  
  
  
              //Brush and Pen colours
              SelectObject(backbuffDC, GetStockObject(DC_BRUSH));
              SetDCBrushColor(backbuffDC, RGB(255,0,0));
              SelectObject(backbuffDC, GetStockObject(DC_PEN));
              SetDCPenColor(backbuffDC, RGB(0,0,0));
  
  
  
              //Shape Coordinates
              temp_shape.left=x1;
              temp_shape.top=y1;
              temp_shape.right=x2;
              temp_shape.bottom=y2;
  
  
  
              //Draw Old Shapes
              //Rectangles
              for ( int i = 0; i &lt; current_rect_count; i++ )
              {
                  Rectangle(backbuffDC, rect_list[i].left, rect_list[i].top, rect_list[i].right, rect_list[i].bottom);
              }
              //Ellipses
              for ( int i = 0; i &lt; current_ellipse_count; i++ )
              {
                  Ellipse(backbuffDC, ellipse_list[i].left, ellipse_list[i].top, ellipse_list[i].right, ellipse_list[i].bottom);
              }
  
              if(mouse_down)
              {
                  if(drawCircle)
                  {
  
                      temp_shape.right=y1+(x2-x1);
  
                      Ellipse(backbuffDC, temp_shape.left, temp_shape.top, temp_shape.right, temp_shape.bottom);
                  }
  
                  if(drawRect)
                  {
                      Rectangle(backbuffDC, temp_shape.left, temp_shape.top, temp_shape.right, temp_shape.bottom);
                  }
  
                  if(drawEllipse)
                  {
                      Ellipse(backbuffDC, temp_shape.left, temp_shape.top, temp_shape.right, temp_shape.bottom);
                  }
              }
  
              BitBlt(hdc,0,0,rect.right,rect.bottom,backbuffDC,0,0,SRCCOPY);
              RestoreDC(backbuffDC,savedDC);
  
              DeleteObject(backbuffer);
              DeleteDC(backbuffDC);
              EndPaint(hWnd, &amp;ps);
          }
          break;
  </code></pre>