.net clipboard metadata (or any skip quotes)
Is it possible to use the Clipboard class to grab all data from the clipboard, like skype full quote? They use some kind of metadata, which I think is how they know when something is a quote or not.
How can I access this from the Clipboard class? What functions could I call to set / restore Skype quotes?
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
a source to share
I know this one is very old, but I found some code that should get you on the right track:
First, you extract the clipboard:
var dataObj = Clipboard.GetDataObject();
var formats = dataObj.GetFormats();
Then you fetch your 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 the 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);
Congratulations to the original author: http://pastebin.com/RygFN7xQ
Hooray!
a source to share
If you don't know the format, you will have to experiment. Start by iterating and displaying the available formats, use Clipboard.GetDataObject (). GetFormats (). These are lines, you can admit something. You can pass one of these to Clipboard.GetData (), you get an opaque object. Put this in a clock expression, maybe the debugger can figure it out.
If Skype is using the clipboard for its own use, there is little hope that you can dig up anything useful. If it intends to provide clipboard data for common applications like MS Word without any add-on, there will be a lot of hope.
a source to share