Computing.Net > Forums > Programming > copy text to clipboard with c/c++

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

copy text to clipboard with c/c++

Reply to Message Icon

Name: Ne0
Date: January 6, 2005 at 17:42:56 Pacific
OS: XP
CPU/Ram: amd64 xp2800 / 2*512 400m
Comment:

hey. i have bin programming with c++ for quite some time. I know the basics like syntax, funtions etc....

Now i want to know how i can make a program copy some text to the windows clipboard..
i've tried googling for it but i always end up with nothing..
I would think i have to use API's and stuff wich i dont know ANYTHING about. neither do i know anything about MFC.

So if anyone are willing to help it would be very nice.
The program i want to make is kind of like a keygen. but i want it to copy the link to the clipboard so that i can just open it and then paste it... without the hassle of [CTRL+C].

I know its not that cool or anything... and that its quite unusable but i think its a good way to learn more.

So please help!



Sponsored Link
Ads by Google

Response Number 1
Name: gimmpy225
Date: January 6, 2005 at 20:13:25 Pacific
Reply:

I know MFC would probably let you write a program to set a hot button so that when you press it it copy's the text. But MFC is really confusing, especialy if you dont know about OOP and havnt been working in c++ for roughly 6 months ish.

BUT anything is posible :).

If you choose to learn MFC I suggest the book
Programming Windows with MFC by Jeff Prosise.

But im sure theres another way to accomplish your task without the use of MFC.

GIMPS


0

Response Number 2
Name: Ne0
Date: January 6, 2005 at 20:42:23 Pacific
Reply:

im sure about that too :) but thanks for clearing it up that its possible with mfc :D

and i dont know much about oop. i'm reading: c++ how to program by deitel & deitel.

have read about 300 pages but still nothing about mfc or oop.


0

Response Number 3
Name: BlueRaja
Date: January 6, 2005 at 21:40:52 Pacific
Reply:

Using the clipboard at the lowest level is very difficult...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/dataexchange/clipboard.asp
I'm sure there are libraries out there to do it for you; for instance, MFC probably does some stuff for you..I don't use it, so I wouldn't know - I just ask gimps ;P -- otherwise, you could look one up online

Hope that helps!

BlueRaja.admin@gmail.com


0

Response Number 4
Name: egkenny
Date: January 6, 2005 at 23:02:41 Pacific
Reply:

Here is a tutorial:
//http://netez.com/2xExplorer/shellFAQ/adv_clip.html

Here is a MFC example using these functions from tutorial:
BOOL SetClipboardText(LPCTSTR pszText)
int GetClipboardText(LPTSTR pszBuf, int nLength)

1. Create 2 push button controls
IDC_PUT; // push button control
IDC_GET; // push button control

2. Create 3 edit box controls
IDC_EDIT_PUT; // edit box control
IDC_EDIT_GET; // edit box control
IDC_EDIT_STATUS; // edit box control

3. Create 3 Member Variables for edit box controls
CString m_get; // string associated with IDC_EDIT_GET edit box
CString m_put; // string associated with IDC_EDIT_PUT edit box
CString m_status; // string associated with IDC_EDIT_STATUS edit box

4. Test the program
a. Type text into IDC_EDIT_PUT edit box
b. Click on IDC_PUT push button
c. Status appears in IDC_EDIT_STATUS edit box
d. Click on IDC_GET push button
e. Status appears in IDC_EDIT_STATUS edit box
f. Text from clipboard appears in IDC_EDIT_GET edit box

// Function for clicking on IDC_PUT push button
void CTestClipboardDlg::OnPut()
{
BOOL success;
UpdateData(TRUE);
success = SetClipboardText(LPCTSTR(m_put));

if (success)
m_status = "Put Success";
else
m_status = "Put Failure";
UpdateData(FALSE);
}

// Function for clicking on IDC_GET push button
void CTestClipboardDlg::OnGet()
{
int result;
char buf[80];
int len = 80;
result = GetClipboardText(buf, len);
if (result>0)
{
m_status = "Get Success";
m_get = CString(buf);
}
else
m_status = "Get Failure";
UpdateData(FALSE);
}



0

Response Number 5
Name: Ne0
Date: January 7, 2005 at 01:49:13 Pacific
Reply:

thank you all! helped alot. Gonna try mess with the proggie in the weekend :D

again, thanks for the help!


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: copy text to clipboard with c/c++

Learning to program with C: A viable opt www.computing.net/answers/programming/learning-to-program-with-c-a-viable-opt/391.html

Where to start with C/C++? www.computing.net/answers/programming/where-to-start-with-cc/11818.html

Copying String to String In C www.computing.net/answers/programming/copying-string-to-string-in-c/699.html