PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

How to do menus in WinCE?

Hi,

I am trying to create an empty menu using the CreateRPCommandBar function that is provided with the samples. It works without a resource ID but how do I add menu items to it after it is created? I am trying to do this dynamicly and not using resources? I tried to use AppendMenu and DrawMenuBar but it doesn't work.

Regards,
Kornalius
Try creating and building your menu (CreateMenu, InsertMenu), then add that menu to your command bar (CommandBar_InsertMenubarEx).

Dan East
Hi Dan,

Here is what I tried:

Code:
HWND m = CommandBar_Create(Instance, h, 400);
HMENU menu = CreateMenu();
AppendMenu(menu, MF_STRING, 401, L"MenuItem1\0");
AppendMenu(menu, MF_STRING, 402, L"MenuItem2\0");
CommandBar_InsertMenubarEx(m, Instance, (LPTSTR)menu, 0);
CommandBar_DrawMenuBar(m, 0);
CommandBar_Show(m, true);


But this doesn't work. I show and update my window right after this code.

Regards,
Kornalius.
The second param of CommandBar_InsertMenubarEx should be NULL:

hInst
Handle to the application instance. This parameter must be NULL if pszMenu contains a menu handle. If pszMenu contains a resource name, hinst must contain the instance handle.


Dan East
Hi Dan,

That did the trick. But this menu bar is a top menubar and not the regular bottom menubar. I would like to use the regular bottom menubar just like in the sample eVc projects.

Here is what I had before:

Code:
HWND CreateEmptyRpCommandBar(HWND hwnd, UINT MENU)
{
SHMENUBARINFO mbi;

memset(&mbi;, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.dwFlags = SHCMBF_EMPTYBAR;
mbi.hwndParent = hwnd;
mbi.nToolBarId = 0;
mbi.hInstRes = Instance;
mbi.nBmpId = 0;
mbi.cBmpImages = 0;

if (!SHCreateMenuBar(&mbi;))
return NULL;

return mbi.hwndMB;
}

HMENU menu = CreateMenu();
AppendMenu(menu, MF_STRING, 401, L"MenuItem1\0");
AppendMenu(menu, MF_STRING, 402, L"MenuItem2\0");
HWND m = CreateEmptyRpCommandBar(h, (int)menu);


Obviously the menubar is empty but how can I dynamicly add new menu items to it and redraw it afterward?

Regards,
Kornalius
Doesn't CommandBar_InsertMenubarEx work?

Dan East
Would it work with the menubar at the bottom?

I tried this and it doesn't work:

Code:
HWND m = CreateEmptyRpCommandBar(h, (int)menu);
CommandBar_InsertMenubarEx(m, NULL, (LPTSTR)menu, 0);
CommandBar_DrawMenuBar(m, 0);


Regards,
Kornalius
You're just going to have to experiment. Take a close look at the documentation, as well as the samples, and try different methods until you find what works.

Dan East
Well thanx anyway. Like you said I will have to find some examples somewhere and try to figure it out.

Regards,
Kornalius
Gestalt73 · 25 Feb 2004, 01:16 UTC — CE CommandBar programming is different from Win32 Menus
There are some fundamental differences in the way menus are handled on the PocketPC platform.

The biggest difference is that on PocketPC, the Menubar isn't a menu at all, but a CommandBar that uses text buttons.

Each Button on the commandbar displays an independant popup menu.

This distinction is important, because you don't have a menu handle to any of the submenus from the CreateCommandbar command, you've got an HWND to the commandbar.

You can use the CommandBar HWND handle to update the main MenuBar items only (enable, disable etc).

In order to update any of the submenus (which are actually popup menus), you need the HMENU handle to that specific submenu.

The PocketPC SDK doesn't adequately cover this subject at all, even in their WindowsMobile 2k3 SDK.

Read through the .rc file in a text editor to see what I mean.

I can pass along some example code tonight when I get home.

Alan
Hi, yes some samples would be greatly appreciated! It's not very obvious to create menubars in PPC. I would have liked to use the SHCreateMenuBar and use this bar at the bottom for my menus but it seems that only CommandBars works for menus that are dynamicly created. CommandBars are on top which is not standard to the PPC menu system I think.

Regards,
Kornalius