Windows Develop Bookmark and Share   
 index > Windows Forms General > How do i copy a variable contents to the clipboard?
 

How do i copy a variable contents to the clipboard?

I need an mfc api or method to copy the contents of a variable into the windows clipboard.
garedkarl  Tuesday, September 15, 2009 5:32 AM
use namespace System.Windows.Forms

or use

SetClipboardData(
UINTuFormat,
HANDLEhMem
);

for more information http://msdn.microsoft.com/en-us/library/ms649051(VS.85).aspx
Bharath kumar Y.S  Tuesday, September 15, 2009 8:46 AM

Clipboard.SetText(<variable value>

)



is this whatyou wanted..
Bharath kumar Y.S  Tuesday, September 15, 2009 5:40 AM

Following link could help

http://www.ex-designz.net/apidetail.asp?api_id=610



For text in a string variable you can use "CF_TEXT". For this link given by bharathkumar will be useful


Or you can use

System.Windows.Forms.Clipboard.SetText("Hello", TextDataFormat.Text)



Gaurav Khanna

Khanna Gaurav  Tuesday, September 15, 2009 10:19 AM
HGLOBAL hText;

hText = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, sizeof(str_data));
pText = GlobalLock(hText);
strcpy(pText, str_data);
GlobalUnlock(hText);

OpenClipboard(hDlg);
EmptyClipboard();
SetClipboardData(CF_TEXT, hText);
CloseClipboard();



check if this can work..

for more information check http://www.codeguru.com/forum/archive/index.php/t-290608.html
Bharath kumar Y.S  Tuesday, September 15, 2009 10:29 AM
declare pTex as char * and then try

pText =(char*) GlobalLock(hText);
Bharath kumar Y.S  Tuesday, September 15, 2009 12:48 PM

Clipboard.SetText(<variable value>

)



is this whatyou wanted..
Bharath kumar Y.S  Tuesday, September 15, 2009 5:40 AM
yeah i think so... but wat header do i need to include for this??
i get the error "'Clipboard' : undeclared identifier"..
garedkarl  Tuesday, September 15, 2009 6:07 AM
use namespace System.Windows.Forms

or use

SetClipboardData(
UINTuFormat,
HANDLEhMem
);

for more information http://msdn.microsoft.com/en-us/library/ms649051(VS.85).aspx
Bharath kumar Y.S  Tuesday, September 15, 2009 8:46 AM
Thanks dude... but im still kinda confused regarding the syntax.

Can u give me a sample code to copy the contents of a string say str_data to the windows clipboard so that i can paste it in some other application (like notepad)

Thanks
Gared
garedkarl  Tuesday, September 15, 2009 10:12 AM

Following link could help

http://www.ex-designz.net/apidetail.asp?api_id=610



For text in a string variable you can use "CF_TEXT". For this link given by bharathkumar will be useful


Or you can use

System.Windows.Forms.Clipboard.SetText("Hello", TextDataFormat.Text)



Gaurav Khanna

Khanna Gaurav  Tuesday, September 15, 2009 10:19 AM
HGLOBAL hText;

hText = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, sizeof(str_data));
pText = GlobalLock(hText);
strcpy(pText, str_data);
GlobalUnlock(hText);

OpenClipboard(hDlg);
EmptyClipboard();
SetClipboardData(CF_TEXT, hText);
CloseClipboard();



check if this can work..

for more information check http://www.codeguru.com/forum/archive/index.php/t-290608.html
Bharath kumar Y.S  Tuesday, September 15, 2009 10:29 AM
Hi... i can understand the idea behind the syntax but there are still a few issues
like of what type ispText,hDlg.

pTex will need to be of a char type but that doesnt match withGlobalLock return type..
garedkarl  Tuesday, September 15, 2009 11:53 AM
declare pTex as char * and then try

pText =(char*) GlobalLock(hText);
Bharath kumar Y.S  Tuesday, September 15, 2009 12:48 PM

You can use google to search for other answers

Custom Search

More Threads

• limit drop drown list of cobobox
• Overriding a method Help
• How to register ToolTip to an area
• Stretch font horizontally in Visual C# (Frame work 2.0)
• Application.ThreadException...How to test it works?
• Is there a way to know when a MDIchild is added?
• FolderBrowserDialog
• MsMq Remote access?
• Reading XML file into TextBox
• Does anybody know how I would do this...