Solved

Want RETURN to acts as TAB

Posted on 1998-08-13
7
466 Views
Last Modified: 2013-11-20
Hello,

I have a bunch of CEdits in a dialog.  I've ordered their tabs and checked their tab stop attributes.  The tab correctly, but what I want to do is be able to tab with the Tab key and Return key.  I tried to use the ON_WM_KEYDOWN message:

ON_WM_KEYDOWN();

void CMyClass::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch (nChar)
   {
        case VK_RETURN:
      CScrollView::OnKeyDown(VK_TAB, nRepCnt, nFlags);
      break;
        default:
                  CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
}
}

What am I doing wrong?

thanks
draw

0
Comment
Question by:draw
  • 3
  • 3
7 Comments
 

Accepted Solution

by:
bogie2 earned 50 total points
ID: 1320741
Hi,

simply replace

CScrollView::OnKeyDown(VK_TAB, nRepCnt, nFlags);
by
PostMessage(WM_KEYDOWN, VK_TAB, nRepCnt + (nFlags<<16));

Why? The call to CScrollView::OnKeyDown() is passed the ORIGINAL
values and not the VALUES you supply (so VK_RETURN will be passed
instead of VK_TAB).

greetings,

bogie2
0
 

Author Comment

by:draw
ID: 1320742
Hello,

I replaced it and it still doesn't work.  Am I using the right message (WM_ON_KEYDOWN) ?  Should it be SYSKEYDOWN?  Also, when I put a breakpoint on it and executed, I couldn't provoke it?  Any help on this?

thanks
draw
0
 
LVL 6

Expert Comment

by:snoegler
ID: 1320743
The point is that the KEYDOWN event will never reach the dialog window - it is handled
by the edit control itself. So the easiest way to find out when the user has pressed 'enter'
is to use the OnOK() function which is called when the user hits the 'OK' button.
Then you can proceed like this:

void CMyDlg::OnOK()
{
      // TODO: Add extra validation here
      
      int      curCtrlID=GetFocus()->GetDlgCtrlID();

      if( /* test if curCtrlID is one of the edit fields which should conv. enter to tab*/)
            GetNextDlgTabItem(GetFocus())->SetFocus();
            return;
      }
      
      CDialog::OnOK();
}

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:draw
ID: 1320744
Hello,

Well, the dialog belongs to a CFormView, so there are no OKs and CANCELs.  I do believe that you're right about the KEYDOWN will never reach to my dialog.  So the problem is, how can I capture the WM_KEYDOWN.  Or maybe I should capture WM_CHAR.  I was looking through the MFC codes and it suggested that maybe I should over write the PreTranslateMessage.  Is this right?  If so, can someone give me some advices because I don't have any idea in using PreTranslateMessage to translate the input character.

thanks
draw
0
 
LVL 6

Expert Comment

by:snoegler
ID: 1320745
You won't ever get a KEYDOWN. This message is sent to the edit control and is
completely processed there - only a BN_CLICKED with the default pushbutton as ID
reaches your CFormView. If you have no default pushbutton, even this message won't
be sent.
You could write a own control which subclasses the EDIT control, and process the
WM_GETDLGCODE message. By this message you can define which key codes the
parent window receives and which are processed by the control (see online help).
I think the easiest way is to add an (invisible) default pushbutton(IDOK), so you
could do it like i suggested.
Hope this helps :)

snoegler
Maybe i am wrong and there is an easier solution.
0
 

Author Comment

by:draw
ID: 1320746
thanks
0
 
LVL 6

Expert Comment

by:snoegler
ID: 1320747
thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now