Link to home
Start Free TrialLog in
Avatar of ahmadpj
ahmadpj

asked on

disable MDI form minimize button

How i can disable or invisible the Minimize button of a MDIform?
ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VBMAD
VBMAD

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

hSysMenu = GetSystemMenu(Me.hWnd, 0)
Call RemoveMenu(hSysMenu, 1, &H400&)
Call RemoveMenu(hSysMenu, 2, &H400&)
Call RemoveMenu(hSysMenu, 3, &H400&)
Call RemoveMenu(hSysMenu, 4, &H400&)


Each form has system menu. It occurs at click mouse on icon in the left upper corner of the form.
Its units:
- Restore
- Move
- Size
- Minimize
- Maximize
- (separator)
- Close
In an example the first 5 menu items are deleted.

Example:
-------------------------------Module1 -------------------------------------------
Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, _
    ByVal wFlags As Long) As Long
Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Const MF_BYPOSITION = &H400&
Const MF_REMOVE = &H1000&

Public Sub DisableMaxMin(ByVal Form_hWnd As Long)
    Dim hMenu As Long
    Dim nCount As Long
    Dim i as Long

    hMenu = Module1.GetSystemMenu(Form_hWnd, 0)
    nCount = Module1.GetMenuItemCount(hMenu)
    For i=1 To 5
        Module1.RemoveMenu hMenu, 1, Module1.MF_REMOVE Or Module1.MF_BYPOSITION
    Next i
    Module1.DrawMenuBar Form_hWnd
End Sub

Sub main()
    MDIForm1.Show
End Sub
------------------------------- end Module1 ------------------------------------

------------------------------- MDIForm1 ----------------------------------------
Private Sub MDIForm_Load()
     Module1.DisableMaxMin Me.hwnd
End Sub
------------------------------- end MDIForm1-----------------------------------
Avatar of ahmadpj

ASKER

Thank u all, i used Ark code, and it works, but i have a question from Ark, how u find out the value of WS_MINIMIZEBOX, i asked it cuz i want it for WS_MAXIMIZEBOX
Private Const WS_MAXIMIZEBOX = &H10000
Avatar of ahmadpj

ASKER

Yes i know it is &H10000 but how we can find it?