How to Lock a Form so it Cannot Be MovedID: Q118376
|
This article shows you how to remove the Move and Size menu items from the Visual Basic Control menu (also known as the System Menu) to prevent the form from being moved or sized by the user.
If you do not want the user to be able to move or size your form, you
can remove both or either of the Move or Size menu items from the
Visual Basic control menu by using Windows API function calls. The
GetSystemMenu API Function returns the handle to the Control menu.
Then you can use that handle with the DeleteMenu API function to
modify or delete specific menu items.
' Enter each Declare statement as one, single line:
Declare Function GetSystemMenu Lib "User" (ByVal hWnd%,
ByVal bRevert%) As Integer
Declare Function DeleteMenu Lib "user" (ByVal hMenu%, ByVal iditem%,
ByVal wflags%) As Integer
Const SC_SIZE = &HF000
Const SC_MOVE = &HF010
Const MF_BYCOMMAND = &H0
NOTE: Other constants to remove other menu items in the Control
menu are described in the WIN30API.TXT text file found in the
\VB\WINAPI directory.
Sub Command1_Click ()
Dim hWnd%, hMenu%, Success%
hWnd% = Form1.hWnd
hMenu% = GetSystemMenu(hWnd%, 0)
Success% = deletemenu(hMenu%, SC_SIZE, MF_BYCOMMAND)
Success% = deletemenu(hMenu%, SC_MOVE, MF_BYCOMMAND)
End Sub
Another method, similar to the one presented here is presented in the
following article in the Microsoft Knowledge Base:
Q82876 : How to Disable Close Command in VB Control Menu (System Menu)
Additional query words: 2.00 3.00
Keywords :
Version :
Platform :
Issue type :
Last Reviewed: June 25, 1999