From: Matthias Heise on
Hello,

sorry for another new thread of mine.

My app has a command bar with two pop-up menu entries. The first is called
IDM_APPLICATION and the second IDM_NAVIGATION.

To enable or gray a menu entry within the pop-up menu I need
EnableMenuItem(hWndMenu, IDM_BACK, MF_ENABLED).

The problem is how to get the hWndMenu (Type: HMENU) from the command bar. I
tried

TBBUTTONINFO tbbi;
SendMessage(g_hwndCB, TB_GETBUTTONINFO, IDM_NAVIGATION, (LPARAM)&tbbi );
hWndMenu = (HMENU)tbbi.lParam;

or

hWndMenu = (HMENU) SendMessage( hWnd, SHCMBM_GETMENU, 0, 0 );

but both do not work correctly. When I use EnableMenuItem later it has no
effekt.

Is there any better way to do this? The menu is grayed in the beginning and
when I connect my PDA to a remote device it should be enabled.

Thanks

Matthias


From: TJ on
Use SHCreateMenuBar and member hwndMB of your SHMENUBARINFO struct will
contain the handle. Here's an example:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceshellui5/html/wce50lrfSHCreateMenuBar.asp

Matthias Heise wrote:
> Hello,
>
> sorry for another new thread of mine.
>
> My app has a command bar with two pop-up menu entries. The first is called
> IDM_APPLICATION and the second IDM_NAVIGATION.
>
> To enable or gray a menu entry within the pop-up menu I need
> EnableMenuItem(hWndMenu, IDM_BACK, MF_ENABLED).
>
> The problem is how to get the hWndMenu (Type: HMENU) from the command bar. I
> tried
>
> TBBUTTONINFO tbbi;
> SendMessage(g_hwndCB, TB_GETBUTTONINFO, IDM_NAVIGATION, (LPARAM)&tbbi );
> hWndMenu = (HMENU)tbbi.lParam;
>
> or
>
> hWndMenu = (HMENU) SendMessage( hWnd, SHCMBM_GETMENU, 0, 0 );
>
> but both do not work correctly. When I use EnableMenuItem later it has no
> effekt.
>
> Is there any better way to do this? The menu is grayed in the beginning and
> when I connect my PDA to a remote device it should be enabled.
>
> Thanks
>
> Matthias
>
>
From: Matthias Heise on
The generated code (by eMbedded Visual Tools 3.0) uses SHCreateMenuBar but
the hwndMB is a HWND type, not HMENU. That's my problem.

Matthias


From: TJ on
They all should work when casted. Are you checking if it is NULL or not?

Matthias Heise wrote:
> The generated code (by eMbedded Visual Tools 3.0) uses SHCreateMenuBar but
> the hwndMB is a HWND type, not HMENU. That's my problem.
>
> Matthias
>
>
From: Frank Steinmetzger on
Wed, 22 Jun 2005 20:37:56 +0200, Matthias Heise schrob:

> Hello,
> [...]
> The problem is how to get the hWndMenu (Type: HMENU) from the command bar. I
> tried
> hWndMenu = (HMENU) SendMessage( hWnd, SHCMBM_GETMENU, 0, 0 );

> Matthias

I once started a thread with the same question. After some discussion we
came to this conclusion:

// get the handle to the menu
HMENU m=SHGetMenu(mbi.hwndMB);
// and do something with it
CheckMenuItem(m,IDM_ENABLED,MF_BYCOMMAND|MF_CHECKED);

SHGetMenu is a macro which is defined as:
#define SHGetMenu(hWndMB) (HMENU)SendMessage((hWndMB), \
SHCMBM_GETMENU, (WPARAM)0, (LPARAM)0);

Now I see you did the same SendMessage. But it looks to me as though you
send it to the main window (hWnd), but you should send it to the handle
which is assigned to the SHMENUBARINFO.

My code:

HWND CreateRpCommandBar(HWND hwnd)
{
SHMENUBARINFO mbi;

memset(&mbi,0,sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hwnd;
mbi.nToolBarId = IDM_MENU;
mbi.hInstRes = g_hInst;
mbi.nBmpId = 0;
mbi.cBmpImages = 0;

// I'm adding some bitmap buttons here

// and finally:
g_hMenu=(HMENU)SendMessage(
mbi.hwndMB,SHCMBM_GETMENU,
(WPARAM)0,(LPARAM)0);
return mbi.hwndMB;
}

--
GruĂ˝ | Greetings | Qapla'
"All I ask is a tall ship and a star to steer her by."
http://www.stud.tu-ilmenau.de/~frst-ii/