如何在Edit实现右键菜单

在Edit父窗口的PreTranslateMessage里面去处理:
C/C++ code
    
    
    
    
BOOL C ** Dlg::PreTranslateMessage(MSG * pMsg) { if ( WM_RBUTTONDOWN == pMsg -> message ) // 截获右键消息 { int iID; HWND hd = (HWND)::GetFocus(); // 取得当前焦点窗口句柄 iID = ::GetDlgCtrlID(hd); // 得到当前焦点窗口的ID if ( iID == IDC_EDIT1 ) // 判断当前窗口是不是要加菜单的Edit窗口 { CEdit * EditWnd = ( CEdit * ) GetDlgItem( iID ); // 取得Edit的窗口指针 CMenu * pMenu; CPoint pt; GetCursorPos( & pt ); pMenu = new CMenu; pMenu -> LoadMenu( IDR_MYEDITMENU ); // 加载菜单资源 CMenu * pMenuPop = pMenu -> GetSubMenu( 0 ); // 一般弹出菜单是资源菜单的第一项 pMenuPop -> TrackPopupMenu( TPM_LEFTALIGN, pt.x, pt.y, this ); delete pMenu; } } return CDialog::PreTranslateMessage(pMsg); }

你可能感兴趣的:(如何在Edit实现右键菜单)