Saving the content of the clipboard and restoring it in VB

Hi I wrote a program which uses the clipboard. But I dont want to loose the content that was in the clipboard before i used it..
I have checked everywhere on the net to find a sample program that can save no matter what from the clipboard and restore it to the clipboard afterwards. I have found some that can save and restore some things like text pictures etc. but they were not ble to save everything.


So if there is anybody who is able to write a function that can do that. id be very thankful.
AIDetonAsked:
Who is Participating?
 
zzzzzoocConnect With a Mentor Commented:
Sorry, an overlooked question.

It's most-likely too late and I apologize but all you had to do was pass an array populated with file-names to the function such as:

    Dim MyArray(2) As String
    MyArray(0) = "c:\test1.txt"
    MyArray(1) = "c:\test1.txt"
    MyArray(2) = "c:\test1.txt"
    Call ClipboardSetFiles(MyArray)


My suggestion for the question is either accept answer / PAQ & refund.
0
 
mmusanteCommented:
I think you can use the 'GetText' method of the clipboard object and then save it to a file ...

Temp = Clipboard.GetText(vbCFText)
Open app.path & "\Clip.txt" For Output As #1
Print #1, Temp
0
 
zzzzzoocCommented:
>> I think you can use the 'GetText' method of the clipboard object and then save it to a file ...

GetText is for Text only and won't apply to objects.


>> So if there is anybody who is able to write a function that can do that. id be very thankful.

http://www.vb-helper.com/howto_track_clipboard.html

The above is a start on how to go about it. Main reason for the link is to take note on how to Get/Set "File Lists" (when you select files in Explorer and chose "copy").

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/dataexchange/clipboard/clipboardformats.asp?frame=true

http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/dataexchange/clipboard/clipboardoperations.asp?frame=true


The above provide information on the formats and operations. Pay attention to how the clipboard data is stored for different formats and how it is suggested to go about retrieving the data... (quote below).

"To retrieve paste information from the clipboard, a window first determines the clipboard format to retrieve. Typically, a window enumerates the available clipboard formats by using the EnumClipboardFormats function and uses the first format it recognizes. This method selects the best available format according to the priority set when the data was placed on the clipboard."
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
AIDetonAuthor Commented:
hey zzzzzooc,
the program from vb-helper seems to be exactly whyt I need. unfortunately I do not seem to have the knowlege on how to use the clipboardsetfiles() function. i do not know what i have to give it as parameter. it says something like an arrey file_names().
I have already tried some things but nothing seems to be working.

and I cant see how it is used because the function is in the exampleprogram but not used at all.

I'd be glad If you could explain to me how i have to use it.

thanks for your help
0
 
AIDetonAuthor Commented:
Hey guys I really need your help I would appreciate if you could tell me how to use the restore function.
I am in a lot time pressure so i will increase the points(250-350) hopeing that you will help me then.

Thank You
AIDeton
0
 
AIDetonAuthor Commented:
yeah it is a little bit late but we cant change that. thank you anyways that you answered the question i dont have time to test the code but i will next week or so...
here are the points.

AIDeton
0
 
AIDetonAuthor Commented:
Hi Zzzzzzooc,
I know i am kinda late with this and that i have already accepted your answere but i have a lil problem... I foudn time today to try out the function you gave me. the problem is when i add your code to a function it will write c:\test1.txt
3 times into the clipboard. I mean okay now i know howto write text into the clipboard but i need to write the data back into the clipboard that had been there shortly before, which can be everything... maybe contacting each other would be easier if we exchanged e mail adresses or ICQ#. I promise i will give you further points if you help me solve this problem.
It is still very important for me to solve/ understand this problem.

AIDeton
ICQ: 110093435
Email: simon@simonweiss.de
0
 
zzzzzoocCommented:
It's best to keep any help provided here.

ClipboardSetFiles() sets every item in the array into the clipboard.

    MyArray(0) = "c:\test1.txt"
    MyArray(1) = "c:\test1.txt"
    MyArray(2) = "c:\test1.txt"

Since there are 3 items in the clipboard, all 3 will be copied to the clipboard. If you removed MyArray(1) and MyArray(2), only one would be copied to the clipboard.

The function ClipboardGetFiles() returns an array such as MyArray() with all of the items from the clipboard. All you would need to do is pass the array from ClipboardGetFiles() to ClipboardSetFiles(). I hope that's enough to resolve that.

Since it seems you aren't too familiar with all of the aspects of VB, you may want to search Yahoo! for tutorials/guides or buy/read books.
0
All Courses

From novice to tech pro — start learning today.