Private Const REG_OR = 2
Private Const REG_MIN = 4
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE
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 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 Boolean) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, ByVal x As Long, Y, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
Dim GlassForm As Long
' ------------------------------------------------------------------------------------
Private Sub Form_Click()
TraspGlass 2
' TraspGlass 0 x tornare allo stato precedente non-glass
' TraspGlass 1 ' ...Glass PARZIALE (Resta la caption del form)
' TraspGlass 2 ' ...Glass TOTALE (restano solo i controlli senza form)
End Sub
' ------------------------------------------------------------------------------------
Private Sub Form_Initialize()
' Creazione di due controlli per il test di trasparenza form:
' Primo controllo (TextBox)
Dim MyCTRL1 As String
Dim NewTextBox As TextBox
MyCTRL1 = "NewTextBox"
Set NewTextBox = Controls.Add("VB.TextBox", MyCTRL1)
NewTextBox.BorderStyle = 1
NewTextBox.Appearance = 0
NewTextBox.Text = "TEXT BOX nr. 1"
NewTextBox.Left = 120
NewTextBox.Top = 120
NewTextBox.Height = 300
NewTextBox.Width = 2200
NewTextBox.Visible = True
' Secondo controllo (CommandButton)
Dim MyCTRL2 As String
Dim NewCmdButton As CommandButton
MyCTRL2 = "NewCmdButton"
Set NewCmdButton = Controls.Add("VB.CommandButton", MyCTRL2)
NewCmdButton.Height = 300
NewCmdButton.Width = 2200
NewCmdButton.Left = 120
NewCmdButton.Top = 444
NewCmdButton.Caption = "CMD DI PROVA"
NewCmdButton.Visible = True
Me.Height = 1890
Me.Width = 6000
' Non modificare!!!
Me.ScaleMode = vbPixels
Me.Caption = "Un click con il tasto del mouse su questo form..."
End Sub
' ------------------------------------------------------------------------------------
Private Sub TraspGlass(GlassFX As Integer)
Dim w As Single, h As Single, Contorno As Single, topEye As Single
Dim i As Long, k As Long, n As Long, q As Long
Dim PosTop As Double, PosLeft As Double
' Conversione su assi X/Y | width/height | scalewidth/scaleheight
w = ScaleX(Width, vbTwips, vbPixels)
h = ScaleY(Height, vbTwips, vbPixels)
' Verifica lo stato...
If GlassFX = 0 Then
GlassForm = CreateRectRgn(0, 0, w, h)
SetWindowRgn hwnd, GlassForm, True
Exit Sub
End If
GlassForm = CreateRectRgn(0, 0, 0, 0)
Contorno = (w - ScaleWidth) / 2
topEye = h - Contorno - ScaleHeight
If GlassFX = 1 Then
k = CreateRectRgn(0, 0, w, h)
n = CreateRectRgn(Contorno, topEye, w - Contorno, h - Contorno)
CombineRgn GlassForm, k, n, REG_MIN
End If
' Traspone la nuova regione sul form...
For i = 0 To Me.Controls.Count - 1
If Me.Controls(i).Visible = True Then
PosLeft = ScaleX(Me.Controls(i).Left, Me.ScaleMode, vbPixels) + Contorno
PosTop = ScaleX(Me.Controls(i).Top, Me.ScaleMode, vbPixels) + topEye
q = CreateRectRgn(PosLeft, PosTop, _
PosLeft + ScaleX(Me.Controls(i).Width, Me.ScaleMode, vbPixels), PosTop + ScaleY(Me.Controls(i).Height, Me.ScaleMode, vbPixels))
CombineRgn GlassForm, q, GlassForm, REG_OR
End If
Next
' Esegue...
SetWindowRgn hwnd, GlassForm, True
End Sub
' ------------------------------------------------------------------------------------
Private Sub Form_Load()
' Centra il form
CentraForm Form1
' On Top
MakeTopMost Me.hwnd
End Sub
' ------------------------------------------------------------------------------------
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
' Scarca l'oggetto GlassForm dalla memoria.
SetWindowRgn hwnd, 0, False
DeleteObject GlassForm
' Scarica il form dalla memoria
Unload Form1
Set Form1 = Nothing
End Sub
' ------------------------------------------------------------------------------------
Public Sub CentraForm(MyForm As Form)
' Centra il form
MyForm.Top = (Screen.Height - MyForm.Height) / 2
MyForm.Left = (Screen.Width - MyForm.Width) / 2
End Sub
' ------------------------------------------------------------------------------------
Sub MakeNormal(Handle As Long)
SetWindowPos Handle, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub
' ------------------------------------------------------------------------------------
Sub MakeTopMost(Handle As Long)
SetWindowPos Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub