Use the Tab-Key in an Edit Box.

I´ve written a program were I among other things use a large Edit-Box. I´ve added Multiline and want Enter. BUT I would like to be able to use the Tab-Key like in Notepad, were the cursor jumps a little bit to the right each time you press it. If that´s possible, I would appriciate the code written out since I´m quite new at this.
Thanx...
FfazeAsked:
Who is Participating?
 
chensuConnect With a Mentor Commented:
class CMyEdit : public CEdit
{
    protected:
        afx_msg UINT OnGetDlgCode();
};

BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
    ON_WM_GETDLGCODE()
END_MESSAGE_MAP()

UINT CMyEdit::OnGetDlgCode()
{
    return DLGC_WANTALLKEYS;
}

Associate the edit control with CMyEdit instead of CEdit. (Use MFC ClassWizard/Member Variables to associate it)

0
 
awdCommented:
Use <tab><enter> inside the edit box.  Otherwise you could probably capture the keystroke in the code.
0
 
FfazeAuthor Commented:
I would like the code please, it should be as easy as any other program to use the Tab-key.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
FfazeAuthor Commented:
Increased points.....
0
 
FfazeAuthor Commented:
I´m using a formview and I´ve tried to input your code in CMyView and it did´nt work I´ve got Errors so if you could tell me were to write the cod I´d appriciate it....
0
 
chensuCommented:
What are the Errors?
0
 
FfazeAuthor Commented:
This is what I get...
D:\Recept\ReceptView.cpp(67) : error C2509: '_GetBaseMessageMap' : member function not declared in 'CReceptEdit'

D:\Recept\ReceptView.cpp(67) : error C2509: 'GetMessageMap' : member function not declared in 'CReceptEdit'

D:\Recept\ReceptView.cpp(67) : warning C4273: 'protected: static struct AFX_MSGMAP const  CWnd::messageMap' : inconsistent dll linkage.  dllexport assumed.

D:\Recept\ReceptView.cpp(67) : error C2491: 'CReceptEdit::CEdit::CWnd::messageMap' : definition of dllimport static data member not allowed

Error executing cl.exe.

Recept.exe - 3 error(s), 1 warning(s)

0
 
chensuCommented:
In your ReceptView.h,

.
class CMyEdit : public CEdit
{
    protected:
        afx_msg UINT OnGetDlgCode();
};
.
class CYourFormView : public CFormView
{
.
    CMyEdit m_edit;
.
};


In your ReceptView.cpp,

.
BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
    ON_WM_GETDLGCODE()
END_MESSAGE_MAP()

UINT CMyEdit::OnGetDlgCode()
{
    return DLGC_WANTALLKEYS;
}
.

// the following should be generated by ClassWizard
void CYourFormView::DoDataExchange(CDataExchange* pDX)
{
      CFormView::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CYourFormView)
        ...
      DDX_Control(pDX, IDC_EDIT1, m_edit);
        ...
      //}}AFX_DATA_MAP
}

0
 
FfazeAuthor Commented:
I´m sorry but it just doesn´t work I´ve tried to change class and move it around but in the end I´ll still get the same errors as before.....
0
 
FfazeAuthor Commented:
I´m sorry but it just doesn´t work I´ve tried to change class and move it around but in the end I´ll still get the same errors as before.....
0
 
chensuCommented:
Which line causes the error?
0
 
FfazeAuthor Commented:
All errors are caused by this:

BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
      ON_WM_GETDLGCODE()
END_MESSAGE_MAP()
0
 
chensuCommented:
Where do you put this?
0
 
chensuCommented:
Sorry, that's my fault. I missed out DECLARE_MESSAGE_MAP().

class CMyEdit : public CEdit
{
    protected:
        afx_msg UINT OnGetDlgCode();

    DECLARE_MESSAGE_MAP()
};

0
 
FfazeAuthor Commented:
In my CReceptView.cpp
Right under:
BEGIN_MESSAGE_MAP(CReceptView, CFormView)
      //{{AFX_MSG_MAP(CReceptView)


END_MESSAGE_MAP()

Here it comes......
0
 
chensuCommented:
Now it should be OK.
0
 
FfazeAuthor Commented:
Thanx for all your work "chensu" it worked perfectly now. I´ve increased the points a little, enjoy.....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.