Solved

Enable/Grey/Disable close on MDI child window

Posted on 1997-06-23
2
270 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

860 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