Reputation: 51
Is there a way to capture arrow keys in a derived CRichEditCtrl class? I request all keys and capture the OnGetCode() and OnChar() commands.
UINT MyRichEditCtrl::OnGetDlgCode()
{
return CRichEditCtrl::OnGetDlgCode() | DLGC_WANTALLKEYS;
}
and
void MyRichEditCtrl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CRichEditCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
...
}
And I match them in the message map..
BEGIN_MESSAGE_MAP(MyRichEditCtrl, CRichEditCtrl)
ON_WM_CHAR()
ON_WM_GETDLGCODE()
END_MESSAGE_MAP()
I am getting most keys, but no arrow keys. I get the same result with OnKeyDown and OnKeyUp events as well. Is there another way to get the arrow keys?
Specifically, I'm interested in knowing if the character at the current cursor position is a parenthesis. The user can change the cursor position by both typing in a character, clicking somewhere in the edit control with a mouse, or by moving the cursor position with an arrow key. I'm thinking if I can detect arrow keys, then I can find out if the cursor is at a parenthesis or not.
Upvotes: 0
Views: 720
Reputation: 19937
Your example code seems wrong. OnChar
should call CRichEditCtrl::OnChar
. I guess you do that in your real code.
Anyway, OnKeyDown
is what you are looking for (arrow keys are not a characters). So, add ON_WM_KEYDOWN()
to your message map and override OnKeyDown
. Look for e.g. VK_LEFT
and VK_RIGHT
.
But... your approach is wrong. What you need is CharFromPos:
CPoint pt = GetCaretPos();
int wordLocation = CharFromPos(pt);
Upvotes: 1