Click here to Skip to main content
15,920,632 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow To Paste Clipboard data in TextBox In Other Dialog Pin
Zhen-Xlogic17-May-07 0:24
Zhen-Xlogic17-May-07 0:24 
AnswerRe: How To Paste Clipboard data in TextBox In Other Dialog Pin
Hans Dietrich17-May-07 0:35
mentorHans Dietrich17-May-07 0:35 
GeneralRe: How To Paste Clipboard data in TextBox In Other Dialog Pin
Zhen-Xlogic17-May-07 0:54
Zhen-Xlogic17-May-07 0:54 
GeneralRe: How To Paste Clipboard data in TextBox In Other Dialog Pin
Hamid_RT17-May-07 1:31
Hamid_RT17-May-07 1:31 
GeneralRe: How To Paste Clipboard data in TextBox In Other Dialog Pin
Zhen-Xlogic17-May-07 1:36
Zhen-Xlogic17-May-07 1:36 
GeneralRe: How To Paste Clipboard data in TextBox In Other Dialog Pin
Hamid_RT17-May-07 1:45
Hamid_RT17-May-07 1:45 
GeneralRe: How To Paste Clipboard data in TextBox In Other Dialog Pin
Hans Dietrich17-May-07 1:32
mentorHans Dietrich17-May-07 1:32 
GeneralRe: How To Paste Clipboard data in TextBox In Other Dialog Pin
Zhen-Xlogic17-May-07 10:15
Zhen-Xlogic17-May-07 10:15 
Code that i tried:
void CChatView::OnChatroomAddtoautojoin()<br />
{<br />
CString strOut;<br />
			strOut.Format(IDS_AUTOJOIN_ADD, GetDocument()->m_strRoom);<br />
			WriteSystemMsg(FALSE, strOut, g_sSettings.GetRGBOK());<br />
	CClipboard::SetText((LPSTR)(LPCSTR)GetDocument()->m_strRoom);<br />
<br />
	OpenClipboard();<br />
	m_strAdd = CClipboard::GetText();<br />
    CloseClipboard();<br />
<br />
	ManageAutojoins dlg;<br />
	dlg.DoModal();<br />
}


CClipboard class header file:
<br />
#ifndef __CCLIPBOARD_H<br />
#define __CCLIPBOARD_H<br />
<br />
class CClipboard<br />
{<br />
public:<br />
	static CString GetText(HWND hWnd = NULL);<br />
	static BOOL GetText (LPSTR lpszBuffer,<br />
						 int nBufSize,<br />
						 HWND hWnd = NULL);<br />
	<br />
	static BOOL GetTextLength (unsigned long *pnSize,<br />
							   HWND hWnd = NULL);<br />
	<br />
	static BOOL SetText (LPSTR lpszBuffer,<br />
						 HWND hWND = NULL);<br />
};<br />
<br />
#endif


