Problem : Copy/Paste in CListCtrl question
Hi,
I have a CListCtrl object and I want to copy and paste from it (using Ctrl+c).
Can it be done ???
thanks,
Solution : Copy/Paste in CListCtrl question
you can derive a class like the following and do it.
//header
class CListCtrlWithCopy : public CListCtrl
{
afx_msg void OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags );
DECLARE_MESSAGE_MAP()
};
//cpp
BEGIN_MESSAGE_MAP(CListCtr
ON_WM_KEYDOWN()
END_MESSAGE_MAP()
void CListCtrlWithCopy::OnKeyDo
{
if((nChar == ‘C’ || nChar == ‘c’) && (GetKeyState(VK_CONTROL) & 0x8000))
{
int nPos = GetNextItem(-1, LVNI_SELECTED) ;
if(nPos != -1)
{
AfxMessageBox(GetItemText(
}
}
CListCtrl::OnKeyDown(nChar
}
If you copy this code in your dialog header and cpp, and make a CListCtrlWithCopy object instead of CListCtrl object in your member variable, you can see the Ctrl+C sequence display the currently selected item in the listctrl if the listctrl has focus and an item is selected.
Search for “Copying Information to the Clipboard” in MSDN and you will get code to copy the text to clipboard.