In Vs2005 i need to disable the Close button and remove Close Menu and then
reactivate them.
I have found how to disable Close button and remove close menu, but i
haven't found how to reactivate them.
Does someone knows how to reactivate them?
This is how i disable close button and remove close menu:
<DllImport("user32.dll")> Private Shared Function GetSystemMenu(ByVal hWnd
As IntPtr, ByVal wMsg As Boolean) As IntPtr
End Function
<DllImport("user32.dll")> Private Shared Function RemoveMenu(ByVal hWnd As
IntPtr, ByVal uPosition As Int32, ByVal uFlags As Int32) As Boolean
End Function
<DllImport("user32.dll")> Private Shared Function SendMessage(ByVal hWnd As
IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32)
As Int32
End Function
Private Const SC_CLOSE As Int32 = &HF060
Private Const MF_BYCOMMAND As Int32 = 0
Private Const WM_NCACTIVATE As Int32 = &H86
Private Sub DeactivateCloseButtonAndMenu()
Dim hMenu As IntPtr
hMenu = GetSystemMenu(Me.Handle, False)
RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
SendMessage(Me.Handle, WM_NCACTIVATE, 0, 0)
SendMessage(Me.Handle, WM_NCACTIVATE, 1, 0)
End Sub
Thanks.
Bob Butler - 23 Sep 2007 14:40 GMT
> In Vs2005

Signature
You need to ask in a newsgroup with "dotnet" in the name. This group is for
VB 6.0 and earlier and does not include VB.Net or VB 200x.
mr_unreliable - 24 Sep 2007 17:27 GMT
> Does someone knows how to reactivate them?
hi fpsoft,
Did you try putting the sysmenu back the way it was,
and then calling "SetWindowPos" with "SWP_FrameChanged"?
See:
http://www.codeguru.com/forum/showthread.php?t=352963
http://www.vb-helper.com/howto_change_window_style.html
cheers, jw
MikeD - 25 Sep 2007 01:18 GMT
> In Vs2005 i need to disable the Close button and remove Close Menu and
> then reactivate them.
[quoted text clipped - 30 lines]
> SendMessage(Me.Handle, WM_NCACTIVATE, 1, 0)
> End Sub
As Bob said, you should be asking this in a dotnet newsgroup instead of this
one which is for VB6 and under. But the answer, this time, happens to be the
same since this is about a Win32 API function (the calling syntax and how
you declare it are just different than in VB6)
With that said, all you had to do was look at a little bit of documentation,
specifically, the GetSystemMenu function. In fact, if you has declared it
using the "right" parameter names, you probably could have figured it out.
The 2nd parameter of GetSystemMenu SHOULD be bRevert (not wMsg as you used).
Does that give you a clue?
See this:
http://msdn2.microsoft.com/en-us/library/ms647985.aspx

Signature
Mike
Microsoft MVP Visual Basic