Solved

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

Posted on 2002-03-04
13
394 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

744 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

13 Experts available now in Live!

Get 1:1 Help Now