Solved

Enable/Grey/Disable close on MDI child window

Posted on 1997-06-23
2
266 Views
Last Modified: 2008-03-06
EASY QUESTION:
How to you grey out/enable the close option in the system
menu of an MDI child window in VB3.
Here's the code I have got, I can enable and grey out the
option but when the option is re-enabled it does not work.
ie. close the window.
Also, how to I disable the user doing ctrl-f4 to close the
child window ?? OnKeyPress ???

Code so far :

' Menu constants and defines
Global Const MF_BYPOSITION = &H400
Global Const MF_ENABLED = &H0
Global Const MF_GRAYED = &H1
Global Const MF_DISABLED = &H2
Global Const MF_STRING = &H0

Declare Function ModifyMenu% Lib "User" (ByVal hmenu%, ByVal nPosition%, ByVal wFlags%, ByVal wIDNewItem%, ByVal lpString As String)
Declare Function DeleteMenu Lib "User" (ByVal hmenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
Declare Function EnableMenuItem Lib "User" (ByVal hmenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
Declare Function GetSystemMenu Lib "User" (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer
Declare Function GetMenuItemID% Lib "User" (ByVal hmenu%, ByVal nPos%)

' Routine
Sub DisableCloseOption(DstForm As Form, bAction As Integer)
    'adjust system menu to disable/enable close
    Dim inthMenu As Integer, intResponse As Integer
    Dim menuID%
    Dim mnuString As String
   
    mnuString = "&Close" & Chr$(9) & "Ctrl-F4"
    inthMenu% = GetSystemMenu(DstForm.hWnd, False)
   
    '**** the function below returns 0 - why ??
    '**** in the SDK help it says that means it is a
    '**** separator - but its not!!
    menuID = GetMenuItemID%(inthMenu, 5)
    If bAction = True Then
        intResponse% = ModifyMenu(inthMenu%, 6, MF_GRAYED Or MF_BYPOSITION, menuID, mnuString)
    Else
        intResponse% = ModifyMenu(inthMenu%, 6, MF_ENABLED Or MF_BYPOSITION, menuID, mnuString)
    End If
End Sub

Any ideas, should be an easy thing to do :-)

Thanks
Andrew
[ajh@jbmsl.co.uk]
0
Comment
Question by:ajh020797
2 Comments
 

Expert Comment

by:PersonX070197
ID: 1427597
have you tried setting the control-box property to true or false? also, as for the ctrl-f4, I think that by turning the control box off you will disable the window being closed. If that doesn't work, setup a timer on your mdi form that checks to see if the form has been closed, if it has been, boot it back up, otherwise do nothing. it's archaic but it works!
0
 
LVL 3

Accepted Solution

by:
ESI earned 30 total points
ID: 1427598
You should check in the Form_QueryUnload event the source that is trying to close the window (MDI parent, Win shutting down, user clicked close button or via menu) and set Cancel = True accordingly.
But the close button (upper-right cross) will never be grayed, I don't think Win95 let it possible.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

706 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