Solved

Easy...  Close "X" diable...

Posted on 2003-11-03
3
193 Views
Last Modified: 2010-05-01
Hello, im trying to 'grayout' to disable the X button at the top of a child form in a mdi form, not sure if its diffrent than just any regular form, but if you can' please provide some source.

Thanks...
0
Comment
Question by:dawnyd01
3 Comments
 
LVL 29

Expert Comment

by:leonstryker
Comment Utility
An MDI form is the same as a regular form with the MDICild property set to true.  You should be able to gray out the X button in the same matter .Borderstyle = None should remove Min, Max and "X".
0
 
LVL 28

Assisted Solution

by:vinnyd79
vinnyd79 earned 25 total points
Comment Utility
Give this a try:

Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Const MF_BYPOSITION = &H400&
Private Const MF_DISABLED = &H2&

Private Sub DisableX(frm As Form)
Dim hMenu As Long, nCount As Long

'Get handle to system menu
hMenu = GetSystemMenu(frm.hwnd, 0)

'Get number of items in menu
nCount = GetMenuItemCount(hMenu)

'Remove last item from system menu (last item is 'Close')
Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)

'Redraw menu
DrawMenuBar frm.hwnd
End Sub

' usage
Private Sub Form_Load()
DisableX Form1
End Sub
0
 
LVL 8

Accepted Solution

by:
harris_c earned 25 total points
Comment Utility
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

Private Sub MDIForm_Load()
    'first mdi child
    Form1.Show
    RemoveMenu GetSystemMenu(Form1.hWnd, 0), 6, MF_BYPOSITION
   
    'second mdi child
    Form2.Show
    RemoveMenu GetSystemMenu(Form2.hWnd, 0), 6, MF_BYPOSITION
   
    'need to refresh somehow
    Me.Arrange (2)
End Sub
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

772 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

11 Experts available now in Live!

Get 1:1 Help Now