Click here to Skip to main content
15,887,135 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Difficult - Owner data in CListCtrl - Pin
JensB21-May-03 23:12
JensB21-May-03 23:12 
GeneralRe: Difficult - Owner data in CListCtrl - Pin
Rage21-May-03 23:24
professionalRage21-May-03 23:24 
GeneralFast User Switching Pin
Alex Korchemniy21-May-03 19:38
Alex Korchemniy21-May-03 19:38 
GeneralRe: Fast User Switching Pin
Neville Franks22-May-03 0:01
Neville Franks22-May-03 0:01 
Questionhow to delete a file ? Pin
thacdo21-May-03 17:25
thacdo21-May-03 17:25 
AnswerRe: how to delete a file ? Pin
Chris Richardson21-May-03 17:32
Chris Richardson21-May-03 17:32 
AnswerRe: how to delete a file ? Pin
AnkushChopra23-May-03 2:20
AnkushChopra23-May-03 2:20 
QuestionCopy a string to clipboard ? Pin
_skidrow_vn_21-May-03 14:21
_skidrow_vn_21-May-03 14:21 
I have a string, such as "Hello World!"
I want copy it to clipboard, so that, after that, when I right click in a word process application ( such as: NotePad, WordPad, Word...), there is a "paste" menu command show for me to paste that string "Hello World!"

My code is wrong (GlobalUnlock) but I dont know how to fix it (I am following code in MSDN sample)

thanks!

//lpszString = "Wednesday, 21 May 2003 --- 08:21:07 PM"<br />
BOOL CopyToClipBoard(LPSTR lpszString)<br />
{<br />
	LPTSTR  lptstrCopy; <br />
	HGLOBAL hglbCopy; <br />
	INT cch; 		<br />
<br />
	OpenClipboard(hWnd);<br />
	EmptyClipboard(); <br />
<br />
	cch=strlen(lpszString);<br />
	hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (cch + 1) * sizeof(TCHAR)); <br />
	if (hglbCopy == NULL) <br />
	{ <br />
        	CloseClipboard(); <br />
		MessageBox(hWnd,"errror on GlobalAlloc()","Error",MB_ICONERROR);<br />
       		return FALSE; <br />
	}  <br />
<br />
	// Lock the handle and copy the text to the buffer.  <br />
	lptstrCopy = (LPTSTR)GlobalLock(hglbCopy); <br />
	memcpy(lptstrCopy, lpszString, cch * sizeof(TCHAR)); <br />
	lptstrCopy[cch] = (TCHAR) 0;    // null character <br />
<br />
<br />
	if(!GlobalUnlock(hglbCopy)) //>>>>>>>ERROR >>>>>>>:eek:	{<br />
		MessageBox(hWnd,"errror on GlobalUnlock()","Error",MB_ICONERROR);<br />
		return FALSE;  <br />
	}<br />
<br />
    	// Place the handle on the clipboard.  <br />
	if(!SetClipboardData(CF_TEXT, hglbCopy))<br />
	{<br />
		MessageBox(hWnd,"errror on SetClipboardData()","Error",MB_ICONERROR);<br />
		return FALSE; <br />
	}<br />
<br />
	if(!CloseClipboard())<br />
	{<br />
		MessageBox(hWnd,"errror on CloseClipboard()","Error",MB_ICONERROR);<br />
		return FALSE;  <br />
	}  <br />
<br />
	return TRUE;<br />
}

AnswerRe: Copy a string to clipboard ? Pin
Dave Bryant21-May-03 15:29
Dave Bryant21-May-03 15:29 
GeneralRe: Copy a string to clipboard ? Pin
_skidrow_vn_22-May-03 10:48
_skidrow_vn_22-May-03 10:48 
AnswerRe: Copy a string to clipboard ? Pin
valikac21-May-03 19:32
valikac21-May-03 19:32 
QuestionHow do I make a window transparent for mouse clicks? Pin
Chris982021-May-03 13:44
Chris982021-May-03 13:44 
AnswerRe: How do I make a window transparent for mouse clicks? Pin
Michael Dunn21-May-03 14:57
sitebuilderMichael Dunn21-May-03 14:57 
GeneralRe: How do I make a window transparent for mouse clicks? Pin
Chris982021-May-03 16:24
Chris982021-May-03 16:24 
Generalstring operator == Pin
Makover21-May-03 13:35
Makover21-May-03 13:35 
GeneralRe: string operator == Pin
Dave Bryant21-May-03 15:23
Dave Bryant21-May-03 15:23 
GeneralRe: string operator == Pin
Makover22-May-03 8:49
Makover22-May-03 8:49 
QuestionHow do I set up a simple test sending data through the com port?? Pin
IrishSonic21-May-03 12:54
IrishSonic21-May-03 12:54 
General(hopefully) easy WaitForMultipleObjects question Pin
Phil Hamer21-May-03 12:01
Phil Hamer21-May-03 12:01 
GeneralRe: (hopefully) easy WaitForMultipleObjects question Pin
Rage21-May-03 21:04
professionalRage21-May-03 21:04 
GeneralTechnical help and Ideas on Videoconferencing Pin
hassanmurtaza21-May-03 10:49
hassanmurtaza21-May-03 10:49 
GeneralFile Sharing Pin
DougW4821-May-03 10:38
DougW4821-May-03 10:38 
GeneralRe: File Sharing Pin
valikac21-May-03 11:10
valikac21-May-03 11:10 
GeneralChanging background Pin
MemLeak21-May-03 9:48
MemLeak21-May-03 9:48 
GeneralRe: Changing background Pin
valikac21-May-03 11:18
valikac21-May-03 11:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.