MFC点击子对话框的编辑框弹出一个窗口

顾小白xx 2012-07-26 12:03:36
怎么解决呢,我看了在编辑框的消息里没有处理鼠标的单击消息,有人说用

BOOL CMyEdit::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_LBUTTONDOWN)
{
HWND hWnd = ::GetFocus();
int iID=::GetDlgCtrlID(hWnd);
if(iID==IDC_EDIT1)
{
AfxMessageBox(_T("1"));
}

else if(iID==IDC_EDIT2)
{
AfxMessageBox(_T("2"));


}

}
return CEdit::PreTranslateMessage(pMsg);
}

可是没反应
我是在编辑框的的主窗口处理的不知道那里错了
...全文
150 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
顾小白xx 2012-07-27
  • 打赏
  • 举报
回复
你这个是可以弹出来 但是只要是左键单击都会相应,不管是主窗口还是子窗口
[Quote=引用 5 楼 的回复:]
BOOL CTtDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class

if (pMsg->message == WM_LBUTTONDOWN)
{
if (pMsg->hwnd == GetDlgItem(IDC_EDIT1)-……
[/Quote]
顾小白xx 2012-07-27
  • 打赏
  • 举报
回复
问题解决了 谢谢各位,。
boylovesports 2012-07-27
  • 打赏
  • 举报
回复
我这有个类似的代码,不过是右键单击弹出菜单的,参考下
void CDlg_KcScan::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

ClientToScreen(&point);

CRect rcImage;
GetDlgItem(IDC_IMAGE)->GetClientRect(rcImage); //该函数检索指定的对话框中的控件句柄
GetDlgItem(IDC_IMAGE)->ClientToScreen(rcImage);

if(rcImage.PtInRect(point))
{
CMenu Menu;
BOOL bRet = Menu.LoadMenu(IDR_MENUTCH);
if(bRet)
{
CPoint pt = point ;

Menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,pt.x,pt.y,this);
Menu.DestroyMenu();
}

}
CDialog::OnRButtonDown(nFlags, point);
}
顾小白xx 2012-07-26
  • 打赏
  • 举报
回复
过滤子类怎么写
BOOL 对话框子类::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_LBUTTONDOWN)
{
HWND hWnd = ::GetFocus();
int iID=::GetDlgCtrlID(hWnd);
if(iID==IDC_EDIT1)
{
AfxMessageBox(_T("1"));
}

else if(iID==IDC_EDIT2)
{
AfxMessageBox(_T("2"));


}

}
return 对话框子类::PreTranslateMessage(pMsg);
}

我写的是这样的上面是错的
  • 打赏
  • 举报
回复
请确保你其它的东西是对,PreTranslateMessage是对的!
BOOL CEditEx::PreTranslateMessage(MSG* pMsg)
{
// TODO: 在此添加专用代码和/或调用基类
if(pMsg->message == WM_LBUTTONDOWN || pMsg->message ==WM_CHAR)
{
HWND hWnd = ::GetFocus();
int iID=::GetDlgCtrlID(hWnd);
if(iID == IDC_EDIT1)
AfxMessageBox(_T("PPPPP"));
}
return CEdit::PreTranslateMessage(pMsg);
}
  • 打赏
  • 举报
回复
使用你的东西测试是OK,重新写CEdit的过滤消息即可!
  • 打赏
  • 举报
回复
BOOL CTtDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class

if (pMsg->message == WM_LBUTTONDOWN)
{
if (pMsg->hwnd == GetDlgItem(IDC_EDIT1)->m_hWnd)
{
TRACE("ddd\n");
}
}

return CDialog::PreTranslateMessage(pMsg);
}
schlafenhamster 2012-07-26
  • 打赏
  • 举报
回复
OnSetFocus

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