Solved

paste at the cursor

Posted on 1999-01-27
9
481 Views
Last Modified: 2008-03-10
I have a RichEdit control in which I move the cursor at the desired position (by program)and I want to paste there some
text. The cursor appears at the new position but when I press Ctrl+V nothing is being pasted. If I move the cursor with a mouse click there is no problem but I don't want to move the cursor in this way.
There is the code I used:
CRichEditCtrl m_Rich;
CBitmap m_Cursor;
void CMyappDlg::OnMyPaste()
{
      m_Cursor.LoadBitmap(MAKEINTRESOURCE(IDB_CURSOR));
      CPoint pct;
      m_Rich.CreateCaret(&m_Cursor);//I create the cursor
      pct=m_Rich.GetCharPos(5);
      m_Rich.SetCaretPos(pct);//the cursor is moved
      m_Rich.ShowCaret();//the cursor is showed
      m_Rich.Paste();//nothing happens!!!
}
please help me.
You can download the entire source code from
http://www.itc-cluj.ro/paste.html
0
Comment
Question by:septip
  • 5
  • 2
  • 2
9 Comments
 
LVL 1

Expert Comment

by:timop
ID: 1185291
You must call SetFocus before Paste.

m_Rich.ShowCaret();//the cursor is showed
m_Rich.SetFocus();
m_Rich.Paste();//nothing happens!!!

0
 

Author Comment

by:septip
ID: 1185292
Timpop, if I use the SetFocus() the text is pasted but
not at my desired position but at the begining of richedit.
0
 

Expert Comment

by:_serega
ID: 1185293
Try to little modify your code on that way:

------------- in .h file
CRichEditCtrl* m_Rich;  
CBitmap m_Cursor;      

------- in OnInitDialog()
      m_Rich = new CRichEditCtrl();
      m_Rich = (CRichEditCtrl*) GetDlgItem(IDC_RICHEDIT1);
      m_Cursor.LoadBitmap(MAKEINTRESOURCE(IDB_BITMAP1));

------- in OnMyPaste()  function
      CPoint pct;
      m_Rich -> CreateCaret(&m_Cursor);//I create the cursor
      pct=m_Rich -> GetCharPos(5);
      m_Rich -> SetCaretPos(pct);//the cursor is moved
      m_Rich -> ShowCaret();//the cursor is showed
      m_Rich -> Paste();//nothing happens!!!

i did that and text was pasted
0
 

Author Comment

by:septip
ID: 1185294
Dear Serega, the text is pasted endeed but I want to paste it at the position established by m_Rich->SetCaretPos(pct);, not at the beginning of the rich edit control.

Does anyone know the correct answer?

You can work on the program at http://www.itc-cluj.ro/paste.html
Thanks!

0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Accepted Solution

by:
timop earned 200 total points
ID: 1185295
Try this

m_Rich.SetSel( 5,5 );  // 5 is the value from GetCharPos
m_Rich.CreateCaret(&m_Cursor);//I create the cursor
pct=m_Rich.GetCharPos(5);
..



0
 

Expert Comment

by:_serega
ID: 1185296
septip, if you have no text in your control, the caret is at (0,0), so , if pct.x=5 and pct.y =10 , for instance, you have to insert 5 "spaces" and 10 "enters" in your control before calling Paste() function.
0
 

Author Comment

by:septip
ID: 1185297
Thank you very much.
0
 

Author Comment

by:septip
ID: 1185298
Serega,

I had some text in the control. The caret wasn't 0,0 .
The solution was to write m_rich.SetSel(5,5).
This is pretty stupid becouse I had already positioned the caret
with SetCaretPos(5).
Thank you anyway!
0
 

Author Comment

by:septip
ID: 1185299
Serega,

I had some text in the control. The caret wasn't 0,0 .
The solution was to write m_rich.SetSel(5,5).
This is pretty stupid becouse I had already positioned the caret
with SetCaretPos(5).
Thank you anyway!
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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

760 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

20 Experts available now in Live!

Get 1:1 Help Now