Solved

Console type program

Posted on 2000-05-14
6
156 Views
Last Modified: 2013-12-03
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
Comment
Question by:scooter1
6 Comments
 
LVL 23

Expert Comment

by:chensu
Comment Utility
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
 
LVL 22

Expert Comment

by:CJ_S
Comment Utility
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
 

Author Comment

by:scooter1
Comment Utility
but after i press enter i still want the next line to be able to accept text. Like in DOS.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 22

Expert Comment

by:CJ_S
Comment Utility
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
 

Author Comment

by:scooter1
Comment Utility
Is there no way to make only specific lines read only, using edit box? ,using richedit ?
0
 
LVL 4

Accepted Solution

by:
saurabh_dasgupta earned 72 total points
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Perl Awk Need Help 3 94
Universal fonts 2 137
crystal report check box and wingdings font 7 136
Problem with Frankling Gothic Book font 5 80
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now