I'm trying to cutout a circular region out of a command button .this is what i have done::
VB Code:
Option Explicit Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) 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 DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private m_FormRegion As Long Private Sub CutRect(ByRef outer_rgn As Long) Const RGN_DIFF = 1 Dim inner_rgn As Long Dim combined_rgn As Long inner_rgn = CreateEllipticRgn(100 - 30, 50 - 0, 20, 10) combined_rgn = CreateRectRgn(Command1.Width, Command1.Height, Command1.Left - 10, Command1.Top - 10) CombineRgn combined_rgn, outer_rgn, inner_rgn, RGN_DIFF DeleteObject outer_rgn DeleteObject inner_rgn outer_rgn = combined_rgn End Sub Private Sub Form_Load() Dim border_width As Single Dim title_height As Single m_FormRegion = CreateRectRgn(Command1.Width, Command1.Height, Command1.Left - 10, Command1.Top - 10) border_width = (Command1.Left + Command1.Width) title_height = Command1.Top + Command1.Height CutRect m_FormRegion SetWindowRgn Command1.hWnd, m_FormRegion, True End Sub Private Sub Form_Unload(Cancel As Integer) If m_FormRegion <> 0 Then DeleteObject m_FormRegion m_FormRegion = 0 End If 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...




Reply With Quote