A1VBCode Forums

min max disable


http://a1vbcode.com/vbforums/Topic18871.aspx

By Sunil KC - 5/28/2006

for disable Max button, here is some code

'Declaration in Form Level
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 MF_BYPOSITION = &H400&

Public Sub DisableCloseWindowButton(frm As Form)
    Dim hSysMenu As Long
    hSysMenu = GetSystemMenu(frm.hwnd, 0)
    RemoveMenu hSysMenu, 6, MF_BYPOSITION
    RemoveMenu hSysMenu, 5, MF_BYPOSITION
End Sub

Private Sub MDIForm_Load()
    DisableCloseWindowButton Me
End Sub

By jackryan - 5/30/2006

kliner, thanks for your response, i placed your code on my mdi form and only the min button is working, the max button is still not working, can you please help me more? thanks
By Sunil KC - 5/30/2006

Nice job Smile
By Sunil KC - 5/30/2006

But it works for me. I have used following code

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)

Private Sub MDIForm_Load()
    Dim lWnd As Long
    lWnd = GetWindowLong(Me.hwnd, GWL_STYLE)
    lWnd = lWnd And Not (WS_MINIMIZEBOX)
    lWnd = lWnd And Not (WS_MAXIMIZEBOX)
    lWnd = SetWindowLong(Me.hwnd, GWL_STYLE, lWnd)
End Sub

By jackryan - 5/30/2006

its working now if i remove



Me.WindowState = vbMaximized



but i need to maximized my screen, thanks again
By Sunil KC - 5/30/2006

Hi,

I have also tested by maximized the MDI form and I have found that Code works perfectly.

By Keithuk - 5/31/2006

jackryan (5/31/2006)
how will i know if my vb6 have sp6 installed?

When VB starts up look at the splash screen it should say SP6. If you miss it click on Help/About Microsoft Visual Basic... it will show the version there, Microsoft Visual Basic 6.0 (SP6). Wink

By jackryan - 5/31/2006

hmmm it doesnt have anything written on it that says SP6. i'll check it on microsoft, btw thanks again




By Sunil KC - 5/31/2006

Please see the attached project.
By jackryan - 5/31/2006

thank you for your interest in helping me, i tried your attached file and i got the same thing as my previous try. disabling of max button fail though the min button works. thank you again


By Othor - 7/14/2006

Try compiling your program when signed on as admin then run it as guest to see if it works.
By Williamvat - 11/8/2017

SUBJ1
By Thomasdalty - 12/17/2017

SUBJ1
By jackryan - 7/9/2006

I was wondering, when I log on to windows as guest or limited account, the min and max button are disabled but if i log on as admin only the min button is disable, any reason for this?



by the way, its working. only on different accounts. many thanks to all of you
By jackryan - 5/31/2006

ive tried it on a new project and it still didn't work, maybe it has something to do with svb6 ettings or something else, btw thanks again
By Sunil KC - 5/31/2006

I am also using VB6 (SP6) in Windows XP and above code is working perfectly.
By jackryan - 5/31/2006

how will i know if my vb6 have sp6 installed?
By jackryan - 5/29/2006

thanks for your reply but it also didn't work
By Sunil KC - 5/29/2006

Oh, sorry above code works for disable close button.
By Othor - 5/30/2006

Remove Min/Max Buttons From MDI Form
'Remove Min/Max Buttons From MDI Form
'Unlike other forms, MDI forms don't have MinButton and MaxButton
'properties to enable or disable the form's Minimize and Maximize buttons.
'If you add this code to an MDI parent form's Load event, it disables the
'Minimize and Maximize buttons on the MDI form. If you just want to disable
'one or the other, comment out the appropriate line, based on which constant
'you don't need:
 
Sub MDIForm_Load()
    Dim lWnd As Long
    lWnd = GetWindowLong(Me.hwnd, GWL_STYLE)
    lWnd = lWnd And Not (WS_MINIMIZEBOX)
    lWnd = lWnd And Not (WS_MAXIMIZEBOX)
    lWnd = SetWindowLong(Me.hwnd, GWL_STYLE, lWnd)
End Sub
Add this code (which includes the required API declarations) to a BAS module:
 
#If Win32 Then
    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
#Else
    Declare Function SetWindowLong Lib "User" (ByVal hwnd _
        As Integer, ByVal nIndex As Integer, ByVal _
        dwNewLong As Long) As Long
    Declare Function GetWindowLong Lib "User" (ByVal hwnd _
        As Integer, ByVal nIndex As Integer) As Long
#End If
Const WS_MINIMIZEBOX = &H20000
Const WS_MAXIMIZEBOX = &H10000
Const GWL_STYLE = (-16)
By jackryan - 5/27/2006

hello,



with my apps, i'm trying to disable min max button or if possible hide them. ive tried several suggestion but nothing seems to work for me, can somebody help me? thankss