Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Prozak

How to send string to the clipboard

This topic is 5278 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, how do I send a string to the clipboard? This cannot be terrifically dificult... Season's Greetings, Happy New Year, Jester Says: "Visit Positronic Dreams"
[Hugo Ferreira][Positronic Dreams][Colibri 3D Engine][Entropy HL2 MOD]
[Yann L.][Enginuity] [Penny Arcade] [MSDN][VS RoadMap][Humus][BSPs][UGP][NeHe]
The most irrefutable evidence that there is intelligent life in the Universe is that they haven't contacted us!
[edited by - pentium3id on January 29, 2004 1:22:21 AM]

Share this post


Link to post
Share on other sites
Advertisement
look up OpenClipboard() in msdn, theres a good article on codeguru.com about copy and paste functions(very easy to do )

Share this post


Link to post
Share on other sites
Easy-pleasy,

  

char* g_pText;
HGLOBAL g_hGlobal;
HWND g_hWnd;

void CopyText()
{
//

// Prepare

g_hGlobal = GlobalAlloc(GHND | GMEM_SHARE, (lstrlen (g_pText) + 1) * sizeof (char));
g_hGlobal = GlobalLock(g_hGlobal);
lstrcpy(g_hGlobal, g_pText);
GlobalUnlock(g_hGlobal);

//

// Send

OpenClipboard(g_hWnd);
EmptyClipboard();
SetClipboardData(CF_TCHAR, g_hGlobal);
CloseClipboard();
}



HNY,



Zeblar Nagrim, Lord of Chaos

Share this post


Link to post
Share on other sites
and in VB it''s something like... Clipboard.setdata ____ or clipboard.getdata, ect..

-eldee
;another space monkey;

Share this post


Link to post
Share on other sites
Another, error checked method:

bool CopyTextToClipboard(const string& strBuff, HWND hWndOwner)
{
HGLOBAL hMem;
void* pData;

// Open Clipboard //

if(!OpenClipboard(hWndOwner))
return false;
EmptyClipboard();

// Allocate memory //

hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,strBuff.length()+1);
if(!hMem)
{
CloseClipboard();
return false;
}

// Fill Memory //

pData = GlobalLock(hMem);
if(!pData)
{
GlobalFree(hMem);
CloseClipboard();
return false;
}
memcpy(pData,strBuff.c_str(),strBuff.length()+1);

// Unlock memory, set clipboard data, and cleanup //

GlobalUnlock(hMem);
SetClipboardData(CF_TEXT,hMem);
CloseClipboard();
return true;
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!