MAKNIGHT71
IS-IT--Management
The old code I have used in the past does not appear to work under either Windows XP or VB.NET. I'm not certain which is the culprit. The following code has always removed the Close System Menu item for me, but it is only removing the separator no matter what the position value is. It appends a new menu item just fine.
maknight
' External system DLL function declarations
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal bRevert As Boolean) As Integer
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Integer) As Integer
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As String) As Integer
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Public Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Integer) As Integer
' External system constants declaration
Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000
Private Const WM_SYSCOMMAND = &H112
' Remove Close system menu item and add menu item(s)
Dim hSysMenu As System.Int32 = GetSystemMenu(Me.Handle.ToInt32, False)
RemoveMenu(hSysMenu, (GetMenuItemCount(hSysMenu) - 1), MF_BYPOSITION)
AppendMenu(hSysMenu, 0, 1000, "View DWG Database..."
DrawMenuBar(Me.Handle.ToInt32)
maknight
' External system DLL function declarations
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal bRevert As Boolean) As Integer
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Integer) As Integer
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As String) As Integer
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Public Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Integer) As Integer
' External system constants declaration
Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000
Private Const WM_SYSCOMMAND = &H112
' Remove Close system menu item and add menu item(s)
Dim hSysMenu As System.Int32 = GetSystemMenu(Me.Handle.ToInt32, False)
RemoveMenu(hSysMenu, (GetMenuItemCount(hSysMenu) - 1), MF_BYPOSITION)
AppendMenu(hSysMenu, 0, 1000, "View DWG Database..."
DrawMenuBar(Me.Handle.ToInt32)