PC Review


Reply
Thread Tools Rate Thread

Accessing form control menus

 
 
Tim Greenwood
Guest
Posts: n/a
 
      23rd Jul 2003
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.



 
Reply With Quote
 
 
 
 
Michael Doherty
Guest
Posts: n/a
 
      24th Jul 2003
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("user32", CallingConvention:=CallingConvention.Cdecl)> _
Private Shared Function GetSystemMenu( _
ByVal hwnd As IntPtr, _
ByVal bRevert As Boolean) As IntPtr
End Function

<DllImport("user32", CallingConvention:=CallingConvention.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.ToInt32 = MyMenuItemID Then
MessageBox.Show("MyMenuItem Clicked", "System Menu")
End If
End If
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
_
Handles MyBase.Load
Dim SysMenu As IntPtr = GetSystemMenu(Me.Handle, False)
AppendMenu(SysMenu, MF_SEPARATOR, 0, Nothing)
AppendMenu(SysMenu, 0, MyMenuItemID, "MyNewItem")
End Sub



"Tim Greenwood" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing toolbars or menus from a Dialog form - not possible? jchao123@hotmail.com Microsoft Access Form Coding 2 26th Oct 2006 11:33 AM
Accessing a control from on form to another in MDI Gary Townsend Microsoft VB .NET 2 19th Aug 2005 12:00 AM
NEWBIE Q - accessing a form control from outside of the form class garyspam@gmail.com Microsoft C# .NET 1 22nd May 2005 05:36 PM
Accessing a parent web form control from within a nested user control? Roy Microsoft ASP .NET 1 10th Feb 2005 07:09 PM
accessing a control on one from from within another form =?Utf-8?B?R2VyYWxkaW5lIEhvYmxleQ==?= Microsoft VB .NET 0 2nd Jun 2004 12:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:24 PM.