I'm trying to cutout a circular region out of a command button .this is what i have done::

VB Code:
  1. Option Explicit
  2.  
  3. Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  4. Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  5. Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
  6. Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
  7. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  8.  
  9. Private m_FormRegion As Long
  10.  
  11. Private Sub CutRect(ByRef outer_rgn As Long)
  12. Const RGN_DIFF = 1
  13. Dim inner_rgn As Long
  14. Dim combined_rgn As Long
  15.  
  16.     inner_rgn = CreateEllipticRgn(100 - 30, 50 - 0, 20, 10)
  17.     combined_rgn = CreateRectRgn(Command1.Width, Command1.Height, Command1.Left - 10, Command1.Top - 10)
  18.     CombineRgn combined_rgn, outer_rgn, inner_rgn, RGN_DIFF
  19.     DeleteObject outer_rgn
  20.     DeleteObject inner_rgn
  21.     outer_rgn = combined_rgn
  22.  
  23. End Sub
  24.  
  25. Private Sub Form_Load()
  26. Dim border_width As Single
  27. Dim title_height As Single
  28.     m_FormRegion = CreateRectRgn(Command1.Width, Command1.Height, Command1.Left - 10, Command1.Top - 10)
  29.     border_width = (Command1.Left + Command1.Width)
  30.     title_height = Command1.Top + Command1.Height
  31.     CutRect m_FormRegion
  32.     SetWindowRgn Command1.hWnd, m_FormRegion, True
  33. End Sub
  34.  
  35. Private Sub Form_Unload(Cancel As Integer)
  36.     If m_FormRegion <> 0 Then
  37.         DeleteObject m_FormRegion
  38.         m_FormRegion = 0
  39.     End If
  40. End Sub

It works if i place my command1 button at the top left corner of the form .but when i place it anywhere else,it doesnt work....

any idea why??

ps:this is the first time i'm coding api's and stuff...