gcapwell
asked on
Waiting for a RETURN key in a TEdit.
Hi everyone, I have an application which use the TDialog as the main window. I have a TEdit object which the user can type information. I would like to perform an action if the RETURN key is pressed. How can I intercept the RETURN key message?? I have tried WM_CHAR, WM_SYSCHAR but they don't seem to work. I never enter the EvChar function. Can someone provide some help. Thanks.
Regards,
Gerry
Regards,
Gerry
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
look here, it is in TEdit, derive your special editor
DEFINE_RESPONSE_TABLE1(Ret Edit, TEdit)
EV_WM_KEYDOWN,
END_RESPONSE_TABLE;
good luck
gaohong
DEFINE_RESPONSE_TABLE1(Ret
EV_WM_KEYDOWN,
END_RESPONSE_TABLE;
good luck
gaohong
ASKER
I have done what you said and still receive the following errors:
Error: FUNC.H(140,3):Ambiguous override of virtual base member 'TWindow::GetClassName()': 'TEdit::GetClassName()'
Error: FUNC.H(140,3):Ambiguous override of virtual base member 'TWindow::GetClassName()': 'TDialog::GetClassName()'
To restate my problem. I have a TDialog with a TEdit control (one line of text allowed) and I would like to perform a function when RETURN is hit. I have two seperate response tables DECLARE_RESPONSE_TABLE1(Ed itObjs, TEdit) and DECLARE_RESPONSE_TABLE1(Fu ncDialog,T Dialog) I also have two classes called EditObjs with a function EvKeyDown(UINT,UINT,UINT) as a member and another class FuncDialog. My EvKeyDown() function uses a variable 'X' in my FuncDialog:TDialog class.
How can I receive messages from both TEdit and TDialog and use variables shared by both?? Am I missing something? See below.
DEFINE_RESPONSE_TABLE1(Fun cDialog,TD ialog)
EV_EN_CHANGE(IDC_FREQUENCY ,EditSineW ave),
END_RESPONSE_TABLE;
DECLARE_RESPONSE_TABLE(Fre q);
DEFINE_RESPONSE_TABLE1(Fre q,TEdit)
EV_WM_KEYDOWN,
END_RESPONSE_TABLE;
class EditObjs:TEdit
{
protected:
void EvKeyDown(UINT,UINT,UINT); <-- uses int X
}
class FuncDialog: TDialog
{
other funcs
int X;
}
end.
Error: FUNC.H(140,3):Ambiguous override of virtual base member 'TWindow::GetClassName()':
Error: FUNC.H(140,3):Ambiguous override of virtual base member 'TWindow::GetClassName()':
To restate my problem. I have a TDialog with a TEdit control (one line of text allowed) and I would like to perform a function when RETURN is hit. I have two seperate response tables DECLARE_RESPONSE_TABLE1(Ed
How can I receive messages from both TEdit and TDialog and use variables shared by both?? Am I missing something? See below.
DEFINE_RESPONSE_TABLE1(Fun
EV_EN_CHANGE(IDC_FREQUENCY
END_RESPONSE_TABLE;
DECLARE_RESPONSE_TABLE(Fre
DEFINE_RESPONSE_TABLE1(Fre
EV_WM_KEYDOWN,
END_RESPONSE_TABLE;
class EditObjs:TEdit
{
protected:
void EvKeyDown(UINT,UINT,UINT);
}
class FuncDialog: TDialog
{
other funcs
int X;
}
end.
ASKER
I have done what you said and still receive the following errors:
Error: FUNC.H(140,3):Ambiguous override of virtual base member 'TWindow::GetClassName()': 'TEdit::GetClassName()'
Error: FUNC.H(140,3):Ambiguous override of virtual base member 'TWindow::GetClassName()': 'TDialog::GetClassName()'
To restate my problem. I have a TDialog with a TEdit control (one line of text allowed) and I would like to perform a function when RETURN is hit. I have two seperate response tables DECLARE_RESPONSE_TABLE1(Ed itObjs, TEdit) and DECLARE_RESPONSE_TABLE1(Fu ncDialog,T Dialog) I also have two classes called EditObjs with a function EvKeyDown(UINT,UINT,UINT) as a member and another class FuncDialog. My EvKeyDown() function uses a variable 'X' in my FuncDialog:TDialog class.
How can I receive messages from both TEdit and TDialog and use variables shared by both?? Am I missing something? See below.
DEFINE_RESPONSE_TABLE1(Fun cDialog,TD ialog)
EV_EN_CHANGE(IDC_FREQUENCY ,EditSineW ave),
END_RESPONSE_TABLE;
DECLARE_RESPONSE_TABLE(Edi tObjs);
DEFINE_RESPONSE_TABLE1(Edi tObjs,TEdi t)
EV_WM_KEYDOWN,
END_RESPONSE_TABLE;
class EditObjs:TEdit
{
protected:
void EvKeyDown(UINT,UINT,UINT); <-- uses int X
}
class FuncDialog: TDialog
{
other funcs
int X;
}
end.
Error: FUNC.H(140,3):Ambiguous override of virtual base member 'TWindow::GetClassName()':
Error: FUNC.H(140,3):Ambiguous override of virtual base member 'TWindow::GetClassName()':
To restate my problem. I have a TDialog with a TEdit control (one line of text allowed) and I would like to perform a function when RETURN is hit. I have two seperate response tables DECLARE_RESPONSE_TABLE1(Ed
How can I receive messages from both TEdit and TDialog and use variables shared by both?? Am I missing something? See below.
DEFINE_RESPONSE_TABLE1(Fun
EV_EN_CHANGE(IDC_FREQUENCY
END_RESPONSE_TABLE;
DECLARE_RESPONSE_TABLE(Edi
DEFINE_RESPONSE_TABLE1(Edi
EV_WM_KEYDOWN,
END_RESPONSE_TABLE;
class EditObjs:TEdit
{
protected:
void EvKeyDown(UINT,UINT,UINT);
}
class FuncDialog: TDialog
{
other funcs
int X;
}
end.
I did see the place you handle WM_KEYDOWN in your editor
copy following to a .h file
#ifndef RETEDIT.H
#define RETEDIT.H
#include <owl\edit.h>
#pragma hdrstop
class RetEdit : virtual public TEdit
{
public:
RetEdit::RetEdit(TWindow* parent,
int id,
const char far* text,
int x, int y, int w, int h,
uint textLen = 0,
bool multiline = false,
TModule* module = 0);
~RetEdit() {;}
void EvKeyDown(uint key, uint repeatCount, uint flags);
private: // hidden to prevent accidental copying or assignment
RetEdit(const RetEdit&);
RetEdit& operator =(const RetEdit&);
DECLARE_RESPONSE_TABLE(Ret Edit);
};
#endif
then copy following to .cpp file
#include above .h file
DEFINE_RESPONSE_TABLE1(Ret Edit, TEdit)
EV_WM_KEYDOWN,
END_RESPONSE_TABLE;
RetEdit::RetEdit(TWindow* parent,
int id,
const char far* text,
int x, int y, int w, int h,
uint textLen,
bool multiline,
TModule* module)
:TEdit(parent, id, text, x, y, w, h, textLen, multiline, module)
{
}
void RetEdit::EvKeyDown(uint key, uint repeatCount, uint flags)
{
if(key == VK_TAB || key == VK_RETURN || //left, right
key == VK_UP || key == VK_DOWN || //up, down
key == VK_HOME || key == VK_END ||
key == VK_NEXT || key == VK_PRIOR)
{
//do what you want, or post user message to
//parent (your dialog) if you prefer to
//handle it in your dialog
}
else
TEdit::EvKeyDown(key, repeatCount, flags);
}
If editor is from resource, make sure select check want return,
and use appropriate form of TEdit() constrcutor
good luck
gaohong xie
copy following to a .h file
#ifndef RETEDIT.H
#define RETEDIT.H
#include <owl\edit.h>
#pragma hdrstop
class RetEdit : virtual public TEdit
{
public:
RetEdit::RetEdit(TWindow* parent,
int id,
const char far* text,
int x, int y, int w, int h,
uint textLen = 0,
bool multiline = false,
TModule* module = 0);
~RetEdit() {;}
void EvKeyDown(uint key, uint repeatCount, uint flags);
private: // hidden to prevent accidental copying or assignment
RetEdit(const RetEdit&);
RetEdit& operator =(const RetEdit&);
DECLARE_RESPONSE_TABLE(Ret
};
#endif
then copy following to .cpp file
#include above .h file
DEFINE_RESPONSE_TABLE1(Ret
EV_WM_KEYDOWN,
END_RESPONSE_TABLE;
RetEdit::RetEdit(TWindow* parent,
int id,
const char far* text,
int x, int y, int w, int h,
uint textLen,
bool multiline,
TModule* module)
:TEdit(parent, id, text, x, y, w, h, textLen, multiline, module)
{
}
void RetEdit::EvKeyDown(uint key, uint repeatCount, uint flags)
{
if(key == VK_TAB || key == VK_RETURN || //left, right
key == VK_UP || key == VK_DOWN || //up, down
key == VK_HOME || key == VK_END ||
key == VK_NEXT || key == VK_PRIOR)
{
//do what you want, or post user message to
//parent (your dialog) if you prefer to
//handle it in your dialog
}
else
TEdit::EvKeyDown(key, repeatCount, flags);
}
If editor is from resource, make sure select check want return,
and use appropriate form of TEdit() constrcutor
good luck
gaohong xie
ASKER
Gaohong, I was able to take your answers and incorporate them into my program without errors, but I still cannot intercept the keystrokes from the TEdit control. Do you have any simple example code you can upload? I am using the resource workshop and using the correct version of TEdit, but it doesn't seem to connect to the control properly. See below:
.h file
class RetEdit: virtual public TEdit
{
public:
RetEdit::RetEdit(TWindow* parent, int id, uint textlen,TModule* module);
~RetEdit();
void EvKeyDown(uint, uint,uint);
DECLARE_RESPONSE_TABLE(Ret Edit);
};
;------------------------- ----;
.cpp file
DEFINE_RESPONSE_TABLE1(Ret Edit,TEdit )
EV_WM_KEYDOWN,
END_RESPONSE_TABLE;
RetEdit::RetEdit(TWindow* parent, int id=IDC_FREQUENCY,uint textlen=8,TModule* module=0):TEdit(parent,id, textlen,mo dule)
{
}
Thanks for your help.
Regards, Gerry
.h file
class RetEdit: virtual public TEdit
{
public:
RetEdit::RetEdit(TWindow* parent, int id, uint textlen,TModule* module);
~RetEdit();
void EvKeyDown(uint, uint,uint);
DECLARE_RESPONSE_TABLE(Ret
};
;-------------------------
.cpp file
DEFINE_RESPONSE_TABLE1(Ret
EV_WM_KEYDOWN,
END_RESPONSE_TABLE;
RetEdit::RetEdit(TWindow* parent, int id=IDC_FREQUENCY,uint textlen=8,TModule* module=0):TEdit(parent,id,
{
}
Thanks for your help.
Regards, Gerry
ASKER
Gaohong, I was finally successful in intercepting keyboard inputs from the TEdit control. Disregard my last comment. Thanks for all your help.
Best Regards,
Gerald Capwell
Best Regards,
Gerald Capwell
ASKER
The TEdit object is in a TDialog. Do I add the WM_KEYDOWN event to the existing response table, or does the TEdit get it's own response table? I have tried to add it to the TDialog response table but it doesn't seem to work. Thanks for your help.
Regards, Gerry