Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

paste at the cursor

Posted on 1999-01-27
9
Medium Priority
?
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 

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
 
LVL 1

Accepted Solution

by:
timop earned 800 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

636 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