Shane Haw
Shane Haw

Reputation: 723

MFC Document View Getting Tabbing to work

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

Upvotes: 1

Views: 421

Answers (1)

snowdude
snowdude

Reputation: 3874

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.

Upvotes: 1

Related Questions