Solved

How to make text in edit control overwriteable

Posted on 1998-05-03
6
345 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

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. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

810 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