March 9, 2021
Hot Topics:

PocketPC-Adding a Permanent Menu Entry to the New Button Menu

  • By Amit Dey
  • Send Email »
  • More Articles »

COM Addin

Custom items can be added to the New button popup menu through a COM addin. There are two ways to add entries to the New button menu—Dynamic and thru a COM Addin. Dynamic means that a notification message (NMN_GETAPPREGKEY) is received by the application when it is in the foreground and the New menu is clicked. The NMNEWMENU pointer passed as a parameter to this notification message can be used to add/modify entries to the New button menu. However, in this article, our discussion is restricted to a COM addin. So, if you are interested in dynamically adding entries, please take a look at the documentation regarding the NMNEWMENU structure and the NMN_GETAPPREGKEY notification message at MSDN.

Thru a COM addin, a new custom entry to the New menu button's popup menu can be created. Such a component is like a Windows shell extension and such a menu addition will be more permanent in nature. You probably have seen the New menu submenus such as New Appointment, New Contact, Notes, Tasks, and so on. These are basically COM addins that appear at all times. The documentation advises that an application should add a single menu item to the New button menu via a COM addin.


As with a shell extension, a custom menu extension needs to add a few Registry entries. The following keys are important.

\CLSID = <menu string>
\Enabled = DWORD

\CLSID\InprocServer = <component dll location>

Getting Started

Here, we'll be creating a COM addin with ATL that adds a custom menu entry to the New button. Next, we'll see how to handle click events in our addin. So, fire up the eVC++ IDE and use the WCE COM ATL Appwizard to create a new ATL COM project. After you have saved the project, use the Insert->New ATL Object menu to add a new ATL Simple object to your project, called MenuHandler (choose all defaults and click OK).

First up, the necessary Registry routines. Go to FileView, open the MenuHandler.rgs resource file, and add the following script.

            ForceRemove {7EB8A0D7-7D17-44CC-A74A-00DC6AB30734} =
                         s 'Clickety'
              val Enabled = d '1'


Luckily, the code to create the Registry keys, necessary to register the COM DLL, has already been added to our Registry script by the ATL Object Wizard and we don't have to bother with those keys.

When our menu entry is clicked, the shell enumerates the NewMenu Registry key based on the CLSID's having created the COM object. You probably would like to do something useful, such as run your app when your 'App Document' menu item is clicked. Here, to handle a 'Clickety' click, we add code to our project's ATL class. The class constructor simply uses the ShellExecuteEx API to launch an instance of the Pocket PC Welcome screen (welcome.exe) executable, like this:

ZeroMemory(&sei, sizeof(SHELLEXECUTEINFO));
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.lpFile = _T("\\windows\\welcome.exe");
sei.nShow = SW_SHOW;

But, in your application, for example, you could run the following code to start your app and open a new document when your 'New App Document' menu is clicked:

sei.lpFile = _T("\\windows\\myapp.exe");
sei.lpParameters = _T("-new");

That's it. To disable the addin menu entry, change Enabled to DWORD 0. To remove it, unregister the component DLL.


MSDN documentation


PPCMenuButton project source - 23 Kb

© Copyright Amit Dey

# # #

Page 2 of 2

This article was originally published on December 12, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date