Here is what I am doing right now:
- Code:
SHMENUBARINFO mbi;
memset(&mbi;, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.dwFlags = SHCMBF_EMPTYBAR;
mbi.hwndParent = hwnd;
mbi.nToolBarId = 0;
mbi.hInstRes = 0;
mbi.nBmpId = 0;
mbi.cBmpImages = 0;
#ifdef SHCMBF_COLORBK
mbi.clrBk = 0 ; // PocketPC2002 only
#endif
SHCreateMenuBar(&mbi;);
HWND b = mbi.hwndMB;
#define SHGetMenu(hWndMB) (HMENU)SendMessage((hWndMB), SHCMBM_GETMENU, (WPARAM)0, (LPARAM)0);
HMENU newmenu = CreatePopupMenu();
HMENU menu = SHGetMenu(b);
AppendMenu(menu, MF_STRING | MF_ENABLED | MF_POPUP, 400, L"&File;");
AppendMenu(menu, MF_STRING | MF_ENABLED | MF_POPUP, 500, L"&Edit;");
CommandBar_DrawMenuBar(b);
SHGetMenu return a NULL.
Now here something else I tried (found this snippet on the internet

):
- Code:
void AddMenuItem(HWND bar, int iFlags, UINT iId, UINT iValue, LPTSTR sText)
{
int iLength ; // Real length of the menu item string
TBBUTTON rButton ; // Menu item "button" on the menu bar
wchar_t *lpBuffer ; // Pointer to buffer for text of menu items
int iIndex ;
iLength = wcslen(sText) ;
lpBuffer = (wchar_t *)malloc((iLength + 2) * sizeof(wchar_t)) ;
wcscpy(lpBuffer, sText) ; // Copy the string to the buffer
lpBuffer[iLength+1] = 0;
if ((iIndex = SendMessage(bar, TB_ADDSTRING, 0, (LPARAM) lpBuffer)) == -1) { // Add one string
MessageBox(GetForegroundWindow(), lpBuffer, L"Could not add menu string", MB_OK | MB_ICONHAND) ;
}
free(lpBuffer) ;
// Now add a toolbar button containing the string
rButton.iBitmap = I_IMAGENONE ; // No bitmap
rButton.idCommand = iId ; // ID for WM_COMMAND
rButton.fsState = TBSTATE_ENABLED ; // Enabled button, text
rButton.fsStyle = iFlags | TBSTYLE_AUTOSIZE ; // Autosize the button, flags indicate dropdown
rButton.dwData = iValue ; // Handle to dropdown menu
rButton.iString = iIndex ; // Use this string for text
CommandBar_AddButtons(bar, 1, &rButton;);
}
SHMENUBARINFO mbi;
memset(&mbi;, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.dwFlags = SHCMBF_EMPTYBAR;
mbi.hwndParent = hwnd;
mbi.nToolBarId = 0;
mbi.hInstRes = 0;
mbi.nBmpId = 0;
mbi.cBmpImages = 0;
#ifdef SHCMBF_COLORBK
mbi.clrBk = 0 ; // PocketPC2002 only
#endif
SHCreateMenuBar(&mbi;);
HWND b = mbi.hwndMB;
#define SHGetMenu(hWndMB) (HMENU)SendMessage((hWndMB), SHCMBM_GETMENU, (WPARAM)0, (LPARAM)0);
#define TBSTYLE_NO_DROPDOWN_ARROW 0x0080
HMENU newmenu = CreatePopupMenu();
AddMenuItem(b, TBSTYLE_DROPDOWN | TBSTYLE_NO_DROPDOWN_ARROW, 400, (UINT)newmenu, L"&File;");
HMENU newmenu = CreatePopupMenu();
AddMenuItem(b, TBSTYLE_DROPDOWN | TBSTYLE_NO_DROPDOWN_ARROW, 500, (UINT)newmenu, L"&Edit;");
CommandBar_DrawMenuBar(b);
Here, CommandBar_AddButtons(bar, 1, &rButton;); doesn't work either.
I would really like some help if anybody can. This is a crucial part for my project.
The funny thing is that if I specify a resource ID for my SHCreateMenuBar instead of an emptybar, it works.
Regards,
Kornalius