Link to home
Start Free TrialLog in
Avatar of septip
septip

asked on

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
Avatar of timop
timop

You must call SetFocus before Paste.

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

Avatar of septip

ASKER

Timpop, if I use the SetFocus() the text is pasted but
not at my desired position but at the begining of richedit.
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
Avatar of septip

ASKER

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!

ASKER CERTIFIED SOLUTION
Avatar of timop
timop

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of septip

ASKER

Thank you very much.
Avatar of septip

ASKER

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!
Avatar of septip

ASKER

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!