DELETE key and Rich Edit control
Harry Hahne -- hahne@epas.utoronto.ca
Monday, May 20, 1996
VC++ 4.1, Win 95
I am trying to capture the Delete key on OnChar from a CRichEditCtrl
derived class. The rich edit control is set to readonly, but I want
to use the Delete key not to change the contents of the edit control
but to delete the database record which is displayed. However, the
key never shows up at OnChar. Evidently it is trapped by the Rich
Edit control.
The other problem is that I have mapped the period key to another
function, but the Visuall C++ complains if I have a case statement
that includes VK_DELETE, since it thinks that key is the same as the
period key.
Any tips would be appreciated.
Harry Hahne
hahne@epas.utoronto.ca
Chet Murphy -- cmurphy@modelworks.com
Wednesday, May 22, 1996
[Mini-digest: 6 responses]
Harry Hahne wrote:
>
> VC++ 4.1, Win 95
>
> I am trying to capture the Delete key on OnChar from a CRichEditCtrl
> derived class. The rich edit control is set to readonly, but I want
> to use the Delete key not to change the contents of the edit control
> but to delete the database record which is displayed. However, the
> key never shows up at OnChar. Evidently it is trapped by the Rich
> Edit control.
>
> The other problem is that I have mapped the period key to another
> function, but the Visuall C++ complains if I have a case statement
> that includes VK_DELETE, since it thinks that key is the same as the
> period key.
>
> Any tips would be appreciated.
>
> Harry Hahne
> hahne@epas.utoronto.ca
Harry,
You can trap the VK_DELETE key in OnKeyDown.
Hope that helps,
--
--Chet Murphy
ModelWorks Software
cmurphy@modelworks.com
http://www.modelworks.com/express
-----From: "Mike Ward"
Try using OnKeyDown() in your derived class. If you don't see the
delete key there, then use PreTranslateMessage() and you'll should
get the VK_DELETE key in the WM_KEYDOWN message.
-----From: adriano@infocon.cgsoft.softex.br
Hi, Harry. I'm not using the CRichEditCtrl, but I had a similar
problem with CGridControl class.
I resolved my problem using the PreTranslateMessage message handler
function on the CGridControl owner dialog. You will receive the WM_CHAR
message and handle it like you need.
See the following code part:
BOOL CYourDialog::PreTranslateMessage(MSG* pMsg)
{
switch( pMsg->message ){
case WM_CHAR:
if( pMsg->hwnd == your_control_wnd ){
switch( (TCHAR) pMsg->wParam ){
case VK_DELETE:
// put your code here
break; // or return, depending on your need
}
}
break;
}
return CDialog::PreTranslateMessage(pMsg);
}
We hope help you.
Adriano Sergio
Dalmer Junior
-----From: Barry Tannenbaum
Try processing the WM_KEYDOWN and WM_KEYUP messages.
- Barry
--------------------------------------------------------------------------------
3DV Technology, Inc Phone: (603) 595-2200 X228
410 Amherst St., Suite 150 Fax: (603) 595-2228
Nashua, NH 03063 Net: barry@dddv.com
-----From: Brian Jones
Try trapping OnKeyDown instead of OnChar for VK_DELETE. OnKeyDown gets
called before OnChar in a CRichEditCtrl. I haven't tried trapping
keystrokes on a read-only edit before, so I don't know if it will work
while in read-only mode. If not, you might consider not making it
read-only but instead filtering out all keystrokes besides the Delete
(you can change the background color too if you want).
Brian Jones
Bremerton, WA
BrianJ@AppTechSys.com
-----From: Bill McGarry
I just went through this with the Delete key in a CEditView class. There
are several keys which do not make it to the OnChar, such as the delete key
and the insert key. I catch the delete key in OnKeyDown.
>The other problem is that I have mapped the period key to another
>function, but the Visuall C++ complains if I have a case statement
>that includes VK_DELETE, since it thinks that key is the same as the
>period key.
Since the Delete key never makes it to the OnChar, there's no problem here.
And in OnKeyDown (and in PreTranslateMessage), the delete key will be 0x2E
but the period will be 0xBE (and the numeric pad period will be 0x6E). The
delete key will never make it to OnChar and both periods will be 0x2E in
OnChar so you will be able to catch both keys.
William Shakespeare ran into the same problem hundreds of years ago and he
said it best: "2E or not 2E"
Hope that this helps,
Bill McGarry
billm@mail.isc-br.com
| Вернуться в корень Архива
|