.net clipboard metadata (or whatever skype quotations use)
Is it possible to use the Clipboard class to grab all the data f开发者_开发问答rom the clipboard, like full skype quotes? They use some kind of metadata I think, which is how it knows when something is a quote or not.
How can I access that from the Clipboard class? What functions would I call to set/restore Skype quotations?
Thanks for the help!
Imports System.IO
Imports System.Text
Public Class Form1
Dim locale As New MemoryStream()
Private Sub l() Handles MyBase.Load
Dim strr As New StreamReader(CType(Clipboard.GetData("SkypeMessageFragment"), System.IO.Stream))
locale = Clipboard.GetData("locale")
TextBox1.Text = strr.ReadToEnd()
For Each x In Clipboard.GetDataObject().GetFormats()
'MessageBox.Show("Format " + x + ": " + Clipboard.GetData(x).ToString)
Next
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Clipboard.Clear()
Clipboard.SetData("SkypeMessageFragment", StreamFromString(TextBox1.Text))
Clipboard.SetData("Text", "testing")
Clipboard.SetData("System.String", "testing")
Clipboard.SetData("UnicodeText", "testing")
Clipboard.SetData("OEMText", "testing")
Clipboard.SetData("locale", locale)
End Sub
Private Shared Function StreamFromString(ByVal s As String) As Stream
Dim encoding As New System.Text.UnicodeEncoding()
Dim mem As New MemoryStream(encoding.GetBytes(s))
Return mem
End Function
End Class
I know this one is very old, but I found the code that should get you on the right track:
First you retrieve the clipboard:
var dataObj = Clipboard.GetDataObject();
var formats = dataObj.GetFormats();
Then you retrieve its data:
var sysString = dataObj.GetData("System.String");
var unicode = dataObj.GetData("UnicodeText");
var text = dataObj.GetData("Text");
var oemText = dataObj.GetData("OEMText");
var msgFragment = dataObj.GetData("SkypeMessageFragment") as MemoryStream;
var msg = new StreamReader(msgFragment).ReadToEnd();
Then you create a new DataObject to hold the quote and set it to clipboard:
DataObject dataObj = new DataObject();
DateTime time = DateTime.UtcNow;
string msg = "This is a Konloch message";
string msgInText = string.Format("[{0}] {1}: {2}", time.ToString("0:hh:mm:ss"), "konloch.me", msg);
string msgInXml = string.Format("<quote author=\"{0}\" timestamp=\"{1}\">{2}</quote>", "konloch.me", time, msg);
dataObj.SetData("System.String", msgInText);
dataObj.SetData("UnicodeText", msgInText);
dataObj.SetData("Text", msgInText);
dataObj.SetData("OEMText", msgInText);
dataObj.SetData("SkypeMessageFragment", new MemoryStream(Encoding.UTF8.GetBytes(msgInXml)));
Clipboard.SetDataObject(dataObj, true);
Compliments to the original author: http://pastebin.com/RygFN7xQ
Cheers!
If you don't know the format then you'll have to experiment. Start by iterating and displaying the available formats, use Clipboard.GetDataObject().GetFormats(). These are strings, you might recognize something. You can pass one of them to Clipboard.GetData(), you'll get an opaque object back. Put it in a watch expression, maybe the debugger can make sense of it.
If Skype uses the clip board for its own use, there's little hope you can dig anything usable out. If it intends to provide clipboard data to common apps like MS Word, without some kind of add-in, there will be lots of hope.
精彩评论