Solved

Want RETURN to acts as TAB

Posted on 1998-08-13
7
477 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

20 Experts available now in Live!

Get 1:1 Help Now