Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Proccessing VK_RETURN in CEdit

134 views
Skip to first unread message

Frank Keck

unread,
Feb 2, 1998, 3:00:00 AM2/2/98
to

Hi there,
I try to create a CEdit control that processes WM_CHAR, VK_RETURN
message itself ( using VC++ 5.0).
I tried out message reflection and overwriting the edit's windowproc,
but it doesn't work.
Does anybody know, how I can get the VK_RETURN into the edit's OnChar
function ??

Thanks for your help !
Frank Keck


Shezan Baig Remove .nospam

unread,
Feb 2, 1998, 3:00:00 AM2/2/98
to

Just a shot in the dark, but try adding ES_WANTRETURN style to the
edit box....

-shezan-

Miwa

unread,
Feb 2, 1998, 3:00:00 AM2/2/98
to

Frank Keck wrote in message <34D5A8F5...@ugs.com>...

>Hi there,
>I try to create a CEdit control that processes WM_CHAR, VK_RETURN
>message itself ( using VC++ 5.0).
>I tried out message reflection and overwriting the edit's windowproc,
>but it doesn't work.
>Does anybody know, how I can get the VK_RETURN into the edit's OnChar
>function ??
>


Try subclassing the edit control. Then you will be able to process all the
messages for the control.

If your edit control is IDC_EDIT1, and you have a member variable in your
class to handle the edit control...

m_MyDialog.m_MyEdit.SubclassDlgItem(IDC_EDIT1, &m_MyDialog);

This will route all messages from the edit through the dialog class. This
also Attaches the window for the edit control to m_MyDialog.m_MyEdit.

Jim Wuerch
(remove the 'miwax' from my address to reply by email)

Girish Bharadwaj [MVP]

unread,
Feb 2, 1998, 3:00:00 AM2/2/98
to

Derive CMyEdit from CEdit.
add WM_GETDLGCODE message handler and
return (DLGC_WANTALLKEYS|DLGC_WANTARROWS|DLGC_WANTCHARS);
Then you can handle VK_RETURN in your OnKeyDown of the CEdit derived
class.
Associate the control on the dialog with CMyEdit.. thats it..

Frank Keck wrote:
>
> Hi there,
> I try to create a CEdit control that processes WM_CHAR, VK_RETURN
> message itself ( using VC++ 5.0).
> I tried out message reflection and overwriting the edit's windowproc,
> but it doesn't work.
> Does anybody know, how I can get the VK_RETURN into the edit's OnChar
> function ??
>

> Thanks for your help !
> Frank Keck

--
Girish Bharadwaj [VC++/MVP]
http://members.tripod.com/~GBharadwaj/index.html
Email :gir...@usa.net

Rail J. Rogut

unread,
Feb 2, 1998, 3:00:00 AM2/2/98
to k...@ugs.com

Frank Keck wrote:
>
> Hi there,
> I try to create a CEdit control that processes WM_CHAR, VK_RETURN
> message itself ( using VC++ 5.0).
> I tried out message reflection and overwriting the edit's windowproc,
> but it doesn't work.
> Does anybody know, how I can get the VK_RETURN into the edit's OnChar
> function ??
>
> Thanks for your help !
> Frank Keck

The code example at: http//home.earthlink.net/~railro/example5.zip
demonstrates how to subclass the CEdit control to handle the VK_RETURN.

You have to overide

UINT CExampleEdit::OnGetDlgCode()
{
return CEdit::OnGetDlgCode()|DLGC_WANTMESSAGE;
}

but then you also have to handle some normal work of the CEdit control
yourself:

void CExampleEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar == VK_TAB) // Handle the TAB key
{
if (::GetKeyState(VK_SHIFT) < 0)
{
(CDialog *)GetParentOwner()->GetNextDlgTabItem(this,
TRUE)->SetFocus();
}
else
{
(CDialog *)GetParentOwner()->GetNextDlgTabItem(this)->SetFocus();
}

return;
}

if (nChar == VK_RETURN)
{
// Do whatever you want to do here... how about tab to the next
control:

(CDialog *)GetParentOwner()->GetNextDlgTabItem(this)->SetFocus();

return;
}

if (nChar == VK_ESCAPE)
{
// Need to cancel the dialog
(CDialog *)GetParentOwner()->SendMessage(WM_CLOSE);
return;
}

CEdit::OnChar(nChar, nRepCnt, nFlags);
}

BTW, to use the control, all you have to do is include the header file
and create a variable of the new class:

// Dialog Data
//{{AFX_DATA(CExampleDlg)
enum { IDD = IDD_EXAMPLE };
CExampleEdit m_CtrlEdit2;
CExampleEdit m_CtrlEdit1;
CString m_szValue1;
CString m_szValue2;
//}}AFX_DATA

There is no need to use SubclassDlgItem().

*****************

Hope this helps.

Rail
--
Recording Engineer/Software Developer
Rail Jon Rogut Software
http://home.earthlink.net/~railro
mailto:rai...@earthlink.net

Joseph M. Newcomer

unread,
Feb 5, 1998, 3:00:00 AM2/5/98
to

Note that VK_RETURN is a virtual key code, whereas '\r' is a character
for the return. It is dangerous to assume that a VK_ code and a
WM_CHAR code are the same (while it works in this case, I've taught
courses in which this difference was the crucial bug the student had
to discover).

You need to process the WM_GETDLGCODE message and return the correct
flags so that the WM_CHAR for return gets routed to you:

int MyDialog::OnGetDlgCode()
{
return CDialog::OnGetDlgCode() | DLGC_WANTRETURN;
}

(My memory is a bit hazy on the return type and parameters, as well as
the DLGC_ code. There are several DLGC_ values, and you may want
other codes as well). Then your subclassing of the CEdit will work (I
just did this last week, you'd think I could remember the codes that
long...)
joe

On Mon, 02 Feb 1998 12:07:33 +0100, Frank Keck <k...@ugs.com> wrote:

>Hi there,
>I try to create a CEdit control that processes WM_CHAR, VK_RETURN
>message itself ( using VC++ 5.0).
>I tried out message reflection and overwriting the edit's windowproc,
>but it doesn't work.
>Does anybody know, how I can get the VK_RETURN into the edit's OnChar
>function ??
>
>Thanks for your help !
>Frank Keck

Joseph M. Newcomer
newc...@flounder.com
http://www3.pgh.net/~newcomer

0 new messages