my test:
Public Class Form1
Public Const WM_SYSCOMMAND As Int32 = &H112
Public Const MF_BYPOSITION As Int32 = &H400
Public Const MYMENU1 As Int32 = 1000
Public Const MYMENU2 As Int32 = 1001
Dim hSysMenu As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Public Declare Function InsertMenu Lib "user32" Alias "InsertMenuA" _
(ByVal hMenu As IntPtr, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As String) As Boolean
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
If (m.Msg = WM_SYSCOMMAND) Then
Select Case m.WParam.ToInt32
Case MYMENU1
MsgBox("1")
Case MYMENU2
MsgBox("2")
End Select
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
hSysMenu = GetSystemMenu(Me.Handle, False)
InsertMenu(hSysMenu, 5, MF_BYPOSITION, MYMENU1, "My Menu 1")
InsertMenu(hSysMenu, 6, MF_BYPOSITION, MYMENU2, "My Menu 2")
End Sub
End Class
and i get an error:
PInvokeStackImbalance was detected
Message: A call to PInvoke function ‘WindowsApplication1!WindowsApplication1.Form1::GetSystemMenu’ has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
Replace
LongwithIntegerin your declarations.