And the CClipboard class source file:
#include "stdafx.h"<br />
#include "Clipboard.h"<br />
<br />
////////////////////////////////////////////////////////////////////<br />
// GetText<br />
// - Retrieves text from the clipboard<br />
////////////////////////////////////////////////////////////////////<br />
//<br />
// Parameters:<br />
//	lpszBuffer - pointer to a string where the text is to be put<br />
//	nBufSize   - allocated length of lpszBuffer<br />
//	hWnd       - window handle to be used by clipboard<br />
//<br />
// Return Values:<br />
//	TRUE       - Text was successfully copied from clipboard<br />
//	FALSE      - No text on the clipboard<br />
//<br />
////////////////////////////////////////////////////////////////////<br />
<br />
BOOL CClipboard::GetText (LPSTR lpszBuffer, int nBufSize, HWND hWnd)<br />
{<br />
	HGLOBAL hGlobal;		// Global memory handle<br />
	LPSTR lpszData;			// Pointer to clipboard data<br />
	unsigned long nSize;	// Size of clipboard data<br />
<br />
	// First, open the clipboard. OpenClipboard() takes one<br />
	// parameter, the handle of the window that will temporarily<br />
	// be it's owner. If NULL is passed, the current process<br />
	// is assumed.<br />
	OpenClipboard(hWnd);<br />
<br />
	// Request a pointer to the text on the clipboard.<br />
	hGlobal = GetClipboardData(CF_TEXT);<br />
<br />
	// If there was no text on the clipboard, we have<br />
	// been returned a NULL handle.	<br />
	if (hGlobal == NULL) return FALSE;<br />
<br />
	// Now we have a global memory handle to the text<br />
	// stored on the clipboard. We have to lock this global<br />
	// handle so that we have access to it.<br />
	lpszData = (LPSTR)GlobalLock(hGlobal);<br />
	// Now get the size of the text on the clipboard.<br />
	nSize = GlobalSize(hGlobal);<br />
<br />
	// Make sure the text on the clipboard is not longer<br />
	// that the buffer that was allocated for it. If it was<br />
	// snip the text on the clipboard so that it fits.<br />
	if(nSize >= (UINT)nBufSize) nSize = nBufSize - 1;<br />
<br />
	// Now, copy the text into the return buffer. At the<br />
	// end, we need to add a NULL string terminator.<br />
	for (UINT i = 0; i < nSize; ++i)<br />
		*(lpszBuffer + i) = *(lpszData + i);<br />
	*(lpszBuffer + i) = 0;<br />
<br />
	// Now, simply unlock the global memory pointer<br />
	// and close the clipboard.<br />
	GlobalUnlock(hGlobal);<br />
	CloseClipboard();<br />
<br />
	return TRUE;<br />
}<br />
<br />
////////////////////////////////////////////////////////////////////<br />
// GetTextLength<br />
// - Retrieves length of text on the clipboard<br />
////////////////////////////////////////////////////////////////////<br />
//<br />
// Parameters:<br />
//	pnSize     - pointer to unsigned long that will receive<br />
//               the length of the text on the clipboard.<br />
//               NOTE: Does not include NULL terminator.<br />
//	hWnd       - window handle to be used by clipboard<br />
//<br />
// Return Values:<br />
//	TRUE       - Text length was successfully returned.<br />
//	FALSE      - No text on the clipboard<br />
//<br />
////////////////////////////////////////////////////////////////////<br />
<br />
BOOL CClipboard::GetTextLength (unsigned long *pnSize, HWND hWnd)<br />
{<br />
	HGLOBAL hGlobal;		// Global memory handle<br />
	unsigned long nSize;	// Size of clipboard data<br />
	LPSTR lpszData;			// Pointer to clipboard data<br />
<br />
	// First, open the clipboard. OpenClipboard() takes one<br />
	// parameter, the handle of the window that will temporarily<br />
	// be it's owner. If NULL is passed, the current process<br />
	// is assumed.<br />
	OpenClipboard(hWnd);<br />
<br />
	// Request a pointer to the text on the clipboard.<br />
	hGlobal = GetClipboardData(CF_TEXT);<br />
<br />
	// If there was no text on the clipboard, we have<br />
	// been returned a NULL handle.	<br />
	if (hGlobal == NULL) return FALSE;<br />
<br />
	// Now we have a global memory handle to the text<br />
	// stored on the clipboard. We have to lock this global<br />
	// handle so that we have access to it.<br />
	lpszData = (LPSTR)GlobalLock(hGlobal);<br />
	// Now get the size of the text on the clipboard.<br />
	nSize = GlobalSize(hGlobal);<br />
<br />
	// Now, simply unlock the global memory pointer<br />
	// and close the clipboard.<br />
	GlobalUnlock(hGlobal);<br />
	CloseClipboard();<br />
<br />
	// Finally, save the length of the string we found<br />
	// into the pnSize pointer and return.<br />
	*pnSize = nSize;<br />
	return TRUE;<br />
}<br />
<br />
////////////////////////////////////////////////////////////////////<br />
// SetText<br />
// - Places text on the clipboard<br />
////////////////////////////////////////////////////////////////////<br />
//<br />
// Parameters:<br />
//	lpszBuffer - pointer to a string where the text is to be put<br />
//	hWnd       - window handle to be used by clipboard<br />
//<br />
// Return Values:<br />
//	TRUE       - Text was successfully copied from clipboard<br />
//	FALSE      - No text on the clipboard<br />
//<br />
////////////////////////////////////////////////////////////////////<br />
<br />
int CClipboard::SetText (LPSTR lpszBuffer, HWND hWnd)<br />
{<br />
	HGLOBAL hGlobal;		// Global memory handle<br />
	LPSTR lpszData;			// Pointer to clipboard data<br />
	unsigned long nSize;	// Size of clipboard data<br />
<br />
	// First, open the clipboard. OpenClipboard() takes one<br />
	// parameter, the handle of the window that will temporarily<br />
	// be it's owner. If NULL is passed, the current process<br />
	// is assumed. After opening, empty the clipboard so we<br />
	// can put our text on it.<br />
	OpenClipboard(hWnd);<br />
	EmptyClipboard();<br />
<br />
	// Get the size of the string in the buffer that was<br />
	// passed into the function, so we know how much global<br />
	// memory to allocate for the string.<br />
	nSize = lstrlen(lpszBuffer);<br />
<br />
	// Allocate the memory for the string.<br />
	hGlobal = GlobalAlloc(GMEM_ZEROINIT, nSize+1);<br />
	<br />
	// If we got any error during the memory allocation,<br />
	// we have been returned a NULL handle.<br />
	if (hGlobal == NULL) return FALSE;<br />
<br />
	// Now we have a global memory handle to the text<br />
	// stored on the clipboard. We have to lock this global<br />
	// handle so that we have access to it.<br />
	lpszData = (LPSTR)GlobalLock(hGlobal);<br />
<br />
	// Now, copy the text from the buffer into the allocated<br />
	// global memory pointer.<br />
	for (UINT i = 0; i < nSize + 1; ++i)<br />
		*(lpszData + i) = *(lpszBuffer + i);<br />
<br />
	// Now, simply unlock the global memory pointer,<br />
	// set the clipboard data type and pointer,<br />
	// and close the clipboard.<br />
	GlobalUnlock(hGlobal);<br />
	SetClipboardData(CF_TEXT, hGlobal);<br />
	CloseClipboard();<br />
<br />
	return TRUE;<br />
}<br />
<br />
<br />
CString CClipboard::GetText(HWND hWnd)<br />
{<br />
<br />
	CString strReturn;<br />
	ULONG nLen = 0;<br />
	char *buffer = 0;<br />
<br />
	if(GetTextLength(&nLen, hWnd)){<br />
<br />
		buffer = new char[nLen];<br />
		GetText(buffer, nLen, hWnd);<br />
		strReturn = buffer;<br />
		delete buffer;<br />
		buffer = 0;<br />
	}<br />
	return strReturn;<br />
}<br />


