Difference between revisions of "Microsoft KB Archive/107689"

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
 
Line 56: Line 56:
 
=== Microsoft Excel Version 97 and 7.0 ===
 
=== Microsoft Excel Version 97 and 7.0 ===
  
<pre class="codesample">Public Declare Function FindWindow Lib &quot;user32&quot; Alias &quot;FindWindowA&quot; _
+
<pre class="codesample">Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
 
       (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
 
       (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  
Declare Function GetSystemMenu Lib &quot;user32&quot; (ByVal hwnd As Long, _
+
Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, _
 
       ByVal bRevert As Integer) As Integer
 
       ByVal bRevert As Integer) As Integer
  
Declare Function DeleteMenu Lib &quot;user32&quot; (ByVal hMenu As Integer, _
+
Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Integer, _
 
       ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
 
       ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
  
Line 68: Line 68:
 
Sub Disable_Control()
 
Sub Disable_Control()
 
   Dim X As Integer, hwnd As Long
 
   Dim X As Integer, hwnd As Long
   hwnd = FindWindow(&quot;XLMain&quot;, Application.Caption)
+
   hwnd = FindWindow("XLMain", Application.Caption)
 
   For X = 1 To 9
 
   For X = 1 To 9
 
       'Delete the first menu command and loop until
 
       'Delete the first menu command and loop until
Line 82: Line 82:
 
   Dim hwnd As Long
 
   Dim hwnd As Long
 
   'Get the window handle of the Excel application.
 
   'Get the window handle of the Excel application.
   hwnd = FindWindow(&quot;xlMain&quot;, Application.Caption)
+
   hwnd = FindWindow("xlMain", Application.Caption)
 
   'Restore system menu to original state.
 
   'Restore system menu to original state.
 
   hMenu% = GetSystemMenu(hwnd, 1)
 
   hMenu% = GetSystemMenu(hwnd, 1)
Line 90: Line 90:
  
 
<pre class="codesample">'The following procedure disables the Control menu
 
<pre class="codesample">'The following procedure disables the Control menu
Declare Function GetActiveWindow Lib &quot;User&quot; () As Integer
+
Declare Function GetActiveWindow Lib "User" () As Integer
  
Declare Function GetSystemMenu Lib &quot;User&quot; (ByVal hWnd As Integer, _
+
Declare Function GetSystemMenu Lib "User" (ByVal hWnd As Integer, _
 
   ByVal bRevert As Integer) As Integer
 
   ByVal bRevert As Integer) As Integer
  
Declare Function DeleteMenu Lib &quot;User&quot; (ByVal hMenu As Integer, _
+
Declare Function DeleteMenu Lib "User" (ByVal hMenu As Integer, _
 
   ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
 
   ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
  

Latest revision as of 10:23, 20 July 2020

Article ID: 107689

Article Last Modified on 6/11/2007



APPLIES TO

  • Microsoft Excel 97 Standard Edition



This article was previously published under Q107689

SUMMARY

You can use the Microsoft Windows Dynamic Link Libraries (DLLs) to disable the commands in the Microsoft Excel Control menu. For example, you can use these tools to delete the Minimize and Maximize buttons.

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. Microsoft Excel does not have the built-in functionality to modify the Control menu commands. However, you can use the Declare statement in a Visual Basic procedure to call Microsoft Windows functions to disable and restore Control menu items.

The following sample Visual Basic procedure, Disable_Control, disables the entire Control menu in Microsoft Excel. The macro disables the Control menu for the current session of Microsoft Excel (when you restart Microsoft Excel the Control menu will be reset). The procedure RestoreSystemMenu restores the Control menu.

Microsoft Excel Version 97 and 7.0

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
      (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, _
      ByVal bRevert As Integer) As Integer

Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Integer, _
      ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer

'The following procedure disables the Control menu.
Sub Disable_Control()
   Dim X As Integer, hwnd As Long
   hwnd = FindWindow("XLMain", Application.Caption)
   For X = 1 To 9
      'Delete the first menu command and loop until
      'all commands are deleted
      Call DeleteMenu(GetSystemMenu(hwnd, False), 0, 1024)
   Next X
End Sub

'The following procedure restores the Control menu.
'Note that to run this procedure, the Declare statements above
'must be in the module.
Sub RestoreSystemMenu()
   Dim hwnd As Long
   'Get the window handle of the Excel application.
   hwnd = FindWindow("xlMain", Application.Caption)
   'Restore system menu to original state.
   hMenu% = GetSystemMenu(hwnd, 1)
End Sub
                

Microsoft Excel version 5.x

'The following procedure disables the Control menu
Declare Function GetActiveWindow Lib "User" () As Integer

Declare Function GetSystemMenu Lib "User" (ByVal hWnd As Integer, _
   ByVal bRevert As Integer) As Integer

Declare Function DeleteMenu Lib "User" (ByVal hMenu As Integer, _
   ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer

Sub Disable_Control()
   Dim X as Integer
   For X = 1 to 9
      'Delete the first menu command and loop until
      'all commands are deleted
      Call DeleteMenu(GetSystemMenu(GetActiveWindow, False),0,1024)
   Next X
End Sub

'The following procedure restores the Control menu
'Note that to run this procedure, the Declare statements above
'must be in the module
Sub RestoreSystemMenu()
   'get the window handle of the Excel application
   hWnd = GetActiveWindow()
   'restore system menu to original state
   hMenu% = GetSystemMenu(hWnd, 1)
End Sub

Notes

The commands on the control menu are numbered starting at zero. The default control menu items are as follows: Control Menu Restore is item 0, Move is item 1, Size is item 2, and so on. Even if items are deleted, the first item always starts at zero.

To delete individual items from the control menu without deleting the entire menu, you can specify the menu command to delete. For example the following two lines of code when used in place of the For Next loop in the procedure Disable_Control above, will delete the Maximize (item 4) and Minimize (item 3) commands and disable the Maximize and Minimize buttons.

   Call DeleteMenu(GetSystemMenu(GetActiveWindow, False),4,1024)
   Call DeleteMenu(GetSystemMenu(GetActiveWindow, False),3,1024)
                


Additional query words: 5.00c 8.00 XL97 97 call register remove api XL

Keywords: kbprogramming KB107689