怎样用回车把焦点从一个编辑框切换到下一个编辑框?

warhorse007 2003-10-19 02:41:04
BOOL CWelcomeDlg::PreTranslateMessage(MSG* pMsg)
{
if((pMsg->wParam==WM_KEYDOWN) && (pMsg->lParam == VK_RETURN)) {
CWnd *m_curWnd = GetFocus(); if(m_curWnd != NULL) {
 CWnd *m_nextTable = GetNextDlgTabItem(m_curWnd);
 m_nextTable->SetFocus(); }
return true;
}
return CDialog::PreTranslateMessage(pMsg);
}
这样写哪里有问题?
...全文
76 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
warhorse007 2003-10-20
  • 打赏
  • 举报
回复
多谢各位了!!
孤必有邻 2003-10-19
  • 打赏
  • 举报
回复
你的变量用错了:
if((pMsg->message==WM_KEYDOWN) && (pMsg->wParam == VK_RETURN))
{
CWnd *m_curWnd = GetFocus();
if(m_curWnd != NULL)
{
CWnd *m_nextTable = GetNextDlgTabItem(m_curWnd);
m_nextTable->SetFocus();
}
return TRUE;
}
对于某些获取界面信息的函数,比如取鼠标位置,当前窗口,调试要注意,在断住后执行,就无效了
warhorse007 2003-10-19
  • 打赏
  • 举报
回复
按楼上说的也不会在断点处停下来。
lsl7909 2003-10-19
  • 打赏
  • 举报
回复
那可能是if((pMsg->wParam==WM_KEYDOWN) && (pMsg->lParam == VK_RETURN))有问题了,改成
if(pMsg->wParam==WM_KEYDOWN)试试
warhorse007 2003-10-19
  • 打赏
  • 举报
回复
还是不行。而且我在CWnd *m_curWnd = GetFocus();前设断点,f5以后,按了回车也不会在断点处停下。
auroraiel 2003-10-19
  • 打赏
  • 举报
回复
((CDialog*)this)->GotoDlgCtrl(GetDlgItem(IDC_EDIT_GHS_BH));
//IDC_EDIT_GHS_BH为你要跳转到的编辑控件的ID
yaoha2003 2003-10-19
  • 打赏
  • 举报
回复
我也看不出
但在BOOL CFileSplitterDlg::OnInitDialog()都有这样一句,
return TRUE; // return TRUE unless you set the focus to a control
所以你return FALSE;看看
Paris_Luo 2003-10-19
  • 打赏
  • 举报
回复
改成这样

BOOL CTestDlg::PreTranslateMessage(MSG* pMsg)
{
if((pMsg->message==WM_KEYDOWN) && (pMsg->wParam == VK_RETURN)) {
CWnd *m_curWnd = GetFocus();
if(m_curWnd != NULL){
CWnd *m_nextTable = GetNextDlgTabItem(m_curWnd);
m_nextTable->SetFocus();

}
return true;
}

return CDialog::PreTranslateMessage(pMsg);
}
clarkralf 2003-10-19
  • 打赏
  • 举报
回复
pMsg->message==WM_KEYDOWN!!!!

15,980

社区成员

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

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