Este é um recurso útil para formulários Splash ou onde a sua imaginação o tornar aplicável.
O que importa é que aprenda aqui como fazê-lo.
No módulo do formulário acrescente:'==============================================================================================' Microsoft® Office Excel by A&A - In Any Place.' Copyright© A&A – In Any Place. All Rights Reserved.'==============================================================================================Option ExplicitPrivate Declare Function SetWindowLong _Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Declare Function SetLayeredWindowAttributes _Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As LongPrivate Declare Function FindWindow _Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function GetWindowLong _Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As LongPrivate Const GWL_EXSTYLE = (-20)Private Const WS_EX_LAYERED = &H80000Private Const LWA_ALPHA = &H2&Public hWnd As LongNo evento de inicialização do seu formulário, faça uma chamada a função a seguir:Function OpacityNow()
' Author: Date: Contact:' André Bernardes 24/11/2008 10:09 bernardess@gmail.com' Deixando o formulário transparente.Dim bytOpacity As ByteLet bytOpacity = 195 ' Nível de opacidade.Let hWnd = FindWindow ("ThunderDFrame", Me.Caption)
Call SetWindowLong (Me.hWnd, GWL_EXSTYLE, GetWindowLong(Me.hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED)Call SetLayeredWindowAttributes (Me.hWnd, 0, bytOpacity, LWA_ALPHA)
Abaixo segue um código adaptado a partir do VB 6.0End Function
Dim formEffectIndex As IntegerDim mFormRegion As LongDim msg1 As String, msg2 As StringDim HWNDDim ODIALOG As ObjectPrivate Sub changeFormEffect (inEffect As Integer, ODIALOG As Object)
Dim w As Single, h As SingleDim edge As Single, topEdge As SingleDim mLeft, mTopDim i As IntegerDim r As LongDim outer As Long, inner As Long' Put width/height in same denomination of scalewidth/scaleheightLet w = ODIALOG.Width 'ScaleX(Width, vbTwips, vbPixels)Let h = ODIALOG.Height 'ScaleY(Height, vbTwips, vbPixels)If inEffect = 0 ThenLet mFormRegion = CreateRectRgn(0, 0, w, h)SetWindowRgn HWND, mFormRegion, TrueExit SubEnd IfLet mFormRegion = CreateRectRgn(0, 0, 0, 0)' Frame edges measurementLet edge = (w) / 2 '-SCALEWIDTHLet topEdge = h - edge - 20 '- ScaleHeight' Get frameIf inEffect = 1 Thenouter = CreateRectRgn(0, 0, w, h)inner = CreateRectRgn(edge, topEdge, w - edge, h - edge)CombineRgn mFormRegion, outer, inner, RGN_DIFFEnd If
' Combine regions of controls on form' For i = 0 To Me.Controls.Count - 1' If Me.Controls(i).Visible = True Then' mLeft = Me.Controls(i).Left 'ScaleX(Me.Controls(i).Left, Me.ScaleMode, vbPixels) + edge' mTop = Me.Controls(i).Top 'ScaleX(Me.Controls(i).Top, Me.ScaleMode, vbPixels) + topEdge' r = CreateRectRgn(mLeft, mTop, _' mLeft + (Me.Controls(i)), _' mTop + (Me.Controls(i).Height))' 'ScaleX(Me.Controls(i).Width, Me.ScaleMode, vbPixels)' 'ScaleY(Me.Controls(i).Height, Me.ScaleMode, vbPixels)' End If' Next' We allow toggleSetWindowRgn HWND, mFormRegion, True
End SubPrivate Sub commandBUTTON1_Click()
Let HWND = FindWindow("ThunderDFrame", ODIALOG.Caption)If formEffectIndex <> 0 ThenLet formEffectIndex = 0'Let Text1.Text = msg1ElseLet formEffectIndex = 1'Let Text1.Text = msg2End IfchangeFormEffect formEffectIndex, Me
End SubPrivate Sub commandBUTTON2_Click()
If formEffectIndex = 1 ThenLet formEffectIndex = 2ElseLet formEffectIndex = 1End IfchangeFormEffect formEffectIndex, Me
End SubPrivate Sub command4_Click(Index As Integer)
Let mShape = IndexUnloadIfExist "frmShapedForm"frmShapedForm.Show
End SubPrivate Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
SetWindowRgn HWND, 0, FalseDeleteObject mFormRegion
End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button <> vbLeftButton Then
Exit Sub
End IfReleaseCaptureSendMessage Me.HWND, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub' Unlike frmShapedForm, since frmTransparent is transparent, we have to' provide a place for user to drag if without frame, so Command0 is used.Private Sub Command0_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button <> vbLeftButton Then
Exit Sub
End IfReleaseCaptureSendMessage Me.HWND, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End SubPublic Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal HWND As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPublic Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As LongPublic 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 LongPublic Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As LongPublic Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As LongPublic Declare Function SetWindowRgn Lib "user32" (ByVal HWND As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As LongPublic Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As LongPublic Declare Function ReleaseCapture Lib "user32" () As Long' RGN_OR creates the union of combined regionsPublic Const RGN_OR = 2' RGN_DIFF creates the intersection of combined regionsPublic Const RGN_DIFF = 4Public Const WM_NCLBUTTONDOWN = &HA1Public Const HTCAPTION = 2Public xp As Long, yp As LongPublic mShape As IntegerPublic Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPublic Declare Function SetWindowPos Lib "user32.dll" (ByVal HWND As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongPublic Declare Function GetActiveWindow Lib "user32.dll" () As LongPublic Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal HWND As Long, ByVal nIndex As Long) As LongPublic Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal HWND As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPublic Declare Function BringWindowToTop Lib "user32.dll" (ByVal HWND As Long) As LongConst WS_SYSMENU = &H80000Const GWL_STYLE = (-16)Private Sub UserForm_INITIALIZE()
Set ODIALOG = UserForm1Select Case Int (Val(Application.Version))Case 8 'Excel 97HWND = FindWindow("ThunderXFrame", ODIALOG.Caption) 'UserFormCase 9, 10 'Excel 2000HWND = FindWindow("ThunderDFrame", ODIALOG.Caption) 'UserFormEnd Select
End Sub
Deixe os seus comentários! Envie este artigo, divulgue este link na sua rede social...
Tags: VBA,
Nenhum comentário:
Postar um comentário