如何用vba在屏幕上画圆?

用api函数Ellipse可以画圆,它的语法如下:

BOOL Ellipse(
  _In_ HDC hdc,
  _In_ int nLeftRect,
  _In_ int nTopRect,
  _In_ int nRightRect,
  _In_ int nBottomRect
);

其中nLeftRect,  nTopRect, nRightRect,  nBottomRect 参数分别表示长方形的左上角和右下角,如果是个正方形,则表示画圆,如果是个长方形则表示画椭圆。

代码如下:

Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long) As Long
Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal nLeftRect As Long, ByVal nTopRect As Long, ByVal nRightRect As Long, ByVal nBottomRect As Long) As Long
Sub QQ1722187970()
    Dim hdc As Long
    hdc = GetDC(0)
    Ellipse hdc, 100, 100, 500, 500
    ReleaseDC 0, hdc
End Sub
       

发表评论