为什么在弹出式菜单中,无法响应ON_COMMAND

解决方案 »

  1.   

    TrackPopupMenu有一个指定窗口的参数,设为主框架应该就行了
      

  2.   

    这个MENU是在CFormView中弹出的,可是如何在CMainFrame中使用OnDrawItem()来重画这个MENU呢?
      

  3.   

    void CBoardBarView::OnButton9() 
    {
    UINT i;
    //To create the LineType Menu for the first time
    if(!bLineTypeMenu)
        bLineTypeMenu=true;
    else
    pLineTypeMenu->Detach();
    //Load the menu to resource
    pLineTypeMenu->LoadMenu(IDR_MLINETYPE);
    pLineTypeMenu=pLineTypeMenu->GetSubMenu(0);
    //assert the menu item
    ASSERT(pLineTypeMenu);
    //Modify the menu to ownerdraw
    for(i=0;i<pLineTypeMenu->GetMenuItemCount();i++)
    {
    switch(i)//Define the ID of each menu item according the position
    {
    case 0:
    pLineTypeMenu->ModifyMenu(i,MF_BYPOSITION|MF_OWNERDRAW,IDM_LINETYPE0);
    break;
    case 1:
    pLineTypeMenu->ModifyMenu(i,MF_BYPOSITION|MF_OWNERDRAW,IDM_LINETYPE1);
    break;
    case 2:
    pLineTypeMenu->ModifyMenu(i,MF_BYPOSITION|MF_OWNERDRAW,IDM_LINETYPE2);
    break;
    case 3:
    pLineTypeMenu->ModifyMenu(i,MF_BYPOSITION|MF_OWNERDRAW,IDM_LINETYPE3);
    break;
    case 4:
    pLineTypeMenu->ModifyMenu(i,MF_BYPOSITION|MF_OWNERDRAW,IDM_LINETYPE4);
    break;
    }
    }
    //Popup the LineType MENU
    pLineTypeMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON,150,330,this);
    }