Solved

paste at the cursor

Posted on 1999-01-27
9
485 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

914 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

22 Experts available now in Live!

Get 1:1 Help Now