Solved

How can I disable the maximize / restore on the window menu

Posted on 2001-09-17
8
301 Views
Last Modified: 2008-02-01
I can disable the close item with following code, but how can I disable the max/restore button on a mdiform???
I can't figure out what to change in this code.


' Bas module
Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Public Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Public Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Public Const MF_BYPOSITION = &H400&
Public Const MF_REMOVE = &H1000&

Private Sub MDIForm_Load()

    Dim hSysMenu As Long, nCnt As Long
    ' Get handle to our form's system menu
    ' (Restore, Maximize, Move, close etc.)
    hSysMenu = GetSystemMenu(Me.hwnd, False)

    If hSysMenu Then
        ' Get System menu's menu count
        nCnt = GetMenuItemCount(hSysMenu)
        If nCnt Then
            ' Menu count is based on 0 (0, 1, 2, 3...)
            RemoveMenu hSysMenu, nCnt - 1, MF_BYPOSITION Or MF_REMOVE
            RemoveMenu hSysMenu, nCnt - 2, MF_BYPOSITION Or MF_REMOVE ' Remove the seperator
            DrawMenuBar Me.hwnd
            ' Force caption bar's refresh. Disabling X button
            Me.Caption = "Try to close me!"
        End If
    End If

End Sub



0
Comment
Question by:Zorxx
  • 4
  • 2
  • 2
8 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 6486940
Zorxx, all three for you:

MinEnabled(frmMDIForm) = False
MaxEnabled(frmMDIForm) = False
And Optionally
CloseEnabled(frmMDIForm) = False

To hide the two (or three) buttons. If you choose to hide all three, you must call the CloseEnabled
method last otherwise it will not work.

Option Explicit

'Window style constants
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const GWL_STYLE = (-16)
Private Const MF_BYPOSITION = &H400&
Private Const MF_DISABLED = &H2&

'API Declarations
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal

nIndex As Long) As Long
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 GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu 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 member variables
Private lWindowStyle As Long
Private lMenu As Long

Public Property Let MinEnabled(ByVal frm As Object, ByVal New_Value As Boolean)

 If New_Value = True Then
    lWindowStyle = GetWindowLong(frm.hwnd, GWL_STYLE)
    Call SetWindowLong(frm.hwnd, GWL_STYLE, lWindowStyle Or WS_MINIMIZEBOX)
    lMenu = GetSystemMenu(frm.hwnd, True)
    Call DrawMenuBar(frm.hwnd)
 Else
    lWindowStyle = GetWindowLong(frm.hwnd, GWL_STYLE)
    Call SetWindowLong(frm.hwnd, GWL_STYLE, lWindowStyle And Not WS_MINIMIZEBOX)
    lMenu = GetSystemMenu(frm.hwnd, True)
    Call DrawMenuBar(frm.hwnd)
 End If

End Property

Public Property Let MaxEnabled(ByVal frm As Object, ByVal New_Value As Boolean)
 
 If New_Value = True Then
    lWindowStyle = GetWindowLong(frm.hwnd, GWL_STYLE)
    Call SetWindowLong(frm.hwnd, GWL_STYLE, lWindowStyle Or WS_MAXIMIZEBOX)
    lMenu = GetSystemMenu(frm.hwnd, True)
    Call DrawMenuBar(frm.hwnd)
 Else
    lWindowStyle = GetWindowLong(frm.hwnd, GWL_STYLE)
    Call SetWindowLong(frm.hwnd, GWL_STYLE, lWindowStyle And Not WS_MAXIMIZEBOX)
    lMenu = GetSystemMenu(frm.hwnd, True)
    Call DrawMenuBar(frm.hwnd)
 End If
 
End Property

Public Property Let TermEnabled(ByVal frm As Object, ByVal New_Value As Boolean)
Dim lCount As Long
 
  If New_Value = True Then
    lMenu = GetSystemMenu(frm.hwnd, True)
    Call DrawMenuBar(frm.hwnd)
  Else
    lMenu = GetSystemMenu(frm.hwnd, 0)
    lCount = GetMenuItemCount(lMenu)
    Call RemoveMenu(lMenu, lCount - 1, MF_DISABLED Or MF_BYPOSITION)
    Call DrawMenuBar(frm.hwnd)
 End If

End Property
0
 

Author Comment

by:Zorxx
ID: 6492787
But how can i disable the restore button of an MDI child then????. Because when I disable the MAXbutton it will not show up. What I want to do is, when the MDI child form is shown there are three buttons the MIN the Restore and the close. How can I disable the Restore button here???
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6493398
<listening..>
0
 

Author Comment

by:Zorxx
ID: 6493503
what is that ryancys,    <listening..>

Is this a special sign in the experts list.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6493544
Sorry Zorxx,

No, Just put a signal here so that i will always get the updates on this question..

And of course learn something from here!
0
 

Author Comment

by:Zorxx
ID: 6493592
I will increase the points now.... to 65

Please help us out.
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 65 total points
ID: 6519263
Zorxx, sorry for taking so long to get back. The code you have should work equally well for MDI Child forms as for the MDIForm itself. To disable the child form's restore button call the appropriate function:

MaxEnabled(MDIChildForm) = False

Though for some reason it still doesn't look as if it is disabled even though it is!
0
 

Author Comment

by:Zorxx
ID: 6522260
Thanks TimCottee, you are absolutely right...
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now