Accessing form control menus

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Greenwood

    #1

    Accessing form control menus

    Title says it. Seems there should be an easy way to get a menu object
    reference to the System menu in the upper left corner of a form so I can add
    items to it.



  • Michael Doherty

    #2
    Re: Accessing form control menus

    I believe you'll have to do this the old way, using GetSystemMenu and
    AppendMenu or InsertMenuItem API Calls, then overide WndProc for the
    messages. The following is a very basic VB.Net example:

    <DllImport("use r32", CallingConventi on:=CallingConv ention.Cdecl)> _
    Private Shared Function GetSystemMenu( _
    ByVal hwnd As IntPtr, _
    ByVal bRevert As Boolean) As IntPtr
    End Function

    <DllImport("use r32", CallingConventi on:=CallingConv ention.Cdecl)> _
    Private Shared Function AppendMenu( _
    ByVal hMenu As IntPtr, _
    ByVal uFlags As Integer, _
    ByVal uIDNewItem As Integer, _
    ByVal lpNewItem As String) As Boolean
    End Function

    Private Const WM_SYSCOMMAND As Integer = &H112
    Private Const MF_SEPARATOR As Integer = &H800&
    Private Const MyMenuItemID As Integer = 1001

    Protected Overrides Sub WndProc(ByRef m As System.Windows. Forms.Message)
    MyBase.WndProc( m)
    If m.Msg = WM_SYSCOMMAND Then
    If m.WParam.ToInt3 2 = MyMenuItemID Then
    MessageBox.Show ("MyMenuItem Clicked", "System Menu")
    End If
    End If
    End Sub

    Private Sub Form1_Load(ByVa l sender As Object, ByVal e As System.EventArg s)
    _
    Handles MyBase.Load
    Dim SysMenu As IntPtr = GetSystemMenu(M e.Handle, False)
    AppendMenu(SysM enu, MF_SEPARATOR, 0, Nothing)
    AppendMenu(SysM enu, 0, MyMenuItemID, "MyNewItem" )
    End Sub



    "Tim Greenwood" <tim_greenwood@ yahoo.com> wrote in message
    news:uZjxcQTUDH A.1664@TK2MSFTN GP11.phx.gbl...[color=blue]
    > Title says it. Seems there should be an easy way to get a menu object
    > reference to the System menu in the upper left corner of a form so I can[/color]
    add[color=blue]
    > items to it.
    >
    >
    >[/color]


    Comment

    • Michael Doherty

      #3
      Re: Accessing form control menus

      I believe you'll have to do this the old way, using GetSystemMenu and
      AppendMenu or InsertMenuItem API Calls, then overide WndProc for the
      messages. The following is a very basic VB.Net example:

      <DllImport("use r32", CallingConventi on:=CallingConv ention.Cdecl)> _
      Private Shared Function GetSystemMenu( _
      ByVal hwnd As IntPtr, _
      ByVal bRevert As Boolean) As IntPtr
      End Function

      <DllImport("use r32", CallingConventi on:=CallingConv ention.Cdecl)> _
      Private Shared Function AppendMenu( _
      ByVal hMenu As IntPtr, _
      ByVal uFlags As Integer, _
      ByVal uIDNewItem As Integer, _
      ByVal lpNewItem As String) As Boolean
      End Function

      Private Const WM_SYSCOMMAND As Integer = &H112
      Private Const MF_SEPARATOR As Integer = &H800&
      Private Const MyMenuItemID As Integer = 1001

      Protected Overrides Sub WndProc(ByRef m As System.Windows. Forms.Message)
      MyBase.WndProc( m)
      If m.Msg = WM_SYSCOMMAND Then
      If m.WParam.ToInt3 2 = MyMenuItemID Then
      MessageBox.Show ("MyMenuItem Clicked", "System Menu")
      End If
      End If
      End Sub

      Private Sub Form1_Load(ByVa l sender As Object, ByVal e As System.EventArg s)
      _
      Handles MyBase.Load
      Dim SysMenu As IntPtr = GetSystemMenu(M e.Handle, False)
      AppendMenu(SysM enu, MF_SEPARATOR, 0, Nothing)
      AppendMenu(SysM enu, 0, MyMenuItemID, "MyNewItem" )
      End Sub



      "Tim Greenwood" <tim_greenwood@ yahoo.com> wrote in message
      news:uZjxcQTUDH A.1664@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Title says it. Seems there should be an easy way to get a menu object
      > reference to the System menu in the upper left corner of a form so I can[/color]
      add[color=blue]
      > items to it.
      >
      >
      >[/color]


      Comment

      • Michael Doherty

        #4
        Re: Accessing form control menus

        I believe you'll have to do this the old way, using GetSystemMenu and
        AppendMenu or InsertMenuItem API Calls, then overide WndProc for the
        messages. The following is a very basic VB.Net example:

        <DllImport("use r32", CallingConventi on:=CallingConv ention.Cdecl)> _
        Private Shared Function GetSystemMenu( _
        ByVal hwnd As IntPtr, _
        ByVal bRevert As Boolean) As IntPtr
        End Function

        <DllImport("use r32", CallingConventi on:=CallingConv ention.Cdecl)> _
        Private Shared Function AppendMenu( _
        ByVal hMenu As IntPtr, _
        ByVal uFlags As Integer, _
        ByVal uIDNewItem As Integer, _
        ByVal lpNewItem As String) As Boolean
        End Function

        Private Const WM_SYSCOMMAND As Integer = &H112
        Private Const MF_SEPARATOR As Integer = &H800&
        Private Const MyMenuItemID As Integer = 1001

        Protected Overrides Sub WndProc(ByRef m As System.Windows. Forms.Message)
        MyBase.WndProc( m)
        If m.Msg = WM_SYSCOMMAND Then
        If m.WParam.ToInt3 2 = MyMenuItemID Then
        MessageBox.Show ("MyMenuItem Clicked", "System Menu")
        End If
        End If
        End Sub

        Private Sub Form1_Load(ByVa l sender As Object, ByVal e As System.EventArg s)
        _
        Handles MyBase.Load
        Dim SysMenu As IntPtr = GetSystemMenu(M e.Handle, False)
        AppendMenu(SysM enu, MF_SEPARATOR, 0, Nothing)
        AppendMenu(SysM enu, 0, MyMenuItemID, "MyNewItem" )
        End Sub



        "Tim Greenwood" <tim_greenwood@ yahoo.com> wrote in message
        news:uZjxcQTUDH A.1664@TK2MSFTN GP11.phx.gbl...[color=blue]
        > Title says it. Seems there should be an easy way to get a menu object
        > reference to the System menu in the upper left corner of a form so I can[/color]
        add[color=blue]
        > items to it.
        >
        >
        >[/color]


        Comment

        Working...