Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to make text in edit control overwriteable

Posted on 1998-05-03
6
Medium Priority
?
369 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 300 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
Industry Leaders: 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

916 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