Catching Arrow Keys in OCX--OnGetDlgCode
Michael & Vicki -- mvp@usaor.net Monday, March 24, 1997 Environment: VC++ 4.2-flat, NT 4.0 Note: I will be changing to VC 4.2b by the time you read this (thanks for the DatTimePick info, B. ekiM) I have been trying to build an OCX (Active X, or whaterver it is called this week) and I am unable to catch the arrow keys. When they are pressed, focus moves to the next/prev control in the tab order. I have referenced MSDN (July 96, latest version on order) and found at least two articles one being Q104637 about trapping the arrow keys. I have created my own OnGetDlgCode and added the WANT_ARROWS (wording may not be exact, I'm writing from memory at home). My version of OnGetDlgCode never gets called, and the arrow keys are still being treated as a focus (tab) change. So what am I missing/doing wrong that prevents me from getting the arrow keys. I don't actually want the arrow keys, I just don't want them to change focus, but only to move the caret. My control is derived from the Edit control. I have used the VC 4.2 control Wizard and the control is being tested/used in a VB4 "app". --Mike
Michael Hupp -- mhupp@ti.lmco.com Thursday, March 27, 1997 [Mini-digest: 2 responses] Hello Mike, I wrote a real simple control and added these two message handlers to my message map: BEGIN_MESSAGE_MAP(CXxxCtrl, COleControl) //{{AFX_MSG_MAP(CXxxCtrl) ON_WM_KEYDOWN() // trap key presses ON_WM_GETDLGCODE() // tell windows I want arrow //}}AFX_MSG_MAP ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties) END_MESSAGE_MAP() And added these two routines to my control: UINT CXxxCtrl::OnGetDlgCode( ) { return DLGC_WANTARROWS; } void CXxxCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default switch ( nChar ) { case VK_UP: case VK_DOWN: case VK_LEFT: case VK_RIGHT: TRACE( "Got Arrow Key\n" ); break; default: break; } COleControl::OnKeyDown(nChar, nRepCnt, nFlags); } And, voila, arrow keys went to my control. Hope this helps, Michael -----Original Message----- From: Pasterik, Michael & Vicki [SMTP:mvp@usaor.net] Sent: Monday, March 24, 1997 8:52 PM To: mfc-l@netcom.com Subject: Catching Arrow Keys in OCX--OnGetDlgCode Environment: VC++ 4.2-flat, NT 4.0 Note: I will be changing to VC 4.2b by the time you read this (thanks for the DatTimePick info, B. ekiM) I have been trying to build an OCX (Active X, or whaterver it is called this week) and I am unable to catch the arrow keys. When they are pressed, focus moves to the next/prev control in the tab order. I have referenced MSDN (July 96, latest version on order) and found at least two articles one being Q104637 about trapping the arrow keys. I have created my own OnGetDlgCode and added the WANT_ARROWS (wording may not be exact, I'm writing from memory at home). My version of OnGetDlgCode never gets called, and the arrow keys are still being treated as a focus (tab) change. So what am I missing/doing wrong that prevents me from getting the arrow keys. I don't actually want the arrow keys, I just don't want them to change focus, but only to move the caret. My control is derived from the Edit control. I have used the VC 4.2 control Wizard and the control is being tested/used in a VB4 "app". --Mike -----From: "Neil A. Van Note"Hello Michael & Vicki, You will want to override PreTranslateMessage for your control and send those to yourself. It would seem that certain containers eat these messages, ie: VB... Something like the following... switch (pMsg->message) { // Trap the arrow keys so we can process them... case WM_KEYDOWN: case WM_KEYUP: switch (pMsg->wParam) { case VK_LEFT: case VK_RIGHT: case VK_UP: case VK_DOWN: this->SendMessage(pMsg->message, pMsg->wParam, pMsg->lParam); return TRUE; } break; } return COleControl::PreTranslateMessage(pMsg); } ---------- From: Pasterik, Michael & Vicki Sent: Monday, March 24, 1997 11:51 PM To: mfc-l@netcom.com Subject: Catching Arrow Keys in OCX--OnGetDlgCode Environment: VC++ 4.2-flat, NT 4.0 Note: I will be changing to VC 4.2b by the time you read this (thanks for the DatTimePick info, B. ekiM) I have been trying to build an OCX (Active X, or whaterver it is called this week) and I am unable to catch the arrow keys. When they are pressed, focus moves to the next/prev control in the tab order. I have referenced MSDN (July 96, latest version on order) and found at least two articles one being Q104637 about trapping the arrow keys. I have created my own OnGetDlgCode and added the WANT_ARROWS (wording may not be exact, I'm writing from memory at home). My version of OnGetDlgCode never gets called, and the arrow keys are still being treated as a focus (tab) change. So what am I missing/doing wrong that prevents me from getting the arrow keys. I don't actually want the arrow keys, I just don't want them to change focus, but only to move the caret. My control is derived from the Edit control. I have used the VC 4.2 control Wizard and the control is being tested/used in a VB4 "app". --Mike
Mike Blaszczak -- mikeblas@nwlink.com Sunday, March 30, 1997 At 23:51 3/24/97 -0500, Pasterik, Michael & Vicki wrote: >Environment: VC++ 4.2-flat, NT 4.0 > >Note: I will be changing to VC 4.2b by the time you read this (thanks for >the DatTimePick info, B. ekiM) >I have been trying to build an OCX (Active X, or whaterver it is called >this week) The name only changed once, and it changed with a major revision of the technology. While it was a little annoying, it's over. >and I am unable to catch the arrow keys. >When they are pressed, >focus moves to the next/prev control in the tab order. I'm embarrassed to recommend it because it is so poorly written. But it looks like the article at http://www.microsoft.com/kb/articles/q132/4/50.htm explains what you need to do. .B ekiM http://www.nwlink.com/~mikeblas/ These words are my own. I do not speak on behalf of Microsoft. One is too many and a million is not enough.
Become an MFC-L member | Вернуться в корень Архива |