Results 1 to 8 of 8

Thread: [VB6] Restrict the maximize button?

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2008
    Location
    Milton Keynes, UK
    Posts
    49

    [VB6] Restrict the maximize button?

    I would like to be able to stop users maximising a form. Can anyone point me to an article or post some code that would allow me to "Grey" it out?

    Regards

    James Roche

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: [VB6] Restrict the maximize button?

    Wouls this work for you?
    Code:
    Option Explicit
    
    Private Const GWL_STYLE = (-16)
    Private Const WS_MAXIMIZEBOX = &H10000
    Private Const WS_THICKFRAME = &H40000
    
    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
    
    Private Sub Form_Load()
    '=======================
    Dim hMenu   As Long
    Dim lStyle As Long
    
        'disable MAXIMIZE button
        lStyle = GetWindowLong(Me.hwnd, GWL_STYLE)
        lStyle = lStyle And Not WS_MAXIMIZEBOX
        Call SetWindowLong(Me.hwnd, GWL_STYLE, lStyle)
        
        'uncomment the following block if you need to make form not resizeable
    '    lStyle = GetWindowLong(Me.hwnd, GWL_STYLE)
    '    lStyle = lStyle And Not WS_THICKFRAME
    '    Call SetWindowLong(Me.hwnd, GWL_STYLE, lStyle)
    
    End Sub

  3. #3
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: [VB6] Restrict the maximize button?

    Why can't you set the maximize property (of the form) to False?
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: [VB6] Restrict the maximize button?

    Quote Originally Posted by Pasvorto
    Why can't you set the maximize property (of the form) to False?
    If you meant to say MaxButton then of course that would work too but only if don't need to change it again.
    For toggling (True/Fals) Max/Min/Close buttons you'll have to use Windows APIs.

  5. #5
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: [VB6] Restrict the maximize button?

    I just took it as a "blanket" can't maximize the form. I may have misunderstood.
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [VB6] Restrict the maximize button?

    I just disable the maximize button of the form in design.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [VB6] Restrict the maximize button?

    SetWindowlacement also will work.
    http://allapi.mentalis.org/apilist/S...lacement.shtml
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Member
    Join Date
    Jun 2008
    Location
    Milton Keynes, UK
    Posts
    49

    Re: [VB6] Restrict the maximize button?

    Lol, i didnt realise the form has a max button property, thats done the trick. Thanks guys

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