Solved

How to make text in edit control overwriteable

Posted on 1998-05-03
6
358 Views
Last Modified: 2013-11-19
How do I make a edit control such that the text inside
can be overwritten. Like what happens in text editiors.
0
Comment
Question by:kumarana
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 100 total points
ID: 1306061
Edit controls can already work that way.  In fact the MFC multipad example (ike notepad) uses an edit control as a view.

0
 

Expert Comment

by:shaqshup
ID: 1306062
What do you mean by overwritten? Edit controls by default select all of the text inside them when they get focus. Typing anything while it has focus will remove the selection and thus the contents of the edit control.
0
 
LVL 1

Author Comment

by:kumarana
ID: 1306063
I think I did not explain by problem compeletly.I want overwrite feature to happen without a selection being made. For example in Wordpad I press the INS key it starts overwriting text.
Now I have implemented by subclassing the edit and on OnChar() function if I find the cursor is not at end of the entered text, then I send VK_DELETE and then call base class CEdit::OnChar() something like below

OnChar(....){
  // get caret pos
  CPoint p = GetCaretPos();

  // get position of caret in edit box
  int pos = CharFromPos(P);

  // Get length of text
  GetDlgItemText( CurrData);
  int len = strlen( CurrData );

  if ( pos < len ) {
    SendMessage( KEY_DOWN, VK_DELETE );
  }
  OnChar(...);
}
 
Is there any other method?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:RONSLOW
ID: 1306064
This might work in OnChar(...):

   if (isprint(nChar)) {
       int nStart,nEnd;
       GetSel(nStart,nEnd);
       if (nEnd == nStart) {
           nEnd++;
           SetSel(nStart,nEnd);
       }
       CEdit::OnChar(...)
    }

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1306065
An alternative is to use a rich-edit control instead of an edit control (set it to plain text mode).  This supports insert/overwrite mode.

However, I am not sure how to detect or get the overwrite mode without doing it yourself.

I'd suggest you subclass the control to include a bool indicating overwrite mode.  Init this to false.  In your OnChar, detect the VK_INSERT key.  If found, toggle the state of the flag.  You can then add a 'SetOverwriteMode' function that checks the flag, and if not set to overwrite, sends a VK_INSERT to the control.  Similarly for detecting and setting insert mode

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1306066
BTW: my comment about the multipad sample is incorrect.  It does NOT support overwrite mode (nor does Notepad).  It appears only rich-edit controls natively support insert/overwrite mode.


0

Featured Post

 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

623 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