比如这个函数
该函数作用是创建一个多边形至scnPts结构中,供CreatePolygonRgn()这样的函数使用,还有很多类似的函数,都有涉及数学方面的知识,我一看就头大。我想问,像这样的函数,有必要读懂它吗,还是会用就行?
Private Static Sub CalcRgnPoints()
   ReDim scnPts(0 To nPts) As POINTAPI
   ReDim rgnPts(0 To nPts) As POINTAPI
   Dim offset As Long
   Dim angle As Long
   Dim theta As Double
   Dim radius1 As Long
   Dim radius2 As Long
   Dim x1 As Long
   Dim y1 As Long
   Dim xOff As Long
   Dim yOff As Long
   Dim n As Long
' Some useful constants.
   Const Pi# = 3.14159265358979
   Const DegToRad# = Pi / 180
' Calc radius based on form size.
   x1 = Me.ScaleWidth \ 2
   y1 = Me.ScaleHeight \ 2
   If x1 > y1 Then
      radius1 = y1 * 0.85
   Else
      radius1 = x1 * 0.85
   End If
   radius2 = radius1 * 0.5
' Offsets to move origin to upper
' left of window.
   xOff = GetSystemMetrics(SM_CXFRAME)
   yOff = GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION)
' Step through a circle, 10 degrees each
' loop, finding points for polygon.
   n = 0
   For angle = 0 To 360 Step 10
      theta = (angle - offset) * DegToRad
' First region is for drawing.
' One long, one short, one long...
      If n Mod 2 Then
         scnPts(n).X = x1 + (radius1 * (Sin(theta)))
         scnPts(n).Y = y1 + (radius1 * (Cos(theta)))
      Else
         scnPts(n).X = x1 + (radius2 * (Sin(theta)))
         scnPts(n).Y = y1 + (radius2 * (Cos(theta)))
      End If
' Second region is for clipping.
' Add offsets.
      rgnPts(n).X = scnPts(n).X + xOff
      rgnPts(n).Y = scnPts(n).Y + yOff
      n = n + 1
   Next angle
   offset = (offset + 2) Mod 360
End Sub

解决方案 »

  1.   

    问题是这样产生的
    模块变量
    Private scnPts() As POINTAPI
    Private rgnPts() As POINTAPI
    调用这两个api使窗体成为rgnPts设置的多边形
          hRgn = CreatePolygonRgn(rgnPts(0), nPts, m_FillMode)
          SetWindowRgn(Me.hWnd, hRgn, True)
    其中,用到了上面我看不懂的那个函数生成rgnPts结构。