• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

Console type program

How can I make a windows application that has a cursur where you enter text but once you press enter you can't go back and delete what you entered. Like what DOS does, but say in an edit control or on the client window area?
0
scooter1
Asked:
scooter1
1 Solution
 
chensuCommented:
You may derive your own class from CEdit and handle the OnChar function. If it is an Enter key, use CWnd::ModifyStyle to set the edit control style ES_READONLY.
0
 
CJ_SCommented:
MFC has an OnOK() function which will handle the ENTER-key.

So, what you might want to do here, is to (when the user has entered some data in the field), you update the data, if the CString is something else than _T("") then you do the following:

GetDlgItem(IDC_THENAMEOFTHEEDITBOX_EDIT)->EnableWindow(FALSE);

Just be sure to get rid of the CDialog::OnOK(); line which is the default of the OnOK Evenet handler.

Good luck,
CJ
0
 
scooter1Author Commented:
but after i press enter i still want the next line to be able to accept text. Like in DOS.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
CJ_SCommented:
UHM...that's a good one.
What you might want to do then is by every enter key (OnOK()) to save the contents of that box, and in the onChange event you check whether the user tries to _delete_ the sentences before it, by checking the value of the box. If it does, just put it back in.

I don't really have some code for you out of the top of my head.

Good luck,
CJ
0
 
scooter1Author Commented:
Is there no way to make only specific lines read only, using edit box? ,using richedit ?
0
 
saurabh_dasguptaCommented:
I got some ideas !!

It will be better to utilise the services of 2 controls simulataneously to get the above effects.
Use a simple borderless edit control window and a simple list box control.

The idea is, fake an impression of a DOS like window, by dynamically positioning the edit control within the list control, such that every time the user writes some text in the edit control and presses enter,

1)the text from the edit control  gets added to the list control

2)the contents of the edit control are cleared

3)The edit control is moved by some distance downwards, this distance will be determined by the height of the font with which the list control will be displaying the text.

4)Whenever the user scrolls the list control, the edit control must be dynamically scrolled along with it.(as in  DOS)

You will have to derive from the CListBox and handle several messages like WM_HSCROLL , WM_VSCROLL .

In the edit control you can provide features like DOS keys, by handling the arrow keys. Special attention is to be given to the handling of the enter key press.

I do not have code that will demonstrate the above idea, but I think a little tinkering with the above should lead to success.

Good luck !
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now