Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleRemove system menu items from another program
DescriptionThis example shows how to remove system menu items from another program in Visual Basic 6.
Keywordssystem menu, remove menu, remove system menu, other program, RemoveMenus, DeleteMenu, FindWindow
CategoriesControls, Software Engineering
 
When you click the Remove button, the program uses the FindWindow API function to get the target application's window handle. It then calls subroutine RemoveMenus to remove the desired system menus. Use the CheckBoxes to indicate which menus you want to remove.
 
Private Sub cmdRemove_Click()
Dim target_hwnd As Long

    target_hwnd = FindWindow(vbNullString, txtTarget.Text)
    If target_hwnd = 0 Then
        MsgBox "Error finding target application"
        Exit Sub
    End If

    ' Remove the indicated menus.
    RemoveMenus target_hwnd, _
        chkRestore.Value = vbChecked, _
        chkMove.Value = vbChecked, _
        chkSize.Value = vbChecked, _
        chkMinimize.Value = vbChecked, _
        chkMaximize.Value = vbChecked, _
        chkSeparator.Value = vbChecked, _
        chkClose.Value = vbChecked

    MsgBox "OK"
End Sub
 
Subroutine RemoveMenus uses the GetSystemMenu API function to get the other program's menu handle and then uses DeleteMenu to remove the indicated menu items.
 
Private Sub RemoveMenus(ByVal hWnd As Long, ByVal _
    remove_restore As Boolean, ByVal remove_move As _
    Boolean, ByVal remove_size As Boolean, ByVal _
    remove_minimize As Boolean, ByVal remove_maximize As _
    Boolean, ByVal remove_separator As Boolean, ByVal _
    remove_close As Boolean)
Dim hMenu As Long

    ' Get the form's system menu handle.
    hMenu = GetSystemMenu(hWnd, False)

    If remove_close Then DeleteMenu hMenu, 6, MF_BYPOSITION
    If remove_separator Then DeleteMenu hMenu, 5, _
        MF_BYPOSITION
    If remove_maximize Then DeleteMenu hMenu, 4, _
        MF_BYPOSITION
    If remove_minimize Then DeleteMenu hMenu, 3, _
        MF_BYPOSITION
    If remove_size Then DeleteMenu hMenu, 2, MF_BYPOSITION
    If remove_move Then DeleteMenu hMenu, 1, MF_BYPOSITION
    If remove_restore Then DeleteMenu hMenu, 0, _
        MF_BYPOSITION
End Sub
 
Note that RemoveMenus deletes menu items by their positions within the system menu. If you delete an item, that changes the indexes of the remaining items so you may have trouble if you later try to remove other menu items. To keep things simple, remove any menus that you don't want all at once and don't remove any others later.

Also note that removing a system menu item disables but does not remove the corresponding toolbar button. For example, removing the Minimize menu item disables the minimize button but it is still visible and looks enabled.

 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated