Michael Curtin
June 13th, 1999, 05:26 PM
Hi everyone!
I'm trying to implement COPY on the edit menu using the Randy More's text-based copy code on http://www.codeguru.com/clipboard/text_tofrom_clipboard.shtml
The problem is that the copy can performed on a huge block of text (a log file from a mail server). For small or even medium-sized copy, his code seems to work. But large copies cause the program to lock up. Here is my code:
void CMercuryLogView::OnEditCopy()
{
CListCtrl& output = GetListCtrl();
CString source;
POSITION pos;
int index;
pos = output.GetFirstSelectedItemPosition();
for (int i=0;i<output.GetSelectedCount();i++)
{
index = output.GetNextSelectedItem(pos);
source = source + output.GetItemText(index,0);
source = source + "\n";
}
if(OpenClipboard())
{
HGLOBAL clipbuffer;
char * buffer;
EmptyClipboard();
clipbuffer = GlobalAlloc(GMEM_DDESHARE, source.GetLength()+1);
buffer = (char*)GlobalLock(clipbuffer);
strcpy(buffer, (LPCTSTR)source);
GlobalUnlock(clipbuffer);
SetClipboardData(CF_TEXT,clipbuffer);
CloseClipboard();
}
}
I suspect that there is some kind of memory problem with the CString "source" -- it grows to be quite large when reading hundreds of lines of text from a list control.
Any ideas on how to solve this? I guess I have to implement some kind of shared scratch file, but I have no idea how...
Thanks,
Mike
I'm trying to implement COPY on the edit menu using the Randy More's text-based copy code on http://www.codeguru.com/clipboard/text_tofrom_clipboard.shtml
The problem is that the copy can performed on a huge block of text (a log file from a mail server). For small or even medium-sized copy, his code seems to work. But large copies cause the program to lock up. Here is my code:
void CMercuryLogView::OnEditCopy()
{
CListCtrl& output = GetListCtrl();
CString source;
POSITION pos;
int index;
pos = output.GetFirstSelectedItemPosition();
for (int i=0;i<output.GetSelectedCount();i++)
{
index = output.GetNextSelectedItem(pos);
source = source + output.GetItemText(index,0);
source = source + "\n";
}
if(OpenClipboard())
{
HGLOBAL clipbuffer;
char * buffer;
EmptyClipboard();
clipbuffer = GlobalAlloc(GMEM_DDESHARE, source.GetLength()+1);
buffer = (char*)GlobalLock(clipbuffer);
strcpy(buffer, (LPCTSTR)source);
GlobalUnlock(clipbuffer);
SetClipboardData(CF_TEXT,clipbuffer);
CloseClipboard();
}
}
I suspect that there is some kind of memory problem with the CString "source" -- it grows to be quite large when reading hundreds of lines of text from a list control.
Any ideas on how to solve this? I guess I have to implement some kind of shared scratch file, but I have no idea how...
Thanks,
Mike