Solved

Want RETURN to acts as TAB

Posted on 1998-08-13
7
505 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
Independent Software Vendors: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replacement selected text 2 69
CRON statement to run every 3 minutes except on Monday morning 12am to 2am 7 123
maxBlock challenge 30 150
Annoying "thing" blocks my view 4 146
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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