Re: OnKeyDown not called for VK_DOWN or VK_RIGHT but is called for others.
On Mar 21, 6:10 pm, Joseph M. Newcomer <newco...@flounder.com> wrote:
I find this a little surprising because I use these all the time, and I;ve never seen
failure in the OnKeyDown handlerin terms of key navigation. Could you show the code?
joe
On 21 Mar 2007 12:58:39 -0700, "Harvey" <harve...@juno.com> wrote:
On Mar 21, 11:01 am, "AliR \(VC++ MVP\)" <A...@online.nospam> wrote:
What is OnKey? Is that the WM_KEYDOWN message handler?
If you can catch VK_UP and VK_LEFT then you should be able to do the same
for down and right. Unless something else is intercepting those keys.
Oops! OnKeyDown() is what I meant. How can I get more info from Spy++?
I have just started learning how to use it. It looks like there are
some re-trys for those two keys; that is three (S, R) pairs instead of
one.
Thanks AliR
Harvey
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm
Joe,
Thank you for considering my question.
I have since tried doing what I want in PreTranslateMessage(), and it
works. But to post some code for you (and to try to understand) I left
both functions in with the useful guts removed for troubleshooting
simplification. So the problem is still there that OnKeyDown() is
called for everything I tried except [DOWN] and [RIGHT]. The trace
output is shown at the bottom for 4 letters and the 4 arrow keys. I
added the 'trap' code to get a printout of the return value of the
base class call for only the WM_KEYDOWN messages - all return true. I
noted that OnKeyDown is called during the base call to
CDialog::PreTranslateMessage(). I tried to follow the flow by single
stepping but besides being a lot of code to follow, somewhere it sends
or posts messages so I can't (or don't know how to) follow it anyway.
There is of course much more to my program not shown. There is a
PreTranslateMessage() function in another class, but a breakpoint set
there is not called during the sequence shown below.
Thanks again,
Harvey
class CMagDlg : public CDialog
{
// Construction
public:
CMagDlg(CWnd* pParent = NULL); // standard constructor
// other member data and functions snipped
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMagDlg)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
//{{AFX_MSG(CMagDlg)
// others snipped
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
BOOL CMagDlg::PreTranslateMessage(MSG* pMsg)
{
bool trig = false;
if( pMsg->message == WM_KEYDOWN )
{
TRACE("CMagDlg::PreTranslateMessage(%d)\n", pMsg->lParam );
trig = true;
// Useful code removed for testing
}
BOOL rv = CDialog::PreTranslateMessage(pMsg);
if( trig ) // only interested in WM_KEYDOWN msgs
TRACE("%d\n",rv);
return rv;
}
void CMagDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
TRACE("CMagDlg::OnKeyDown(%d)\n", nChar );
// Useful code removed for testing
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
TRACE output for 'a', 'b', 'c', [UP], [DOWN], [LEFT], [RIGHT] and 'd':
CMagDlg::PreTranslateMessage(136183809)
CMagDlg::OnKeyDown(65)
1
CMagDlg::PreTranslateMessage(137363457)
CMagDlg::OnKeyDown(66)
1
CMagDlg::PreTranslateMessage(137232385)
CMagDlg::OnKeyDown(67)
1
CMagDlg::PreTranslateMessage(155713537)
CMagDlg::OnKeyDown(38)
1
CMagDlg::PreTranslateMessage(156237825)
1
CMagDlg::PreTranslateMessage(155910145)
CMagDlg::OnKeyDown(37)
1
CMagDlg::PreTranslateMessage(156041217)
1
CMagDlg::PreTranslateMessage(136314881)
CMagDlg::OnKeyDown(68)
1