一闪一闪小星星
介绍 很久以前,我需要给我的老板留下深刻印象。我们不得不年度讨论薪水。所以我写了一个应用程序显示“非常先进的编程技能”。 背景 现在我有翻译这个令人难以置信的VB.NET应用程序。 使用的代码 运行代码,您将看到所有的结果产生的代码。 的兴趣点 基本api: 隐藏,收缩,复制Code
Structure RECT Public Left As Int32 Public Top As Int32 Public Right As Int32 Public Bottom As Int32 End Structure Public Structure POINTAPI Dim X As Int32 Dim Y As Int32 End Structure Declare Function DeleteObject Lib "gdi32" (ByVal hObject As IntPtr) As Boolean Declare Function GetStockObject Lib "gdi32.dll" (ByVal nIndex As Int32) As IntPtr Declare Function GetWindowRgn Lib "user32" (ByVal hwnd As IntPtr, ByVal hRgn As IntPtr) As IntPtr Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As IntPtr, ByVal hRgn As IntPtr, ByVal bRedraw As Boolean) As Int32 'for round form Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Int32, ByVal Y1 As Int32, ByVal X2 As Int32, ByVal Y2 As Int32, ByVal X3 As Int32, ByVal Y3 As Int32) As IntPtr 'for star form Declare Function CreatePolygonRgn Lib "gdi32" (ByRef lpPoint As POINTAPI, ByVal nCount As Int32, ByVal nPolyFillMode As Int32) As IntPtr 'for elliptic form Declare Function CreateEllipticRgn Lib "gdi32.dll" (ByVal X1 As Int32, ByVal Y1 As Int32, ByVal X2 As Int32, ByVal Y2 As Int32) As IntPtr Declare Function CreateRectRgn Lib "gdi32.dll" (ByVal X1 As Int32, ByVal Y1 As Int32, ByVal X2 As Int32, ByVal Y2 As Int32) As IntPtr Declare Function GetWindowDC Lib "user32" (ByVal hWnd As IntPtr) As IntPtr Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As Int32 'for frame of form Declare Function FrameRgn Lib "gdi32" (ByVal hdc As IntPtr, ByVal hRgn As IntPtr, ByVal hBrush As IntPtr, ByVal nWidth As Int32, ByVal nHeight As Int32) As IntPtr Private Const BLACK_BRUSH As Int32 = 4
(注意:POINTAPI不在框架。) 恒星的制作: 隐藏,收缩,复制Code
Private Sub MakePolygonForm(ByVal InForm As Form, ByVal Offset As Single) Const WINDING As Int32 = 2 Const RADIEKONVERT As Double = 3.1416 / 180 Const GRADER As Int32 = 360 Const MAXRADER As Int32 = 200 'change this to 6 for a David star, try alsso 5,7,8,9,10 Const SPETSAR As Int32 = 7 Dim x, y As Int32 Dim xCenter, yCenter, Radie, Punkter, I As Int32 Dim Vinkel As Double Dim Rotation As Int32 Dim arPoints(MAXRADER) As POINTAPI Dim RECT As RECT Dim rgn As IntPtr RECT.Right = 300 RECT.Left = 0 RECT.Top = 0 RECT.Bottom = 300 xCenter = CInt((RECT.Right - RECT.Left) / 2) yCenter = CInt((RECT.Bottom - RECT.Top) / 2) Rotation = CInt(GRADER / (2 * SPETSAR)) Punkter = 2 * SPETSAR Radie = yCenter For I = 0 To Punkter - 1 If (I Mod 2) = 0 Then Radie = CInt((Radie / 2)) Else Radie = yCenter End If 'remove Offset to make it stay put: Vinkel = I * Rotation * RADIEKONVERT Vinkel = I * Rotation * RADIEKONVERT + Offset x = CInt(xCenter + (System.Math.Cos(Vinkel) * Radie)) y = CInt(yCenter + (System.Math.Sin(Vinkel) * Radie)) arPoints(I).X = x arPoints(I).Y = y Next rgn = CreatePolygonRgn(arPoints(0), Punkter, WINDING) Call SetWindowRgn(Me.Handle, rgn, True) If CInt(rgn) <> 0 Then DeleteObject(rgn) End Sub
如果你想要另一种形式的表单,使用: 隐藏,复制Code
MakeRoundForm(Me)
或者: 隐藏,复制Code
MakeEllipticForm(Me)
你可以调整FrameRgn框架的厚度: 隐藏,复制Code
Private Function FrameWindowRgn(ByVal hwnd As IntPtr) As IntPtr Dim hRgn,hDC As IntPtr hDC = GetWindowDC(hwnd) ' Get a DC for non-client area If CInt(hDC) <> 0 Then hRgn = CreateRectRgn(0, 0, 0, 0) ' Create empty region If CInt(hRgn) <> 0 Then If CInt(GetWindowRgn(hwnd, hRgn)) <> 0 Then ' to make border thicker, adjust the 2:s to something else FrameWindowRgn = FrameRgn(hDC,hRgn, GetStockObject(BLACK_BRUSH), 2, 2) ' Draw the frame End If End If End If If CInt(hRgn) <> 0 Then DeleteObject(hRgn) 'release resources If CInt(hDC) <> 0 Then ReleaseDC(hwnd, hDC) 'release resources End Function
本文转载于:http://www.diyabc.com/frontweb/news8438.html