Solved

how to remove the minimized/maximized button of a MDIForm?

Posted on 2002-03-04
13
395 Views
Last Modified: 2008-02-01
how can I remove the minimized/maximized button of a MDIForm, but preserve the close button?
0
Comment
Question by:eugeneng
  • 6
  • 3
  • 2
  • +2
13 Comments
 
LVL 1

Expert Comment

by:Madmarlin
ID: 6841059
Dont they have a MinButton and MaxButton property you can set to false???????
0
 
LVL 1

Expert Comment

by:Madmarlin
ID: 6841063
Sorry didnt realise those properties dont exsist..
0
 
LVL 15

Expert Comment

by:Eyal
ID: 6841101
change the form BorderStyle property value to Fixed Single or Fixed Dialog
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 6841962
Hey e,  I see you posted this question to see about your other issue.  I'll be listening to hear the answer. T
0
 

Expert Comment

by:warlox
ID: 6842017
<<ping>>
0
 

Author Comment

by:eugeneng
ID: 6843008
Eya,
  MDIForm doesn't have BorderStyle for you to set!!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:eugeneng
ID: 6843061
Eya,
  MDIForm doesn't have BorderStyle for you to set!!
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 6843656
eugeneng, guess what... I have a solution for you utilizing the same APIs that we used to set the borders on your MDI form to fixed. see: http://www.experts-exchange.com/visualbasic/Q.20272107.html

Amend your code as follows in the MDI Form:

'** = changes added since the code I gave you to get fixed borders

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 nIndex As Long) As Long

Const GWL_STYLE = (-16)
Const WS_THICKFRAME = &H40000
Const WS_MINIMIZEBOX = &H20000  '**
Const WS_MAXIMIZEBOX = &H10000  '**

Private Sub MDIForm_Load()
Dim CurStyle As Long
Dim NewStyle As Long
Dim L As Long  '**
'This code will remove the min and max boxes from the MDI form
L = GetWindowLong(Me.hwnd, GWL_STYLE) '**
L = L And Not (WS_MINIMIZEBOX) '**
L = L And Not (WS_MAXIMIZEBOX) '**
L = SetWindowLong(Me.hwnd, GWL_STYLE, L) '**
'This code will set the borderstyle = fixed
CurStyle = GetWindowLong(MDIForm1.hwnd, GWL_STYLE)
NewStyle = SetWindowLong(MDIForm1.hwnd, GWL_STYLE, CurStyle And Not (WS_THICKFRAME))
End Sub

I think this will take care of all your woes!
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 6843659
eugeneng - This is better... In my haste I did not look carefully enough at what I was doing.  Use this code instead for your MDIForm load:

Private Sub MDIForm_Load()
Dim CurStyle As Long
Dim NewStyle As Long

CurStyle = GetWindowLong(Me.hwnd, GWL_STYLE)
CurStyle = CurStyle And Not (WS_MINIMIZEBOX)
CurStyle = CurStyle And Not (WS_MAXIMIZEBOX)
CurStyle = CurStyle And Not (WS_THICKFRAME)
NewStyle = SetWindowLong(Me.hwnd, GWL_STYLE, CurStyle)
End Sub
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 6843665
e, you may want to leave this code, provided in the referenced question above in your program:

Private Sub MDIForm_Resize()
Static bMsgd As Boolean
Me.WindowState = vbNormal
If Not bMsgd Then
  MsgBox "You are not allowed to resize this window!"
  bMsgd = True
Else
  bMsgd = False
End If
End Sub

The reason is... if you click on the upper left icon of the MDI Form, you STILL have Min & Max options there!  Inclusion of this code will override those if the user discovers them.
0
 
LVL 4

Accepted Solution

by:
trkcorp earned 20 total points
ID: 6843707
E,
To get rid of the close button and the icon dropdown you can add this constant like so:

Const WS_SYSMENU = &H80000

Private Sub MDIForm_Load()
Dim CurStyle As Long
Dim NewStyle As Long
CurStyle = GetWindowLong(Me.hwnd, GWL_STYLE)
CurStyle = CurStyle And Not (WS_MINIMIZEBOX)
CurStyle = CurStyle And Not (WS_MAXIMIZEBOX)
CurStyle = CurStyle And Not (WS_THICKFRAME)
CurStyle = CurStyle And Not (WS_SYSMENU)
NewStyle = SetWindowLong(Me.hwnd, GWL_STYLE, CurStyle)

Then you can rely on your form menu for an exit...  I
0
 

Author Comment

by:eugeneng
ID: 6845838
Excellent!!! you are great trkcorp, thanx alot man.
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 6845848
Hey, You are welcome. I learned a few things too!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

910 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

21 Experts available now in Live!

Get 1:1 Help Now