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
 
 
 
 
 
TitlePrevent the user from resizing another program
Keywordsmenu, resize, minimize, maximize
CategoriesControls, Software Engineering
 
Find the handle of the target window using the FindWindow API function or some other method. Use the GetSystemMenu API function to get the form's system menu. Then use DeleteMenu to remove the Restore, Size, Minimize, and Maximize menu items.

Unfortunately the minimize and maximize buttons will remain on the form and if you hover the mouse over a form edge, you will see the resize cursor. None of them will work, however.

 
Private Sub RemoveMenus(ByVal app_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_seperator As Boolean, _
    ByVal remove_close As Boolean)
Dim hMenu As Long
    
    ' Get the form's system menu handle.
    hMenu = GetSystemMenu(app_hwnd, False)
    
    If remove_close Then DeleteMenu hMenu, 6, MF_BYPOSITION
    If remove_seperator 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

Private Sub cmdRemoveMenus_Click()
Dim app_hwnd As Long

    ' Find the target's hWnd.
    app_hwnd = FindWindow(vbNullString, Text1.Text)

    ' Remove the minimize, maximize, size, and restore menu
    ' commands.
    RemoveMenus app_hwnd, True, False, _
        True, True, True, False, False
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated