How to get highlighted text by double click?
-
-
Hello, I have a problem with text selection. I want to get the highlighted text that users double click on it (not only in my own application). Do I have to use COleDataObject to implement this? Is this about clipboard? I'm a beginner. Guide me, please.:-O
Yes, it's about clipboard. This code places the contents of strClipboardText variable in clipboad. You'll probably use CEdit::GetSel and CEdit::GetSel and CEdit::GetWindowText to get this string.
CString strClipboardText = ...;
if (!OpenClipboard() || !EmptyClipboard())
{
AfxMessageBox("Error: can't open the clipboard.");
return;
}
HGLOBAL hglbText = GlobalAlloc(GMEM_MOVEABLE, 1 + strClipboardText.GetLength());
char *pData = (char *)GlobalLock(hglbText);
lstrcpy(pData, strClipboardText);
GlobalUnlock(hglbText);
SetClipboardData(CF_TEXT, hglbText);
CloseClipboard();Assuming that you're using CEdit control, there will be a problem with double-clicking - this action highlights the *word* you're clicking on. Previous selection is lost. You may try to override WM_LBUTTONDBLCLK to change this behavior. Tomasz Sowinski -- http://www.shooltz.com
-
Yes, it's about clipboard. This code places the contents of strClipboardText variable in clipboad. You'll probably use CEdit::GetSel and CEdit::GetSel and CEdit::GetWindowText to get this string.
CString strClipboardText = ...;
if (!OpenClipboard() || !EmptyClipboard())
{
AfxMessageBox("Error: can't open the clipboard.");
return;
}
HGLOBAL hglbText = GlobalAlloc(GMEM_MOVEABLE, 1 + strClipboardText.GetLength());
char *pData = (char *)GlobalLock(hglbText);
lstrcpy(pData, strClipboardText);
GlobalUnlock(hglbText);
SetClipboardData(CF_TEXT, hglbText);
CloseClipboard();Assuming that you're using CEdit control, there will be a problem with double-clicking - this action highlights the *word* you're clicking on. Previous selection is lost. You may try to override WM_LBUTTONDBLCLK to change this behavior. Tomasz Sowinski -- http://www.shooltz.com