How can I enable/disable the ability to resize a form at runtime?
Printable View
How can I enable/disable the ability to resize a form at runtime?
Use the RemoveMenu API function.
VB Code:
Private Declare Function GetSystemMenu Lib "User32" _ (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer Private Declare Function RemoveMenu Lib "User32" (ByVal hMenu _ As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) _ As Integer Const MF_BYPOSITION = &H400 Private Sub Form_Load() RemoveMenu GetSystemMenu(hWnd, 0), 2, MF_BYPOSITION End Sub
Actually, here's full code to both enable and disable resizing.
Try this:
VB Code:
Private Declare Function GetSystemMenu Lib "user32" _ (ByVal hwnd As Integer, ByVal bRevert As Integer) As _ Integer Private Declare Function RemoveMenu Lib "user32" _ (ByVal hMenu As Integer, ByVal nPosition As Integer, _ ByVal wFlags As Integer) As Integer Const MF_BYPOSITION = &H400 Const MF_APPEND = &H100& Private Sub Command1_Click() RemoveMenu GetSystemMenu(hwnd, MF_APPEND), 2, MF_BYPOSITION End Sub Private Sub Form_Load() RemoveMenu GetSystemMenu(hwnd, 0), 2, MF_BYPOSITION End Sub
The suggestion you offered MAtthew returns an OVerflow error at Form_Load, and at COmmand1_Click. Why might this be happening?
Change "Integer" to "Long" as I have done below and it will work
Private Declare Function GetSystemMenu Lib "User32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Declare Function RemoveMenu Lib "User32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
I get a compile coding error with a variable not declared...
BC30451: "hwnd" as not declared. It may be inaccessible due to its
protection level.
How do I correct this?
You start by not replying to a 20 year old thread. Then you have to understand how to read an API declaration. hwnd relates to a Handle to a WiNDow... so you get the window handle that you want to manipulate, and you pass that in as the hwnd value. It doesn't need to be specifically called hwnd... it could be called qwerty or asdf or windwHandle or what ever.
-tg