Solved

Inserting text in CEditView

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tab names are off by one 5 54
WinWaitActive parameters 12 31
zeroFront challenge 7 114
mapAB Challlenge 35 160
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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