Solved

Want RETURN to acts as TAB

Posted on 1998-08-13
7
513 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

617 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