CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Aug 2003
    Location
    Malaysia
    Posts
    59

    Disable Min,Max and X button in MDI child form

    I want to disable min,max & X button in MDI child form. I try disable this in not MDI child from and its works but not in MDI child form. I get the code in codeguru web.

    Please help.Thanks

  2. #2
    Join Date
    Sep 2006
    Posts
    635

    Re: Disable Min,Max and X button in MDI child form

    may you have to refresh form,

    what is your code?

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Disable Min,Max and X button in MDI child form

    the_magicien : You would need to use the following APIs :
    GetSystemMenu
    EnableMenuItem

  4. #4
    Join Date
    Aug 2003
    Location
    Malaysia
    Posts
    59

    Re: Disable Min,Max and X button in MDI child form

    How do I use that function?

    Thanks

  5. #5
    Join Date
    Nov 2004
    Location
    LA. California Raiders #1 AKA: Gangsta Yoda™
    Posts
    616

    Re: Disable Min,Max and X button in MDI child form

    This will work for the 'x' button and the min/max system menu items of the child form but the titlebar buttons on the child form still seem to function.

    The EnableMenuItem API didnt work either for the min/max.


    Code:
    Option Explicit
    'WRITTEN BY ROBDOG888
    'MDI CHILD FORM
    Private Sub Form_Load()
        'REMOVE THE SYSTEM MENU ITEM - CLOSE
        RemoveMenu GetSystemMenu(Me.hwnd, 0), GetMenuItemCount(GetSystemMenu(Me.hwnd, 0)) - 3, MF_BYPOSITION
        'REMOVE THE MENU SEPARATOR
        RemoveMenu GetSystemMenu(Me.hwnd, 0), GetMenuItemCount(GetSystemMenu(Me.hwnd, 0)) - 3, MF_BYPOSITION
        'REMOVE THE SYSTEM MENU ITEM - MAX
        RemoveMenu GetSystemMenu(Me.hwnd, 0), GetMenuItemCount(GetSystemMenu(Me.hwnd, 0)) - 3, MF_BYPOSITION
        'REMOVE THE SYSTEM MENU ITEM - MIN
        RemoveMenu GetSystemMenu(Me.hwnd, 0), GetMenuItemCount(GetSystemMenu(Me.hwnd, 0)) - 3, MF_BYPOSITION
        'NOTE: THE CODE LEAVES THE "NEXT" MENU ITEM WHICH IS FOR ADVANCING TO THE NEXT CHILD FORM
    End Sub
    Code:
    Option Explicit
    'WRITTEN BY ROBDOG888
    'IN A MODULE
    Public Declare Function RemoveMenu Lib "user32" ( _
                        ByVal hMenu As Long, _
                        ByVal nPosition As Long, _
                        ByVal wFlags As Long) As Long
    
    Public Declare Function GetSystemMenu Lib "user32" ( _
                        ByVal hwnd As Long, _
                        ByVal bRevert As Long) As Long
    
    Public Declare Function GetMenuItemCount Lib "user32.dll" ( _
                        ByVal hMenu As Long) As Long
    
    Public Const MF_BYPOSITION      As Long = &H400&
    VB/Office Guru™ (AKA: Gangsta Yoda™)
    VB Forums - Super Moderator 2001-Present

    Microsoft MVP 2006-2011

    Please use [code]your code goes in here[/code] tags when posting code.

    Senior Software Engineer MCP, BSEE, CET
    VS 2012 Premium, VS 6.0 Enterprise SP6, VSTO, Office Ultimate 2010, Windows 7 Ultimate
    Star Wars Gangsta Rap SE Reputations & Rating Posts Office Primary Interop AssembliesAdvanced VB/Office Guru™ Word SpellChecker™.NETAdvanced VB/Office Guru™ Word SpellChecker™ VB6Outlook Global Address ListVB6/Crystal Report Ex.VB6/CR Print Setup Dialog Ex.

  6. #6
    Join Date
    Jul 2007
    Posts
    71

    Re: Disable Min,Max and X button in MDI child form

    Quote Originally Posted by the_magicien
    I want to disable min,max & X button in MDI child form.
    Please help.Thanks
    If you don't mind, can you tell me why do you want to disable all those buttons.

    actually you want to disable for a particular time or you don't want.

  7. #7
    Join Date
    Nov 2004
    Location
    LA. California Raiders #1 AKA: Gangsta Yoda™
    Posts
    616

    Re: Disable Min,Max and X button in MDI child form

    Probably because they dont want the child forms to be closed or resized seeing that it may allow acess to other child forms either out of turn or create issues in the program if they change child forms without the "Next form" menu.
    VB/Office Guru™ (AKA: Gangsta Yoda™)
    VB Forums - Super Moderator 2001-Present

    Microsoft MVP 2006-2011

    Please use [code]your code goes in here[/code] tags when posting code.

    Senior Software Engineer MCP, BSEE, CET
    VS 2012 Premium, VS 6.0 Enterprise SP6, VSTO, Office Ultimate 2010, Windows 7 Ultimate
    Star Wars Gangsta Rap SE Reputations & Rating Posts Office Primary Interop AssembliesAdvanced VB/Office Guru™ Word SpellChecker™.NETAdvanced VB/Office Guru™ Word SpellChecker™ VB6Outlook Global Address ListVB6/Crystal Report Ex.VB6/CR Print Setup Dialog Ex.

  8. #8
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Disable Min,Max and X button in MDI child form

    Quote Originally Posted by RobDog888
    Probably because they dont want the child forms to be closed or resized seeing that it may allow acess to other child forms either out of turn or create issues in the program if they change child forms without the "Next form" menu.
    If that is the case, it is a direct violation of the MDI user interfice specifications. The OP should switch to a non-MDI architecture.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  9. #9
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Disable Min,Max and X button in MDI child form

    Quote Originally Posted by RobDog888
    The EnableMenuItem API didnt work either for the min/max.
    Hmm, what was I thinking! Man, I give dumb answers sometimes!

    OK, I did find a way to Remove the Child form's Minimize & Maximise buttons!

    This procedure, Removes the Minimize & Maximze buttons on the Child form, and Disables the Close button on the Child form too.

    Code:
    Option Explicit
    
    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 lIndex 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
    
    Const MAXIMIXE_BUTTON = &HFFFEFFFF
    Const MINIMIZE_BUTTON = &HFFFDFFFF
    Const MF_BYPOSITION = &H400
    Const GWL_STYLE = (-16)
    
    Enum RemoveMenuEnum
        rmMove = 1
        rmSize = 2
        rmMinimize = 3
        rmMaximize = 4
        rmClose = 6
    End Enum
    
    
    Private Sub Form_Load()
    Call pRemoveMenu(Me, rmClose)
    Call RemoveChildMenu(Me, rmMaximize)
    Call RemoveChildMenu(Me, rmMinimize)
    Call RemoveChildMenu(Me, rmSize)
    Call RemoveChildMenu(Me, rmMove)
    End Sub
    
    Private Sub RemoveChildMenu(ByVal TargetForm _
        As Form, ByVal MenuToRemove As RemoveMenuEnum)
    
    Dim lSysMenu As Long
    Dim lStyle   As Long
    
    lSysMenu = GetSystemMenu(TargetForm.hWnd, 0&)
    Call RemoveMenu(lSysMenu, MenuToRemove, MF_BYPOSITION)
    
    Select Case MenuToRemove
        Case rmClose
            
            Call RemoveMenu(lSysMenu, MenuToRemove - 1, MF_BYPOSITION)
        Case rmMinimize, rmMaximize
            
            lStyle = GetWindowLong(TargetForm.hWnd, GWL_STYLE)
    
            If MenuToRemove = rmMaximize Then
                lStyle = lStyle And MAXIMIXE_BUTTON
            Else
                lStyle = lStyle And MINIMIZE_BUTTON
            End If
    
            Call SetWindowLong(TargetForm.hWnd, GWL_STYLE, lStyle)
    End Select
    End Sub
    Right, now, you can remove them, but, CPUWizard actually brought up a good point too, why is this functionality needed ¿

  10. #10
    Join Date
    Jul 2007
    Posts
    71

    Talking Re: Disable Min,Max and X button in MDI child form

    I think, if you want to show all those buttons as disabled then only you need codes.

    Otherwise you don't need codes for that. You can do that by handling form's properties.

    Check These properties.

    Form's properties.

    1) BorderStyle (It has 5 style)
    2) ControlBox (remove all those buttons)
    3) MinButton (Disable minimize button)
    4) MaxButton (Disable maximize button)

  11. #11
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Disable Min,Max and X button in MDI child form

    But can you change those properties' settings at run time ¿ No.

  12. #12
    Join Date
    Jul 2007
    Posts
    71

    Re: Disable Min,Max and X button in MDI child form

    Can't change in run time, that's why I asked before, he want to do that in a particular time or not.

  13. #13
    Join Date
    Mar 2010
    Posts
    1

    Re: Disable Min,Max and X button in MDI child form

    Actually the Normal Form Min, Max & X button will disable using the Control Box = False in Form Property Window, bu i want to know how o diable it for MDI Form not for Child could you pls tell me

    thnx

  14. #14
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Disable Min,Max and X button in MDI child form

    selva.spak This thread is over 2 years old.............
    Please start a new thread, thank you!

    I am closing this thread now.

    Hannes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured