天末凉风

有梦最美,希望相随!

导航

windows mobile 开发总结--菜单

在开发时经常要创建菜单,并且动态显示和隐藏菜单或者是某个子菜单。以下就是实现的方法:

1。创建并显示菜单,先在资源里添加菜单,然后如下代码

SHMENUBARINFO mbi;

ZeroMemory(&mbi, sizeof(SHMENUBARINFO));

mbi.cbSize=sizeof(SHMENUBARINFO);

mbi.hwndParent=m_hWnd;

mbi.hInstRes=::AfxGetInstanceHandle(); mbi.dwFlags=SHCMBF_HMENU|SHCMBF_HIDESIPBUTTON;//隐藏SIP mbi.nToolBarId=IDR_MYMENU; SHCreateMenuBar(&mbi);

2。隐藏菜单 HWND hwnd=::SHFindMenuBar(m_hWnd); if(hwnd!=NULL) ::ShowWindow(hwnd,SW_HIDE);

3。隐藏某个子菜单

TBBUTTONINFO tbbi = {0};

tbbi.cbSize = sizeof(TBBUTTONINFO);

tbbi.dwMask = TBIF_LPARAM | TBIF_BYINDEX;

::SendMessageW(mbi.hwndMB, TB_GETBUTTONINFO,1, (LPARAM)&tbbi); //1为SoftKey1,2为SoftKey2 g_hMenu = (HMENU)tbbi.lParam;//g_hMenu为全局变量,这样就可以在任何地方隐藏子菜单了 EnableMenuItem(g_Menu,ID_TEST,MF_GRAYED);//隐藏子菜单

//显示子菜单 EnableMenuItem(g_Menu,ID_TEST,MF_ENABLED);

4。使某个SoftKey不可用 ::SHEnableSoftkey(mbi.hwndMB,0,TRUE,FALSE); 5。动态修改菜单 ModifyMenu(g_hMenu,ID_TEST,MF_DISABLED|MF_STRING,ID_TEST,L"修改"); DrawMenuBar();

posted on 2008-09-19 18:07  天末凉风  阅读(122)  评论(0编辑  收藏  举报