Solved

Inserting text in CEditView

Posted on 1998-09-03
2
406 Views
Last Modified: 2013-11-20
I created an editor with the CEditView MFC. I added a dialogbox where I can enter one line of text. When I press on OK, I want the text to be pasted in my document. How can I write to my editor document,or is there a way to write to the clipboard so that I can paste the text from the clipboard?
0
Comment
Question by:940961sl
  • 2
2 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
Comment Utility
Answer in my comment below, takes me a while to type <g>
0
 
LVL 8

Expert Comment

by:Answers2000
Comment Utility
1. To insert text on the clipboard use the following

Crude code (you should check return values) :-

// say char szBuffer[] contains the text to put on the clipboard

// allocate HGLOBAL memory for the text (extra char is the terminating NULL)
HGLOBAL hText = GlobalAlloc( GHND, strlen(szBuffer)+1 ) ;
LPSTR lpText = (LPSTR)GlobalLock( hText ) ;
memcpy( lpText, szBuffer, strlen(szBuffer)+1 ) ;
GlobalUnlock( hText ) ;

// put new text in clipboard
::OpenClipboard( NULL ) ; // open clipboard for current task
::EmptyClipboard() ;
::SetClipboardData( CF_TEXT, hText ) ;
::CloseClipboard() ;

2. You can force pasting of text into the edit control using the WM_PASTE message, for each in your class derived from CEditView

GetEditCtrl().SendMessage( WM_PASTE, 0, 0 ) ;


3. If you just want to manipulate the text in the edit control (and don't care about the clipboard)

i. use GetWindowText to get the text out of the window.  This gives you a CString
ii. Manipulate the CString as necessary
iii. use SetWindowText to put the text back into CEditView

CString strText = GetEditCtrl().GetWindowText() ;
strText += "another word" ;
GetEditCtrl().SetWindowText( strText ) ;

You can find the text selection of a CEditView using GetSelectedText, and use CEdit member functions to find out any other info you want.

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 125
unable to delete all specified values regedit 38 149
iSeries DB2 Query 2 83
sumNumber challenge 16 98
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: 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…
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

8 Experts available now in Live!

Get 1:1 Help Now