1
votes

I have created a MFC Document View app and added several classes which inherit from CEdit to the CView. I would like to get tabbing between each CEdit working. I have looked around and most solution involve Adding IsDialogMessage() to either the message loop or in PreTranslateMessage. I have tried this in the PreTranslateMessage method of the CEdit class like this:

BOOL WordControl::PreTranslateMessage(MSG* pMsg)
{
    if(IsDialogMessage(pMsg))
        return TRUE;
    else
        return __super::PreTranslateMessage(pMsg);
}

however, now the CEdit doesn't receive any keyboard messages and doesn't tab. I have created the CEdit like this:

Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_CENTER , Rect, Parent, Index);

What am I doing wrong?

EDIT:

The app uses the basic MFC single document template. I am dynamically adding several objects which inherit from CEdit and several which inherit from CStatic. I have managed to create all the CEdits and CStatics but I would like to be able to tab from CEdit to CEdit.

A picture is worth a thousand words; here is a screenshot:

Screenshot

I want to be able to type "hello" in the first CEdit, hit tab and for the next CEdit to have focus. Then I will type "world" and then hit tab and the next CEdit will have focus for me to type "this" etc.

EDIT:

New Window:

New Window

1
Any reason for not inheriting from CEditView? Can you show a mockup of the app to describe the issue a little more. - snowdude
I am pretty new to using C++ and MFC so to tell you the truth I didn't know about CEditView. I am using the MFC single document template so I am just using what it gave me. Can I just change my view to inherit from CEditView instead? - Shane Haw
Sure. Is it tabbing between the views you're trying to get working? - snowdude
I tried changing the view to inherit from CEditView as per your suggestion but the app gave a Debug Exception failure on startup. - Shane Haw
For something like this you'd normally create a view based on CFormView. Then you'll have a dialog resource that you can add edits to, specify tab order etc. Am I missing something? - snowdude

1 Answers

1
votes

Use a CFormView as your base. You can add controls dynamically and the form will manage the tabbing for you. If you only have a small number of maximum edit controls you could also just create them on the form and then show/hide them as necessary.