这个是比较容易实现的,处理右键消息即可
去:http://www.codeguru.com/editctrl/index.shtml看看有没有源程序
去:http://www.codeguru.com/editctrl/index.shtml看看有没有源程序
解决方案 »
- 我R。 这次真气炸了
- 如何在对话框程序中实现网页浏览
- 在ATL中如何将结构体类型和类转换为COM中的标准类型?(我是新手)请大家多帮帮忙呀!!
- 已知内码,怎样显示汉字?
- VC中如何引用DLL库
- 紧急求助!!
- 静音检测技术
- 大家则偶的标准时什么?
- 初学VC,想问大家一些东东。在主窗体中建立一个ListView和TreeView也可以是两个程序中各含有ListView和TreeView,最好能给出源代码(送100)
- 在程序中模式调用dll中定义的对话框,要注意些什么?
- 帮帮忙,Whe I using CreateComatilbeDC & BitBlt have something wrong
- 求助:那位大哥有串口编程的资料?
class CMyAddressBar : public CComboBoxEx
{
// Construction
public:
CMyAddressBar();// Attributes
public:// Operations
public:
afx_msg void OnEditUrlRedo();
afx_msg void OnUpdateEditUrlRedo(CCmdUI* pCmdUI);
afx_msg void OnEditCopy();
afx_msg void OnEditCut();
afx_msg void OnEditPaste();
afx_msg void OnEditSelectAll();
afx_msg void OnEditUndo();
afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
afx_msg void OnUpdateEditPaste(CCmdUI* pCmdUI);
afx_msg void OnUpdateEditCut(CCmdUI* pCmdUI);
afx_msg void OnUpdateEditCopy(CCmdUI* pCmdUI);
afx_msg void OnUpdateEditUrlSelectAll(CCmdUI* pCmdUI);// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyAddressBar)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
//}}AFX_VIRTUAL// Implementation
public:
virtual ~CMyAddressBar(); // Generated message map functions
protected:
BOOL IsEditFocus(CWnd* pWnd);
BOOL OnNewContextMenu(MSG* pMsg);
//{{AFX_MSG(CMyAddressBar)
//}}AFX_MSG DECLARE_MESSAGE_MAP()
}CMyAddressBar::CMyAddressBar()
{
}CMyAddressBar::~CMyAddressBar()
{
}
BEGIN_MESSAGE_MAP(CMyAddressBar, CComboBoxEx)
//{{AFX_MSG_MAP(CMyAddressBar)
//}}AFX_MSG_MAP
// ON_CONTROL
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CMyAddressBar message handlersvoid CMyAddressBar::OnEditCopy()
{
// TODO: Add your command handler code here
// CEdit* pEdit = GetEditCtrl();
CEdit* pEdit = (CEdit*)GetFocus();
ASSERT(pEdit);
ASSERT_VALID(pEdit);
pEdit->Copy();
}void CMyAddressBar::OnEditCut()
{
// TODO: Add your command handler code here
//CEdit* pEdit = GetEditCtrl();
CEdit* pEdit = (CEdit*)GetFocus();
ASSERT(pEdit);
ASSERT_VALID(pEdit);
pEdit->Cut();
}void CMyAddressBar::OnEditPaste()
{
// TODO: Add your command handler code here
// CEdit* pEdit = GetEditCtrl();
CEdit* pEdit = (CEdit*)GetFocus();
ASSERT(pEdit);
ASSERT_VALID(pEdit);
ASSERT(::IsClipboardFormatAvailable(CF_TEXT));
pEdit->Paste();
}void CMyAddressBar::OnEditSelectAll()
{
// TODO: Add your command handler code here
// CEdit* pEdit = GetEditCtrl();
CEdit* pEdit = (CEdit*)GetFocus();
ASSERT(pEdit);
ASSERT_VALID(pEdit); pEdit->SetSel(0,-1);
}void CMyAddressBar::OnEditUndo()
{
// TODO: Add your command handler code here
CEdit* pEdit = (CEdit*)GetFocus();
ASSERT(pEdit);
ASSERT_VALID(pEdit);
pEdit->Undo();
}BOOL CMyAddressBar::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
switch(pMsg->message)
{
case WM_RBUTTONDOWN:
return OnNewContextMenu(pMsg);
}
return CComboBoxEx::PreTranslateMessage(pMsg);
}BOOL CMyAddressBar::OnNewContextMenu(MSG* pMsg)
{
CPoint point =pMsg->pt;
{
if (point.x == -1 && point.y == -1){
//keystroke invocation
CRect rect;
GetClientRect(rect);
ClientToScreen(rect); point = rect.TopLeft();
point.Offset(5, 5);
} CMenu menu;
VERIFY(menu.LoadMenu(IDR_ADDRESSBARPOPUP)); CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS_CHILD)
pWndPopupOwner = pWndPopupOwner->GetParent(); VERIFY(pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
pWndPopupOwner));
}
return TRUE;
}void CMyAddressBar::OnUpdateEditUndo(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
CWnd* pWnd = GetFocus();
if ( NULL == pWnd || !IsEditFocus( pWnd ) ||
(pWnd->GetStyle() & ES_READONLY) != 0 )
{
pCmdUI->Enable( FALSE );
}
else
{
BOOL bResult = (BOOL)::SendMessage(pWnd->GetSafeHwnd(),EM_CANUNDO,0,0);
pCmdUI->Enable(bResult);
// pCmdUI->Enable(::IsClipboardFormatAvailable(CF_TEXT));
}
}void CMyAddressBar::OnUpdateEditPaste(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
CWnd* pWnd = GetFocus();
if ( NULL == pWnd || !IsEditFocus( pWnd ) ||
(pWnd->GetStyle() & ES_READONLY) != 0 )
{
pCmdUI->Enable( FALSE );
}
else
pCmdUI->Enable(::IsClipboardFormatAvailable(CF_TEXT));
//pCmdUI->Enable(::IsClipboardFormatAvailable(CF_TEXT));
}void CMyAddressBar::OnUpdateEditCut(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here CWnd* pWnd = GetFocus();
if (NULL == pWnd || !IsEditFocus( pWnd ))
{
pCmdUI->Enable( FALSE );
}
else
{
CEdit* pEdit = (CEdit*)pWnd;
int nBeg, nEnd; pEdit->GetSel( nBeg, nEnd );
pCmdUI->Enable( nBeg != nEnd );
}
}void CMyAddressBar::OnUpdateEditCopy(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
CWnd* pWnd = GetFocus();
if (NULL == pWnd || !IsEditFocus( pWnd ))
{
pCmdUI->Enable( FALSE );
}
else
{
CEdit* pEdit = (CEdit*)pWnd;
int nBeg, nEnd; pEdit->GetSel( nBeg, nEnd );
pCmdUI->Enable( nBeg != nEnd );
}
}BOOL CMyAddressBar::IsEditFocus(CWnd* pWnd)
{
ASSERT( pWnd != NULL );
HWND hWnd = pWnd->GetSafeHwnd();
if (hWnd == NULL)
return FALSE; TCHAR szClassName[6];
return ::GetClassName(hWnd, szClassName, 6) &&
_tcsicmp(szClassName, _T("Edit")) == 0;
}void CMyAddressBar::OnEditUrlRedo()
{
// TODO: Add your command handler code here
CEdit* pEdit = (CEdit*)GetFocus();
ASSERT(pEdit);
ASSERT_VALID(pEdit); ::SendMessage(pEdit->GetSafeHwnd(),EM_REDO,0,0);
}void CMyAddressBar::OnUpdateEditUrlRedo(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
CWnd* pWnd = GetFocus();
if ( NULL == pWnd || !IsEditFocus( pWnd ) ||
(pWnd->GetStyle() & ES_READONLY) != 0 )
{
pCmdUI->Enable( FALSE );
}
else
{
BOOL bResult = (BOOL)::SendMessage(pWnd->GetSafeHwnd(),EM_CANREDO,0,0);
pCmdUI->Enable(bResult);
}
}void CMyAddressBar::OnUpdateEditUrlSelectAll(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
CWnd* pWnd = GetFocus();
if ( NULL == pWnd || !IsEditFocus( pWnd ) ||
(pWnd->GetStyle() & ES_READONLY) != 0 )
{
pCmdUI->Enable( FALSE );
}
else
{
CEdit* pEdit = (CEdit*)pWnd;
CString str;
pEdit->GetWindowText(str);
pCmdUI->Enable(!str.IsEmpty());
}
}在主框架实现程序中有
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
ON_COMMAND(ID_EDIT_URL_COPY, OnEditCopy)
ON_COMMAND(ID_EDIT_URL_CUT, OnEditCut)
ON_COMMAND(ID_EDIT_URL_PASTE, OnEditPaste)
ON_COMMAND(ID_EDIT_URL_SELECT_ALL, OnEditSelectAll)
ON_COMMAND(ID_EDIT_URL_UNDO, OnEditUndo)
ON_UPDATE_COMMAND_UI(ID_EDIT_URL_UNDO, OnUpdateEditUndo)
ON_UPDATE_COMMAND_UI(ID_EDIT_URL_PASTE, OnUpdateEditPaste)
ON_UPDATE_COMMAND_UI(ID_EDIT_URL_CUT, OnUpdateEditCut)
ON_UPDATE_COMMAND_UI(ID_EDIT_URL_COPY, OnUpdateEditCopy)
END_MESSAGE_MAP()class CMainFrame : public CMDIFrameWnd
{
DECLARE_DYNAMIC(CMainFrame)
public:
CMainFrame();// Attributes
public:// Operations
public:// Implementation
public:
virtual ~CMainFrame();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected: // control bar embedded members
CMyAddressBar m_wndURLBar;
protected:
afx_msg void OnEditCopy();
afx_msg void OnEditCut();
afx_msg void OnEditPaste();
afx_msg void OnEditSelectAll();
afx_msg void OnEditUndo();
afx_msg void OnEditUrlRedo();
afx_msg void OnUpdateEditUrlRedo(CCmdUI* pCmdUI);
afx_msg void OnUpdateEditUrlSelectAll(CCmdUI* pCmdUI);
afx_msg void OnUpdateEditCopy(CCmdUI* pCmdUI);
afx_msg void OnUpdateEditCut(CCmdUI* pCmdUI);
afx_msg void OnUpdateEditPaste(CCmdUI* pCmdUI);
afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI); //}}AFX_MSG
DECLARE_MESSAGE_MAP()
};void CMainFrame::OnEditCopy()
{
m_wndURLBar.OnEditCopy();
}void CMainFrame::OnEditPaste()
{
m_wndURLBar.OnEditPaste();
}void CMainFrame::OnEditCut()
{
m_wndURLBar.OnEditCut();
}
void CMainFrame::OnEditSelectAll()
{
m_wndURLBar.OnEditSelectAll();
}void CMainFrame::OnEditUndo()
{
m_wndURLBar.OnEditUndo();
}
void CMainFrame::OnUpdateEditCopy(CCmdUI* pCmdUI)
{
m_wndURLBar.OnUpdateEditCopy(pCmdUI);
}
void CMainFrame::OnUpdateEditCut(CCmdUI* pCmdUI)
{
m_wndURLBar.OnUpdateEditCut(pCmdUI);
}
void CMainFrame::OnUpdateEditPaste(CCmdUI* pCmdUI)
{
m_wndURLBar.OnUpdateEditPaste(pCmdUI);
}
void CMainFrame::OnUpdateEditUndo(CCmdUI* pCmdUI)
{
m_wndURLBar.OnUpdateEditUndo(pCmdUI);
}void CMainFrame::OnEditUrlRedo()
{
// TODO: Add your command handler code here
m_wndURLBar.OnEditUrlRedo();
}void CMainFrame::OnUpdateEditUrlRedo(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
m_wndURLBar.OnUpdateEditUrlRedo(pCmdUI);
}void CMainFrame::OnUpdateEditUrlSelectAll(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
m_wndURLBar.OnUpdateEditUrlSelectAll(pCmdUI);
}另外MSDN中好象有篇文章是如何讲述怎么实现编辑框的右键菜单的,可以找来看看.