Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit Box and return 1

Status
Not open for further replies.

BeerFizz

Technical User
Jan 23, 2004
28
0
0
Hi Guys,

When in an edit box, if return is pressed, my dialog exits. This appears to be because a default button is set to IDOK or IDCANCEL etc. By changing the default button to something else you can change the behavior to NOT exit the dialog (obviously :)), however the cursor reamins in the edit box.

On pressing Return or Tab I would like the cursor to jump to the next tabbed field.

Please can you tell me what to do?

Thanks
Phil
 
I think you should deal also with property WantReturn of the edit box

Ion Filipski
1c.bmp
 
Trap the key pressed event of the the edit box and write a code to check the ascii value of the key pressed. If it is return or tab, set the focus to te next item in your dialog.

ALL THE BEST

Cheers,

Ravi
 
>rchandr3
do it in a dialog based MFC project and say the results right here :).

Ion Filipski
1c.bmp
 
I accomplished this by creating a class which derives from CEdit. Define an override function for OnGetDlgCode and OnChar. I threw in a SWITCH statement in my OnChar function to handle any type of key press.

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

void CEditBoxValidate::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// Find out what control we're currently focused on ...
CWnd* pwndCtrl = GetFocus();
int ctrl_ID = pwndCtrl->GetDlgCtrlID();

// Get the contents of the control we're focused on ...
// I do this for validation purposes.
CString strCtrlText;
pwndCtrl->GetWindowText(strCtrlText);

switch (nChar)
{
case VK_RETURN:
case VK_TAB:
// Handle the case of this key press. I validate the text box data and set focus to the next dialog item in the tab control list.
}

Good luck!

 
>RileyCat
great workaround :) but it is possible to do without workarounds

Ion Filipski
1c.bmp
 
:)

Ion, would you like to tell us?

:)
 
read my first post on current thread [smile]. The only reason to press enter into a edit box is to enter a new line. You can enter a new line in only multiline edit box. If you set the property WantReturn to true then thet message will be eaten by edit box.

Ion Filipski
1c.bmp
 
if you just want to prevent the dialog box from closing use on void OnClose() in the message map and do a declaration like this:
void StatsDlg::OnClose()
{
ShowWindow(FALSE);
StatsDlg::OnClose();
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top