下面的代码可以屏蔽掉密码框的“Ctrl+V”。BOOL CLoginDlg::PreTranslateMessage(MSG* pMsg) 
{
if(GetFocus()==GetDlgItem(IDC_txtPASSWORD))
{
if(pMsg->wParam =='V' && GetKeyState(VK_CONTROL)<0)
{
//Clear();
}
}
  
return CDialog::PreTranslateMessage(pMsg);
}
又有两个问题要请教:
1、如何让密码框弹出的右键菜单中的那个“粘贴”选项失效?
2、如何截获“WM_PASTE”消息?下面的写法好像不行。BOOL CLoginDlg::PreTranslateMessage(MSG* pMsg) 
{
if(GetFocus()==GetDlgItem(IDC_txtPASSWORD))
{
if(pMsg->wParam==WM_PASTE)
{
AfxMessageBox("pastess");
}
}
  
return CDialog::PreTranslateMessage(pMsg);
}

解决方案 »

  1.   

    I achieve this by deriving a class from CEdit .
    The implementation is below:
    /*Overridet this message to disable the menu*/
    afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
    //}}AFX_MSG
    /*
      Since the Classwizard couldn't help us add handler for WM_PASTE.
      We add it by hand.
    */
    BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
    //{{AFX_MSG_MAP(CMyEdit)
    ON_WM_RBUTTONDOWN()
    //}}AFX_MSG_MAP
    ON_MESSAGE(WM_PASTE,OnPaste)
    END_MESSAGE_MAP()
    /*
      Override this message to disable paste from clipboard.
    */
    afx_msg LRESULT OnPaste(WPARAM p,LPARAM l);/*
       Overridet this message to disable the menu
    */
    void CMyEdit::OnRButtonDown(UINT nFlags, CPoint point) 
    {
    // CEdit::OnRButtonDown(nFlags, point);
             return;
    }
    /*
      Override this message to disable paste from clipboard.
    */LRESULT CMyEdit::OnPaste(WPARAM p,LPARAM l)
    {
     return FALSE;
    }---------------------------------->
    Ok.The work is done.Don't forget the check the "Password" property in the Edit's 
    property dialog.
      

  2.   

    I typed wrong.
    Make a revision:
    Move the line:
    "afx_msg LRESULT OnPaste(WPARAM p,LPARAM l);"
    To the line below:
    "afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
    //}}AFX_MSG
    "