Trucos Formulario MDI que no se pueda maximizar ni cambiar el tamaño

Si queremos que un formulario MDI (padre) no tenga el botón de maximizar ni se le pueda cambiar el tamaño podremos hacer lo siguiente :

Si eliminas una opción del menu de sistema de la ventana eliminas la acción asociada. Con el código que veremos a continuación podremos eliminar las opciones tamaño, maximizar y minimizar de dicho menú y los botones de la barra de título correspondientes :

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

Const WS_MINIMIZEBOX = &H20000
Const WS_MAXIMIZEBOX = &H10000
Const GWL_STYLE = (-16)

Const MF_BYPOSITION = &H400
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 Sub MDIForm_Load()
Dim L As Long
Dim hMenu As Long
Dim menuItemCount As Long


'para que no se vean los botones
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)

'para quitar las opciones del menu de sistemas
'Obtenemos un handle al menú de sistema del formulario
hMenu = GetSystemMenu(Me.hwnd, 0)
If hMenu Then
     'eliminamos tamaño
     Call RemoveMenu(hMenu, 2, MF_REMOVE Or MF_BYPOSITION)
     'eliminamos minimizar (ahora está en el 3)
     Call RemoveMenu(hMenu, 2, MF_REMOVE Or MF_BYPOSITION)
     'Eliminamos el elemento maximizar (ahora está en el 3)
      Call RemoveMenu(hMenu, 2, MF_REMOVE Or MF_BYPOSITION)
     'Forzamos el redibujado del menú. Esto refresca la barra de título
     Call DrawMenuBar(Me.hwnd)
End If

End Sub



Trucos Trucos

Visual Basic Página de Visual Basic

Página principal Página principal

www.jrubi.com