Solved

How to make text in edit control overwriteable

Posted on 1998-05-03
6
341 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
  • 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

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.

Join & Write a Comment

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

707 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

12 Experts available now in Live!

Get 1:1 Help Now