Solved

Enable/Grey/Disable close on MDI child window

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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 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…

832 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