With this code in the CChatView::OnChatroomAddtoautojoin is build ok! but the Room ID is copy but isnt paste in IDC_ADD_BOX (The IDC_ADD_BOX is m_strAdd: DDX_Text(pDX, IDC_ADD_BOX, m_strAdd);).

Why Isnt work my code is correct???

Thanks,
Zhen-Xlogic Smile | :)
GeneralRe: How To Paste Clipboard data in TextBox In Other Dialog Pin
Hans Dietrich17-May-07 21:35
mentorHans Dietrich17-May-07 21:35 
GeneralRe: How To Paste Clipboard data in TextBox In Other Dialog Pin
Zhen-Xlogic17-May-07 23:14
Zhen-Xlogic17-May-07 23:14 
GeneralRe: How To Paste Clipboard data in TextBox In Other Dialog Pin
Hans Dietrich18-May-07 3:02
mentorHans Dietrich18-May-07 3:02 
Questioncompiler error with &amp;amp;lt;&amp;amp;lt; operator overloading [modified] Pin
Dj_Lordas17-May-07 0:16
Dj_Lordas17-May-07 0:16 
AnswerRe: compiler error with &amp;amp;lt;&amp;amp;lt; operator overloading Pin
Hans Dietrich17-May-07 0:37
mentorHans Dietrich17-May-07 0:37 
GeneralRe: compiler error with &amp;amp;amp;amp;amp;lt;&amp;amp;amp;amp;amp;lt; operator overloading Pin
Dj_Lordas17-May-07 2:29
Dj_Lordas17-May-07 2:29 
GeneralRe: compiler error with &amp;amp;amp;amp;amp;lt;&amp;amp;amp;amp;amp;lt; operator overloading Pin
David Crow17-May-07 2:44
David Crow17-May-07 2:44 
GeneralRe: compiler error with &amp;amp;amp;amp;amp;amp;lt;&amp;amp;amp;amp;amp;amp;lt; operator overloading Pin
Dj_Lordas17-May-07 3:15
Dj_Lordas17-May-07 3:15 
QuestionRe: compiler error with &amp;amp;amp;amp;amp;amp;lt;&amp;amp;amp;amp;amp;amp;lt; operator overloading Pin
David Crow17-May-07 3:58
David Crow17-May-07 3:58 
AnswerRe: compiler error with &amp;amp;amp;amp;amp;amp;lt;&amp;amp;amp;amp;amp;amp;lt; operator overloading Pin
Dj_Lordas17-May-07 4:11
Dj_Lordas17-May-07 4:11 
QuestionBarcode reading Pin
kk.tvm17-May-07 0:11
kk.tvm17-May-07 0:11 
AnswerRe: Barcode reading Pin
toxcct17-May-07 0:45
toxcct17-May-07 0:45 
AnswerRe: Barcode reading Pin
Hans Dietrich17-May-07 1:30
mentorHans Dietrich17-May-07 1:30 
QuestionApplication & Citrix Pin
Sivaraman Dhamodaran17-May-07 0:03
Sivaraman Dhamodaran17-May-07 0:03 
AnswerRe: Application & Citrix Pin
Hans Dietrich17-May-07 1:38
mentorHans Dietrich17-May-07 1:38 
Questioninstalled path Pin
deeps_cute16-May-07 23:45
deeps_cute16-May-07 23:45 
AnswerRe: installed path Pin
Mark Salsbery17-May-07 5:37
Mark Salsbery17-May-07 5:37 

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.