Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Want RETURN to acts as TAB

Posted on 1998-08-13
7
Medium Priority
?
533 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 200 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
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.

 

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses
Course of the Month11 days, 23 hours left to enroll

916 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