Solved

Inserting text in CEditView

Posted on 1998-09-03
2
428 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

822 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