呵呵,以前只做过单一菜单,没做过子菜单,看了你的问题,又特定试了一下,实际上也不难:<br>-----------------------------------------------------------------------------------<br><br>STDMETHODIMP TShellExt::QueryContextMenu( HMENU hMenu,UINT indexMenu,<br> UINT idCmdFirst,UINT idCmdLast,<br> UINT uFlags)<br>{<br> <br> //根据MSDN的说明,必须从indexMenu位置开始插入菜单,并且菜单的标识符必须在idCmdFirst和idCmdLast之间<br><br><br> int idCmd=idCmdFirst;<br> AnsiString MenuItemStr="定制菜单2";<br><br> MENUITEMINFO mii;<br> char *MenuStr = "定制菜单1";<br><br> HMENU hNewMenu = CreateMenu();<br><br> AppendMenu(hNewMenu,MF_STRING,idCmd++,"子菜单1");<br> AppendMenu(hNewMenu,MF_STRING,idCmd++,"子菜单2");<br> AppendMenu(hNewMenu,MF_STRING,idCmd++,"子菜单3");<br><br> mii.cbSize = sizeof(MENUITEMINFO);<br> mii.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_ID;<br> mii.wID = idCmd++;<br> mii.fType = MFT_STRING;<br> mii.hSubMenu = hNewMenu;<br> mii.dwTypeData = MenuStr;<br> mii.cch = sizeof(MenuStr);<br><br> //定制菜单1 含有子菜单<br> InsertMenuItem(hMenu,indexMenu++,true,&mii);<br><br> //独立的菜单项<br> InsertMenu(hMenu,indexMenu++,MF_STRING | MF_BYPOSITION,idCmd++,MenuItemStr.c_str());<br><br> return HRESULT(idCmd-idCmdFirst); ////返回值必须等于所增加的菜单数目.<br><br>}<br>//---------------------------------------------------------------------------<br>STDMETHODIMP TShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)<br>{<br> // 根据MSDN的说明,如果你的DLL被资源管理起调用,那么HIWORD(lpcmi->lpVerb)等于0,<br> // 这时候LOWORD(lpcmi->lpVerb)等于菜单标识符,实际上这个值等于所增加的顺序号,<br> // 如0,1,2...<br><br> int idCmd;<br><br> if(!HIWORD(lpcmi->lpVerb))<br> {<br> idCmd=LOWORD(lpcmi->lpVerb);<br><br> switch(idCmd)<br> {<br> case 0: //”子菜单1“被调用<br> case 1: //“子菜单2”被调用<br> case 2: //”子菜单3“被调用<br><br>// case 3: //“定制菜单1”的标识符,因为含有子菜单,所以该菜单项不可能被激活<br><br> case 4: //”定制菜单2“被调用<br> }<br> }<br>} <br>//---------------------------------------------------------------------------<br>//注意这一步不能少。<br><br>STDMETHODIMP TShellExt::GetCommandString(UINT idCmd,<br> UINT uFlags,<br> UINT FAR *reserved,<br> LPSTR pszName,<br> UINT cchMax)<br>{<br>// MessageBox(NULL,AnsiString("IdCmd="+IntToStr(idCmd)).c_str(),NULL,MB_OK | MB_APPLMODAL | MB_ICONWARNING);<br> if(idCmd==0)<br> {<br> lstrcpy(pszName,"子菜单1");<br> }<br> else if(idCmd==1)<br> {<br> lstrcpy(pszName,"子菜单2");<br> }<br> else if(idCmd==2)<br> {<br> lstrcpy(pszName,"子菜单3");<br> }<br><br> return NOERROR;<br>}<br>//---------------------------------------------------------------------------<br><br>另:你在CSDN论坛上的类似问题我也答了。<br><br>题外话 :<br><br>这个论坛怎么没有象CSDN论坛上的"我参与的问题"这一功能,害得我不停的翻页,一直翻到第8页才找到这个问题。<br><br>我操! 以后我再也不想在这里回复了,有问题到CSDN上问吧.<br>