我在vc6 的对话框中使用了右键菜单,当dialog的模式是pop 和 dialog Frame时 ,右键菜单正常显示。
当把dialog设成 child 和 none 模式,嵌入到一个form后,右键菜单变成了灰色,不能点击,请问怎么解决?

解决方案 »

  1.   

    对话框嵌入form后就不应该用对话框的菜单了吧?应该用主框架的菜单在主框架中响应你的菜单消息
      

  2.   

    可以参看<用MFC做windows编程>,内有示例.
      

  3.   

    WS_CHILD 
    Creates a child window. A window with this style cannot have a menu bar. This style cannot be used with the WS_POPUP style.
    如果窗口设定为child这个窗口就不能有菜单栏。没有菜单栏也就等同于不会处理你的菜单消息,菜单就会灰显。楼主的问题可以在TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner ); 这个函数上
    其最后一个参数如果设定的不对就会出现问题。
    上面这个函数实际上就是BOOL TrackPopupMenu( HMENU hMenu,  UINT uFlags, int x, int y, int nReserved, HWND hWnd,  HWND prcRect); 
    MSDN对这个函数的HWND hWnd参数是这样解释的: 
    hWnd 
    Handle to the window that owns the shortcut menu. This window receives all messages from the menu. The window does not receive a WM_COMMAND message from the menu until the function returns. If you specify TPM_NONOTIFY in the uFlags parameter, the function does not send messages to the window identified by hWnd. However, you must still pass a window handle in hWnd. It can be any window handle from your application. 
    从这段描述可以看出来,这个窗口句柄将处理你菜单的所有消息,而且这个窗口可以是你工程里面的其他任何窗口。楼主既然设定了Child属性以后在自己Dialog窗口不能处理菜单消息,那么可以把这个菜单消息转交给工程中其他的窗口,例如CMainFrame类,因此不要直接写:
    TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this); 
    而是写成:
    //pMainFrame = ......先得到MainFrame的指针。
    TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pMainFrame );  
     
      

  4.   

    非常感谢各位朋友的帮忙。下面是我程序的一部分代码,其中
    while (pWndPopupOwner->GetStyle() & WS_CHILD)
    pWndPopupOwner = pWndPopupOwner->GetParent();这段程序就是判断当前的窗体是否为child,如果是,则寻找其父窗体。我想这样的话应该可以与Tinary3v0说的处理方法相同,可以结果仍然是灰色。
    再次请各位高手帮忙!!
    void CMyDlg::OnContextMenu(CWnd* pWnd, CPoint point) 
    {
    // TODO: Add your message handler code here
    int pos = (int) m_lvPoint.GetFirstSelectedItemPosition()-1;
    if(pos < 0 ) return; if (point.x == -1 && point.y == -1){
    //keystroke invocation
    CRect rect;
    GetClientRect(rect);
    ClientToScreen(rect);

    point = rect.TopLeft();
    point.Offset(5, 5);
    }
    CRect rect;
    m_lvPoint.GetClientRect(rect);
    m_lvPoint.ClientToScreen(rect); CMenu menu;
    VERIFY(menu.LoadMenu(IDR_MENU_POP));
    CMenu* pPopup =NULL;
    CWnd* pWndPopupOwner = this;
    pPopup= menu.GetSubMenu(6);
    ASSERT(pPopup != NULL);
    while (pWndPopupOwner->GetStyle() & WS_CHILD)
    pWndPopupOwner = pWndPopupOwner->GetParent();

    if (point.x < rect.right && point.x > rect.left && point.y < rect.bottom &&
    point.y > rect.top

    {
    pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
    pWndPopupOwner);
    }
    }
      

  5.   

    非常感谢Tinary3v0及各位好友,问题已解决。