gpt4 book ai didi

c++ - 如何在编辑控件上获得左键单击通知?

转载 作者:搜寻专家 更新时间:2023-10-31 00:31:02 24 4
gpt4 key购买 nike

我想跟踪在编辑控件上单击鼠标左键的事件。我如下覆盖 PretranslateMessage 函数:

BOOL CMyClass::PreTranslateMessage(Msg* pMsg)
{
switch(pMsg->message)

case WM_LBUTTONDOWN:
{
CWnd* pWnd = GetFocus();
if (pWnd->GetDlgCtrlID == MY_EDIT_CTRL_ID)
{
//Do some thing
}
break;
}
}

问题是当我点击编辑控件时,所有其他控件都被禁用(例如按钮不响应点击等)

我该如何解决这个问题?或者我如何跟踪编辑框上的点击通知?

最佳答案

你需要这个:

BOOL CMyClass::PreTranslateMessage(MSG* pMsg)
{
switch(pMsg->message)
{
case WM_LBUTTONDOWN:
{
CWnd* pWnd = GetFocus();
if (pWnd->GetDlgCtrlID() == MY_EDIT_CTRL_ID) // << typo corrected here
{
//Do some thing
}
break;
}
}

return __super::PreTranslateMessage(pMsg); //<< added
}

顺便说一句,在这里使用 switch 语句有点奇怪。下面的代码是更清晰的 IMO,除非你想添加比 WM_LBUTTONDOWN 更多的案例:

BOOL CMyClass::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_LBUTTONDOWN)
{
CWnd* pWnd = GetFocus();

if (pWnd->GetDlgCtrlID() == MY_EDIT_CTRL_ID)
{
//Do some thing
}
}

return __super::PreTranslateMessage(pMsg); //<< added
}

关于c++ - 如何在编辑控件上获得左键单击通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35062788/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com