?
Solved

Enable/Grey/Disable close on MDI child window

Posted on 1997-06-23
2
Medium Priority
?
275 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 60 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

752 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