Este artículo muestra cómo suprimir los botones maximizar y minimizar en un formulario MDI Parent.
En los formularios no MDI podemos poner a false las propiedades MinButton y MaxButton, pero estas propiedades no están disponibles en un formulario MDI "padre", necesitamos emplear la función SetWindowLong para cambiar el estilo de la ventana.
Declaramos en el formulario :
Funciones para 16 bits :
Declare Function SetWindowLong Lib "User" (ByVal hwnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long
Declare Function GetWindowLong Lib "User" (ByVal hwnd As Integer, ByVal nIndex As Integer) As Long
Funciones para 32 bits:
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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Constantes (comunes):
Const WS_MINIMIZEBOX = &H20000
Const WS_MAXIMIZEBOX = &H10000
Const GWL_STYLE = (-16)
Y ponemos en evento Load del formulario MDI :
Dim L As Long
L = GetWindowLong(Me.hwnd, GWL_STYLE)
L = L And Not (WS_MINIMIZEBOX)
L = L And Not (WS_MAXIMIZEBOX)
L = SetWindowLong(Me.hwnd, GWL_STYLE, L)
Otro ejemplo. Para quietar los botones maximizar, minimizar y cerrar de un formulario podemos hacer :
Declaramos :
rivate Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA"
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const GWL_STYLE = (-16)
Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000
Private Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" _
(ByVal hMenu As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, _
ByVal bRevert As Long) As Long
Private Declare Function RemoveMenu Lib "user32" _
(ByVal hMenu As Long, _
ByVal nPosition As Long, _
ByVal wFlags As Long) As Long
Private Const SC_MINIMIZE As Long = &HF020&
Private Const SC_MAXIMIZE As Long = &HF030&
Private Const MF_BYCOMMAND = &H0&
Private Const SC_CLOSE = &HF060&
Y en el load del formulario :
Dim L As Long
Dim hMenu As Long
Dim menuItemCount As Long
'quitamos los botones de la barra de título
L = GetWindowLong(Me.hwnd, GWL_STYLE)
L = L And Not (WS_MINIMIZEBOX)
L = L And Not (WS_MAXIMIZEBOX)
L = SetWindowLong(Me.hwnd, GWL_STYLE, L)
'quitamos las opciones del menú de control
'Obtenemos un handle al menú de sistema del formulario
hMenu = GetSystemMenu(Me.hwnd, 0)
If hMenu Then
'eliminamos las opciones del menu de control
Call RemoveMenu(hMenu, SC_MAXIMIZE, MF_BYCOMMAND)
Call RemoveMenu(hMenu, SC_MINIMIZE, MF_BYCOMMAND)
'Obtenemos el número de elementos del menú
menuItemCount = GetMenuItemCount(hMenu)
'Eliminamos el elemento Cerrar, que es el último
'Los elemento empiezan a numerarse en cero por lo que el
'último es menuItemCount - 1
Call RemoveMenu(hMenu, menuItemCount - 1, _
MF_REMOVE Or MF_BYPOSITION)
'Eliminamos la barra de separación que hay justo antes de la opción Cerrar
Call RemoveMenu(hMenu, menuItemCount - 2, _
MF_REMOVE Or MF_BYPOSITION)
'redibujamos la barra de menu
Call DrawMenuBar(Me.hwnd)
End If