Friday, October 31, 2008

Windows Mobile API ToolBar

Today I'd like to make some suggestion about CCommandBar class for Windows Mobile 5.0.
You can use MFC menu wrapper class or you can use Windows WINAPI function to get access to the ToolBar


MFC class CCommandBar class has no API to access to menu items and doesn't know how to control the menu. After a brief investigation and experiments with the menu I have got a working code:
 TBBUTTON tbb;
 ::SendMessage(m_oCommandBar.GetSafeHwnd(),     TB_GETBUTTON, 1, (LPARAM)&tbb);
 HMENU hMenu=HMENU(tbb.dwData);
 if(hMenu)
 {
     ::DeleteMenu(hMenu,0,MF_BYPOSITION);

     ::InsertMenu(hMenu,0,MF_BYPOSITION, ID_MENU_FR_SHOWDETAILS, L"Show Details");
 }


Here m_oCommandBar is an instance of CCommandBar. By using windows messages you can access to WINAPI menu and create a dynamic menus :-)

No comments: