WD97: How to Turn Off Word Title Bar Close Command and Button (192733)



The information in this article applies to:

  • Microsoft Word 97 for Windows

This article was previously published under Q192733

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 that you can use to selectively turn off some or all of these commands on the Word 97 for Windows title bar.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements. To turn off title bar commands in Microsoft Word 97 for Windows on a Microsoft Windows 95, Microsoft Windows 98, or Microsoft Windows NT 4.0 system, type the macro code below in the Visual Basic Editor. This code removes the items from the menu in the current session of Word and turns off the buttons on the right side of the title bar.

After you run 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 you use 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. You can run this code as an Auto macro or event, or call it from 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 any of the following values, the corresponding menu item is removed from the list, and the button turned off on the program's title bar:
    • Close command = 6.
    • Separator line = 5.
    • Maximize command = 4.
    • Minimize command = 3.
    • Size command = 2.
    • Move command = 1.
    • Restore command = 0.
For additional information, please click the article number below to view the article in the Microsoft Knowledge Base:

173707 OFF97: How to Run Sample Code from Knowledge Base Articles

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

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbhowto KB192733