I have some code that allows me to drag and drop a hyperlink from a webpage onto a windows form, and it seperates the URL and the Title 开发者_如何学Pythonand puts them in two different text boxes.
This works on windows XP fine, but on windows 7 it no longer works. I'm not sure where the difference lies.
object data = e.Data.GetData("UniformResourceLocator");
data will always be null, but when i use
string[] fmts = e.Data.GetFormats();
one of fmts will always be UniformResourceLocator, along with a bunch of other ones that I can never seem to get any data from. If anyone has an resources to point me to or something I would greatly appreciate it, this is really confusing for me.
Thanks.
UPDATE:added method code that used to work
string hyperLinkUrl = null;
string hyperLinkText = null;
hyperLinkUrl = e.Data.GetData(typeof(string)) as string;
// some browser deliver url and text
// in UniformResourceLocator (Firebird)
string[] tokens = null;
if (hyperLinkUrl != null)
{
tokens = hyperLinkUrl.Split('\n');
}
if (tokens != null && tokens.Length > 1)
{
hyperLinkUrl = tokens[0];
hyperLinkText = tokens[1];
}
// we have to read FILEGROUPDESCRIPTOR to get the text (IE)
else
{
System.IO.Stream ioStream =
(System.IO.Stream)e.Data.GetData("FileGroupDescriptor");
byte[] contents = new Byte[512];
try
{
ioStream.Read(contents, 0, 512);
}
catch (Exception x)
{
}
ioStream.Close();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
//The magic number 76 is the size of that part of the
//FILEGROUPDESCRIPTOR structure before
// the filename starts - cribbed
//from another usenet post.
for (int i = 76; contents[i] != 0; i++)
{
sb.Append((char)contents[i]);
}
if (!sb.ToString(sb.Length - 4, 4).ToLower().Equals(".url"))
{
throw new Exception("filename does not end in '.url'");
}
hyperLinkText = sb.ToString(0, sb.Length - 4);
}
tbLinkTitle.Text = hyperLinkText;
tbLinkAddress.Text = hyperLinkUrl;
drag and drop a hyperlink from a webpage
That page wouldn't be in a web browser running in low integrity (e.g. IE Protected Mode), would it? Drag-and-drop doesn't work across integrity levels.
- http://en.wikipedia.org/wiki/Mandatory_Integrity_Control
What happens if you use icacls
to set your executable's integrity level to low as well? If drag-and-drop starts working, this was the problem.
精彩评论