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

x
?
Solved

Inserting text in CEditView

Posted on 1998-09-03
2
Medium Priority
?
463 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 200 total points
ID: 1321667
Answer in my comment below, takes me a while to type <g>
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1321668
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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…
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 summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

927 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