• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 521
  • Last Modified:

paste at the cursor

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
septip
Asked:
septip
  • 5
  • 2
  • 2
1 Solution
 
timopCommented:
You must call SetFocus before Paste.

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

0
 
septipAuthor Commented:
Timpop, if I use the SetFocus() the text is pasted but
not at my desired position but at the begining of richedit.
0
 
_seregaCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
septipAuthor Commented:
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
 
timopCommented:
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
 
_seregaCommented:
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
 
septipAuthor Commented:
Thank you very much.
0
 
septipAuthor Commented:
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
 
septipAuthor Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now