How do I hide the SysMenu on an MDI child form? I'm pulling my hair out on this one and am having no luck.
Thanks...
Printable View
How do I hide the SysMenu on an MDI child form? I'm pulling my hair out on this one and am having no luck.
Thanks...
Turn off the Control Box...
*Sigh* If only it were that easy...
I need to keep on the minimizing, maximizing, and closing option on the form. I just have no need for the sysmenu with the icon....
Anyone else? Please? :-)
Change the border style? If you change it to "sizable toolwindow" you will still have the close box but lose everything else. they will be able to resize the window still with border dragging.
If you want to keep the 3 buttons and lose the context menu altogether, the attached file contains all the info you need to do that.
You can easily do it via subclassing.
Add to a Module
Add to your FormCode:Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const GWL_WNDPROC = (-4)
Private Const WM_NCHITTEST = &H84
Private Const HTSYSMENU = 3
Private Const WM_NCLBUTTONDOWN = &HA1
Global WndProcOld As Long
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wMsg = WM_NCLBUTTONDOWN And wParam = HTSYSMENU Then
Exit Function
End If
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Function
Sub SubClassWnd(hwnd As Long)
WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
End Sub
Sub UnSubclassWnd(hwnd As Long)
SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
WndProcOld& = 0
End Sub
Code:Private Sub Form_Load()
SubClassWnd hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd hwnd
End Sub
Megatron -- Thanks for the code. It works, but in this case I want to hide the SysMenu icon as well as disable it. I will definetely use that code in the future.
Lord Orwell -- Thanks for that attachment. My question is, and this is an "API Newbie" one (hey, gotta start somewhere...):
How am I able to turn off the sysmenu with that?
Do I just try something like:
SetWindowLong(hwnd,WS_SYSMENU,0)?
I see that the sysmenu property is 80000 to use it. So what is its value to not use it? I am unfamiliar with these api's, and reading my Appleman API book fails to clear up my confusion.
I must be making this more difficult than it is.....
Thanks...
Yes, that will work, but it's just the same as disabling the the ControlBox property.
Just incase your interested, here's the code
Code:Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_SYSMENU = &H80000
Private Sub Form_Load()
Dim wStyle As Long
wStyle = GetWindowLong(hwnd, GWL_STYLE)
wStyle = wStyle Xor WS_SYSMENU
SetWindowLong hwnd, GWL_STYLE, wStyle
End Sub
Hmmm... so basically I can either a) disable the whole control box or disable the sysMenu when it pops up but still show the icon? But I can't "hide" that icon and the menu?
How do programs like Word, FileMaker, even Windows clock do it? They still have the "X" at the top right and they do not have a sysMenu....
And thanks for the example Megatron... that helps my understanding of how to use the API....
;)Quote:
Originally posted by Lord Orwell
Change the border style? If you change it to "sizable toolwindow" you will still have the close box but lose everything else. they will be able to resize the window still with border dragging.
And the clock does still have the context menu. Right-click on the title bar to activate it.
The problem with the toolwindow is that it is smaller than the normal window. Know what I mean? The caption at the top is smaller, which makes the windows look somewhat "weird" to some people....
I'll resort to using that if I have to, but I just figured since I've seen programs not use the sysMenu, I figured there was a way...
I am afraid MEGATRON is right. It seems that the sysmenu has to be active for the controls to appear. Annoyingly, the reverse is not true.