Create rounded form

Visual Basic Topics
Post Reply
User avatar
tharaka
Posts: 2
Joined: Tue Jul 21, 2009 10:59 pm

Create rounded form

Post by tharaka » Mon Aug 03, 2009 11:28 am

how to create rounded form using windows APIs?

Ta
User avatar
kumara
Posts: 2
Joined: Tue Jul 21, 2009 11:03 pm

Re: Create rounded form

Post by kumara » Wed Aug 19, 2009 2:40 pm

Code: Select all

Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long

Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long

Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, _
    ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, _
    ByVal Y3 As Long) As Long

Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type


Private Sub Form_Load()

    Dim lpRect As RECT
    Dim W As Long, H As Long
    Dim hRgn As Long
    
    ' get the bounding rectangle's size
    GetWindowRect hWnd, lpRect
    W = lpRect.Right - lpRect.Left
    H = lpRect.Bottom - lpRect.Top

    hRgn = CreateRoundRectRgn(0, 0, W, H, 20, 20)
    
    ' trim the window to the region
    SetWindowRgn hWnd, hRgn, True
    DeleteObject hRgn

End Sub
Post Reply

Return to “Visual Basic Programming”