Click to See Complete Forum and Search --> : Edit Control


timber
May 7th, 1999, 01:03 PM
Hi,
I have a VB program I'm trying to port to VC++ code. In VB I have a text control which has code in the Keypress & KeyDown events. I'm using the Edit control to replace the Text control. Because the Edit control has no MFC built-in Keypress or Keydown events should I use the EN_CHANGE message to replace these events or is there better way?

Thanks
Steve

chiuyan
May 7th, 1999, 01:12 PM
CEdit is derived from a CWnd, so you can catch the WM_KeyDown & WM_KeyUp Events

--michael

timber
May 7th, 1999, 02:14 PM
Michael,
Thanks, could you give me more info. I understand, I think ,that the class CWnd receives WM_KEYPRESS & WM_KEYDOWN messages. Can I code for the events using the MFC Class wizard? Don't see a way. Or do I have to code my own event handelers for this.

Steve

chiuyan
May 7th, 1999, 02:37 PM
you will probably need to create your own class derived from a CEdit, and either create the editbox dynamically or subclass the edit box on your dialog (this would probably be easier). Then you can use the class wizard to add WM_KeyDown & KeyUp handlers in your derived class.

If you want to subclass the edit box, just call
MyNewEditClass.SubClassWindow (OldEditClass.hWnd)
in the OnInitDialog, and call MyNewEditClass.UnSubclassWindow in the OnDestroy or something.

--michael

timber
May 7th, 1999, 03:17 PM
Michael,
Almost there. Took the subclass approach. Please tell me what the 'OldEditClass' refers to when I have a edit control in a dialog that is using the default names given to them by Class Wizard. I tried the 'IDC_EDIT1.hWnd', that didn't compile... I knew it wouldn't... is the 'OldEditClass'refering to the dialog class name? Probubly not.

Thanks
Steve

chiuyan
May 7th, 1999, 03:25 PM
You would do a GetDlgItem with whatever ID Number you (or the class wizard) gave the Edit Control.

Like
CEdit* pEdit = (CEdit*)GetDlgItem (IDC_MyEdit);
MyNewEditClass.SubClassWindow (pEdit->m_hWnd);

or something like that.

--michael