WD97: How to Disable Word Title Bar Close Command and Button

ID: Q192733


The information in this article applies to:


SUMMARY

In Microsoft Word 97 for Windows, there is no built-in functionality for making commands unavailable on the Title Bar Control menus. This article provides a macro you can use to selectively disable some or all of these commands on the Word 97 for Windows application title bar.


MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/refguide/

To disable Title Bar commands in Microsoft Word 97 for Windows on a Microsoft Windows 95, Windows 98, or Windows NT 4.0 system, type the macro code found in this article in the Visual Basic Editor. This code removes the items from the menu listing in the current session of Word and disables the buttons on the right side of the title bar.

After running this code, the Microsoft Word window is locked on the screen, and you cannot move or close it with the mouse. To close Microsoft Word, press ALT+F4. To restore the menu, you must quit Microsoft Word; if WordMail for Microsoft Outlook, Microsoft Outlook Express, or Microsoft Exchange Inbox is running in the background, you must quit these programs, and then restart Microsoft Word.

When using Visual Basic for Applications on system features, this macro uses Win32API code, which gives you greater customization options.

  1. Type the following declare statements in the "General Declarations" selection of the Visual Basic Editor code window in the project you want this to affect:
    
          Declare Function FindWindowA Lib "user32" (ByVal lpClassName$, _
             ByVal lpWindowName As Long) As Long
    
          Declare Function GetFocus Lib "user32" () As Long
    
          Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    
          Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, _
             ByVal bRevert As Long) As Long
    
          Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, _
             ByVal nPos As Long) As Long
    
          Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, _
             ByVal nPosition As Long, ByVal wFlags As Long) As Long 


  2. Type the following code in the same Visual Basic Editor project window. This code can be run as an Auto macro or event, or called by another macro:
    
          Sub RemoveItem()
             Dim hwnd, hMnu, y
             Const MF_BYPOSITION As Long = 1024
             Const MF_GRAYED As Long = 1
             Const MF_DISABLED As Long = 2
             hwnd = FindWindowA("OPUSApp", 0)
             hMnu = GetSystemMenu(hwnd, 0)
             For I = 6 To 0 Step -1
                y = RemoveMenu(hMnu, I, MF_BYPOSITION)
             Next I
          End Sub 


  3. When the variable I equals the following values, that menu item is removed from the list, and the button functionality is disabled on the application title bar:



For additional information, please see the following article in the Microsoft Knowledge Base:
OFF97: How to Run Sample Code from Knowledge Base Articles


Also see the "Microsoft Windows Software Development Kit (SDK) Programmer's Reference" manual.

Additional query words: vba api commandbars toolbar controls


Keywords          : kbwordvba 
Version           : WINDOWS:97
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: April 8, 1999