第一段代码:
void CMyDrawView::OnContextMenu(CWnd* pWnd, CPoint point) 
{
// TODO: Add your message handler code here
CMenu menu;
menu.LoadMenu(IDR_MAINFRAME);
menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, 
      point.y,this);//可以让菜单跟踪鼠标左键或右键还可以选择对其方式
}
第二段代码:
void CMyDrawView::OnContextMenu(CWnd* pWnd, CPoint point) 
{
// TODO: Add your message handler code here
CMenu menu;
menu.LoadMenu(IDR_MAINFRAME);
menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, 
      point.y,AfxGetMainWnd());//可以让菜单跟踪鼠标左键或右键还可以选择对其方式
}执行效果反正是不一样,谁能告诉我这里面到底有什么区别?消息是怎样传递的?

解决方案 »

  1.   

    这两段程序不同之处在于:
    menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, 
          point.y,this)
    menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, 
          point.y,AfxGetMainWnd());
    最后一参数,请参阅MSDN对这个参数的说明:
    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. 
    简单的说就由mune发出的消息由哪个窗口接收处理
      

  2.   

    非常感谢,不过你所看到的 区别太明显了,我想知道的是消息是怎样传递的?因为原来的消息是发送给view的,后面哪个是发送给frame的,按道理说他们的处理结果是一样的,frame的消息首先会发送给view来处理,而实际结果却不是这样?!拜托楼上你认真思考!