'Chiamo le API
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
'prende lo stile corrente
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
'Imposta il nuovo stile
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function SetFocus Lib "user32" _
(ByVal hWnd As Long) As Long
'stile della finestra
Private Const GWL_STYLE As Long = (-16)
'stile della finestra esteso
Private Const GWL_EXSTYLE As Long = (-20)
'imposta barra del titolo
Private Const WS_CAPTION As Long = &HC00000
'imposta barra di chiusura
Private Const WS_SYSMENU As Long = &H80000
'imposta finestra ridimensionabile
Private Const WS_THICKFRAME As Long = &H40000
'imposta pulsante riduci
Private Const WS_MINIMIZEBOX As Long = &H20000
'imposta pulsante ingrandisci
Private Const WS_MAXIMIZEBOX As Long = &H10000
Private mhWndForm As Long
'Imposto le nuove proprietà
Public Property Set Form(oForm As Object)
'Ottengo le impostazioni di UserForm in base alle versioni
If Val(Application.Version) < 9 Then
'Excel 97
mhWndForm = FindWindow("ThunderXFrame", oForm.Caption)
Else
'Excel 2000 o superiori
mhWndForm = FindWindow("ThunderDFrame", oForm.Caption)
End If
SetFormStyle
End Property
Private Sub SetFormStyle()
Dim lStyle As Long
lStyle = GetWindowLong(mhWndForm, GWL_STYLE)
'(1) Crea una finestra senza barra del titolo
' SetWindowLong mhWndForm, GWL_STYLE, lStyle And Not WS_CAPTION
'Crea una finestra senza pulsante di chiusura
SetWindowLong mhWndForm, GWL_STYLE, lStyle And Not WS_SYSMENU
'(3) Crea una finestra ridimensionabile
'SetWindowLong mhWndForm, GWL_STYLE, lStyle Or WS_THICKFRAME
'(4) Crea una finestra ridimensionabile e riducibile a icona
'SetWindowLong mhWndForm, GWL_STYLE, lStyle _
Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX
'Aggiorno i cambiamenti
DrawMenuBar mhWndForm
SetFocus mhWndForm
End Sub
|