Solved

Enable/Grey/Disable close on MDI child window

Posted on 1997-06-23
2
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

756 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