Discussion:
How to detect Return key in VC++.NET and MFC
(too old to reply)
Z.K.
2006-06-13 21:45:03 UTC
Permalink
I was wondering if someone could tell me how to trap the Return key in
VC++.NET using MFC? I tried using the pretranslatemessage function, but it
either gave me an exception or locked up my PC. Is there a different way to
do it with VC++.NET?


virtual BOOL PreTranslateMessage(MSG* pMsg);



BOOL CT45679View::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class


//if return key is pressed or scanned
if((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_RETURN) )
{
//do something

}

Return CT45679View::PreTranslateMessage(pMsg);

}
Z.K.
2006-06-13 22:31:10 UTC
Permalink
I am not sure if this is the best way to do it, but this seems to work.



Z.K.



BOOL CT45662_BLView::PreTranslateMessage(MSG* pMsg)

{

// TODO: Add your specialized code here and/or call the base class

if(pMsg->message==WM_KEYDOWN)

{

if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE)

{

pMsg->wParam=NULL ;

MessageBox("Return");

return true;

}

}


return false;

}
Post by Z.K.
I was wondering if someone could tell me how to trap the Return key in
VC++.NET using MFC? I tried using the pretranslatemessage function, but it
either gave me an exception or locked up my PC. Is there a different way to
do it with VC++.NET?
virtual BOOL PreTranslateMessage(MSG* pMsg);
BOOL CT45679View::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
//if return key is pressed or scanned
if((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_RETURN) )
{
//do something
}
Return CT45679View::PreTranslateMessage(pMsg);
}
Loading...