有一个多级菜单,我知道它的HMENU,我用这样的方法去得到它的当前选中项,在有子项的那一项菜单用键盘上的左右键一切换就挂掉,求安全的方法: int nItem = GetMenuItemCount(m_hMenu);

while (nItem--)
{
if (GetMenuState(m_hMenu, nItem, MF_BYPOSITION) & MF_HILITE)
return nItem;
} return -1; 是有子菜单的那一项用键盘<--/-->切换几次就挂了!
能给个完整答案的马上结贴给分,在线等,谢谢。

解决方案 »

  1.   

    WM_MENUCOMMAND
    The WM_MENUCOMMAND message gives you a handle to the menu—so you can access the menu data in the MENUINFO structure—and also gives you the index of the selected item, which is typically what applications need. In contrast, the WM_COMMAND message gives you the menu item identifier.http://msdn.microsoft.com/en-us/library/windows/desktop/ms647603(v=vs.85).aspx
      

  2.   

    WM_MENUCOMMAND
    这个消息是父窗口才能得到,我是在菜单内部处理,有没有函数遍历的方法得到。