boton minimizar userform
Publicado por Haver (149 intervenciones) el 03/01/2007 23:23:01
como coloco un boton de minimizar o maximizar en un userform? porque por lo general solo tiene el de cerrar...
Valora esta pregunta


0
Option Explicit
Private Declare Function apiGetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function apiSetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function apiDrawMenuBar Lib "user32" Alias "DrawMenuBar" (ByVal hWnd As Long) As Long
Private Declare Function apiFindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function apiGetSystemMenu Lib "user32" Alias "GetSystemMenu" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Declare Function apiModifyMenu Lib "user32" Alias "ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Any) As Long
Private Const MF_BYCOMMAND = &H0&
Private Const MF_ENABLED = &H0&
Private Const MF_GRAYED = &H1&
Private Const SC_CLOSE = &HF060&
Private Const GWL_EXSTYLE = (-20)
Private Const GWL_STYLE As Long = (-16)
Private Const WS_EX_APPWINDOW = &H40000
Private Const WS_SYSMENU As Long = &H80000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_POPUP As Long = &H80000000
Private Const WS_THICKFRAME = &H40000
Public Sub ModificarVentana(frm As Object, bMinimizar As Boolean, bMaximizar As Boolean, bCerrar As Boolean, bReDimensionable As Boolean)
Dim hWnd&, hMenu&
Dim lStyle&
On Error Resume Next
hWnd = apiFindWindow(vbNullString, frm.Caption)
If Not bCerrar Then
hMenu = apiGetSystemMenu(hWnd, 0)
apiModifyMenu hMenu, SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED, -10, "Close"
End If
lStyle = apiGetWindowLong(hWnd, GWL_STYLE)
lStyle = lStyle Or WS_SYSMENU
If bMinimizar Then lStyle = lStyle Or WS_MINIMIZEBOX
If bMaximizar Then lStyle = lStyle Or WS_MAXIMIZEBOX
If bReDimensionable Then lStyle = lStyle Or WS_THICKFRAME
lStyle = lStyle Or WS_POPUP
apiSetWindowLong hWnd, GWL_STYLE, (lStyle)
lStyle = apiGetWindowLong(hWnd, GWL_EXSTYLE)
lStyle = lStyle Or WS_EX_APPWINDOW
apiSetWindowLong hWnd, GWL_EXSTYLE, lStyle
apiDrawMenuBar hWnd
End Sub
Private Sub UserForm_Initialize()
Application.WindowState = xlMaximized
Me.Width = Application.Width
Me.Height = Application.Height
End Sub