父窗口PreTranslateMessage里过滤WM_LBUTTONDOWN消息利用
BOOL CXXDlg::PreTranslateMessage(MSG* pMsg) 
{
// TODO: Add your specialized code here and/or call the base class
if(WM_LBUTTONDOWN == pMsg->message)
{
CPoint pt;
GetCursorPos(&pt);
ScreenToClient(&pt);
CWnd* pWnd = ChildWindowFromPoint(pt, CWP_ALL);
if(pWnd)
{
CString str;
pWnd->GetWindowText(str);
AfxMessageBox(str);
}
}
return CDialog::PreTranslateMessage(pMsg);
}

解决方案 »

  1.   

    ON_WM_LBUTTONDOWN
    先是获取edit控件相对于父窗体的CRECT,判断点击坐标是否在里面,如果是则按F10显示edit内容
      

  2.   

    调试正确!BOOL CXXXDlg::PreTranslateMessage(MSG* pMsg) 
    {
    //获取鼠标坐标
        CPoint pt;
        GetCursorPos(&pt);
        ScreenToClient(&pt);

    //获取edit与combobox的rect
    CRect rectEdit, rectCombo;
    m_edit.GetWindowRect(&rectEdit);   //获取edit相对于屏幕的位置
    ScreenToClient(rectEdit);          //转化为对话框上的相对位置  m_combo.GetWindowRect(&rectCombo); //获取combobox相对于屏幕的位置
      ScreenToClient(rectCombo);         //转化为对话框上的相对位置 if(rectEdit.PtInRect(pt))   
    {//如果鼠标在Edit控件范围之内
    if (pMsg->wParam == VK_F10)
    {//如果按下F10键,弹出Edit里面的字符串
    CString str;
    m_edit.GetWindowText(str);
    AfxMessageBox(str);
    }
    }
    else if (rectCombo.PtInRect(pt))
    {//如果鼠标在combobox控件范围之内
    if ( pMsg->wParam == VK_F10)
    {//如果按下F10键,弹出combobox里面的字符串
    CString str;
    m_combo.GetWindowText(str);
    AfxMessageBox(str);
    }
    } return CDialog::PreTranslateMessage(pMsg);
    }
      

  3.   

    程序的效果是,当鼠标移动到控件之上,无需按下鼠标左键,直接按F10键后弹出控件中的字符串。PS:
    m_edit、m_combo是控件的变量