Skip to main content
GameDev.net gamedev.net
🔒 Locked

TextBox Behavior

Started by brain21 Dec 1, 2002 at 11:45 AM 9 replies 450+ views
Original Post
brain21
brain21
I''m having a little problem with my application. This is what I have: Visual C++ 6.0 MFC Dialog Based Application My main Dialog calls another dialog: CMyDialog dlgNewDialog; dlgNewDialog.DoModal(); My new dialog has an Exit button and a textbox. When I enter some text in the textbox and press ENTER the dialog closes. Almost like it is calling the Exit Button. I have other objects on the dialog and the textbox is the first in the tab order and the exit button is the last in the tab order. I can''t figure out why it''s doing this. Brain21
CodeZ
CodeZ
Sounds like your close button have focus. You can set focus to another controller when the dialog shows up.

Like this:


  

BOOL CALLBACK DlgProc(HWND hwnd, UINT uiMessage, WPARAM wParam, LPARAM lParam)
{
switch(uiMessage)
{
case WM_INITDIALOG:
SetFocus(GetDlgItem(hwnd, IDC_TEXTBOX_EB));
break;

...

brain21
brain21
When my dialog pops-up, the text box has focus. But when I type something in and press ENTER the dialog exits.
brain21
brain21
What I discovered is that when I press ENTER on the text box, the OnOK() function gets called. What is up with that??
And the "want return" option does not help. Is there a default peice of code somewhere that gets galled when I press ENTER??
Evil Bill
Evil Bill
Change the tab order on the dialog template (Ctrl+D) so that the OK button is not the next control after the edit box. I dunno if this''ll work if you only have 1 or 2 controls tho

Member of the Unban Mindwipe Society (UMWS)
Evil Bill
Evil Bill
brain21: What do you expect to happen when you press Enter?

Member of the Unban Mindwipe Society (UMWS)
brain21
brain21
Ok, I found the answer in another forum. I have to override the OnOK() funtion and use EndDialog() in my Exit button.

Evil Bill: I am using the text box to enter strings into a listbox, so when I press ENTER I want the string to to go into the list box. The Tab''s are set correctly.

Thanks all.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.