Click here to Skip to main content
12,553,437 members (57,266 online)
Click here to Skip to main content
Add your own
alternative version


35 bookmarked

Subclassed System Menu

, 17 Feb 2004
Rate this:
Please Sign up or sign in to vote.
Implementation of a subclassed system menu for non standard UIs.

Sample Image


The reason for this article is to show a method of subclassing an application's system menu, so that extra menu items can be added and click events can be easily handled. This is my first article submitted to CodeProject and all suggestions, criticisms etc. are welcome.


This all came about after working on an application that didn't have a standard UI, e.g. menus. I needed to show an About dialog for the application, but I didn't have the usual menus and there didn't seem a natural place from which to launch the dialog, so I created this. I have tried to make it as generic as possible so that it adds a menu separator, then a user defined menu item.

When the object is created, it will retrieve the handle for the parent window and append two new menu items, the first being a separator and the second being "About...". Once this has been completed, an overridden WndProc is used to receive the WM_SYSCOMMAND (&H112) message. If the message is invoked by the user selecting the "About..." menu item, the LaunchDialog event is raised.


The object inherits from System.Windows.Forms.NativeWindow to receive the window messages. Also the IDisposible interface is implemented, so we can release our reference to the window handle when the object is destroyed or goes out of scope.

Using the code

The implementation of the object is straight forward and uses a couple of Win32 API calls, e.g. GetSystemMenu and AppendMenu. The object uses standard VB.NET events to notify the parent form that the new system menu item has been clicked. There are many different ways that the event notifications can be implemented including using an interface. There are many other ways but this way does the job.

The code is very easy to use, you just need to declare a module level variable using WithEvents.

Private WithEvents mobjSubclassedSystemMenu As SubclassedSystemMenu

Then instantiate the declared object, passing in two parameters, the first is the parent window handle and the second being the text for the new menu item.

mobjSubclassedSystemMenu = New _ 
  SubclassedSystemMenu(Me.Handle.ToInt32, "&About...")

Next you need to implement the SubclassedSystemMenu event (LaunchDialog).

Private Sub mobjSubclassedSystemMenu_LaunchDialog() _
                         Handles mobjSubclassedSystemMenu.LaunchDialog
    Dim frmNew As New frmAbout

End Sub

And that's it really!


01-31-2004: Initial version.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Mark Woan
United Kingdom United Kingdom
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionHow do I open up the file? Pin
augiesasso10-Apr-05 11:09
memberaugiesasso10-Apr-05 11:09 
GeneralCode is good... Pin
robdogg116-Mar-04 8:34
memberrobdogg116-Mar-04 8:34 
GeneralRe: Code is good... Pin
Mark Woan16-Mar-04 12:47
memberMark Woan16-Mar-04 12:47 
GeneralRe: Code is good... and now better... Pin
Radgar9-Jun-04 15:38
memberRadgar9-Jun-04 15:38 
GeneralRe: Code is good... and now better... Pin
Mark Woan12-Jun-04 0:43
memberMark Woan12-Jun-04 0:43 
GeneralRe: Code is good... Pin
achavez24-Feb-05 15:46
memberachavez24-Feb-05 15:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161021.1 | Last Updated 18 Feb 2004
Article Copyright 2004 by Mark Woan
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid