PDA

Click to See Complete Forum and Search --> : Menus & Control Boxes


Jimbob
Aug 17th, 2000, 09:28 AM
I want to prevent users of my app from closing the form and from having it in an unmaximised state.

i've successfully ghosted out the close and min/max button, but there is still the option to restore on the top left menu. selecting restore from this makes my form into a window. because i have disabled the max button, the form can't be maximised again

is there any way I can turn off themenu at the top left completley, because I don't want to be maximising the form in code whenever the form resize event is fired

Aug 17th, 2000, 10:57 AM
Try this:

Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Any) As Long
Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long

Const MF_STRING = &H0
Const MF_GRAYED = &H1

Private Sub Form_Load()

Me.WindowState = 2
Dim hMenu As Long, hID As Long, hSubMenu As Long

'Get the SystemMenu handle
hMenu = GetSystemMenu(Me.hwnd, 0)
'Get the ID and Handle for the Restore Item
hID = GetMenuItemID(hMenu, 0)
hSubMenu = GetSubMenu(hMenu, 0)
'Disable it
ModifyMenu hMenu, hID, MF_GRAYED, hSubMenu, "Restore"

End Sub

Jimbob
Aug 17th, 2000, 11:17 AM
thanks very much for that, it was a great help - worked first time, too

Aug 17th, 2000, 04:07 PM
No problem. Since the above example disables the system command for maximizing, you do not need to disable the Max button. Even if the user were to press it, nothing would happen.