{"id":23133,"date":"2008-03-12T10:00:00","date_gmt":"2008-03-12T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2008\/03\/12\/what-a-drag-dragging-a-uniform-resource-locator-url\/"},"modified":"2022-08-02T07:10:01","modified_gmt":"2022-08-02T14:10:01","slug":"20080312-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20080312-00\/?p=23133","title":{"rendered":"What a drag: Dragging a Uniform Resource Locator (URL)"},"content":{"rendered":"<p><a title=\"What a drag: Dragging text\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20080311-00\/?p=23153\"> Last time, we dragged some text around<\/a> and found that the text would be interpreted as a URL if you dropped it onto Firefox, but Internet Explorer was not as willing to accept it. Today, we&#8217;ll make the data object work for Internet Explorer.<\/p>\n<p>The only change is that we have to provide the URL in the form of a <code>CFSTR_SHELLURL<\/code> clipboard format rather than as <code>CF_TEXT<\/code>. Take the program from last time and make two changes. First, use the handy-dandy search-and-replace function to change <code>DATA_TEXT<\/code> to <code>DATA_URL<\/code> throughout. (This step isn&#8217;t technically necessary, but it&#8217;s nice to have the name match its usage.) The real work happens in this change to the constructor:<\/p>\n<pre>CTinyDataObject::CTinyDataObject() : m_cRef(1)\r\n{\r\n  SetFORMATETC(&amp;m_rgfe[DATA_URL],\r\n               RegisterClipboardFormat(CFSTR_SHELLURL));\r\n}\r\n<\/pre>\n<p>That&#8217;s all; just change the clipboard format from <code>CF_TEXT<\/code> to <code>CFSTR_SHELLURL<\/code>. It is important to note that <code>CFSTR_SHELLURL<\/code> represents an ANSI string. Since &#8220;<a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc1738#section-2.2\">URLs are written only with the graphic printable characters of the US-ASCII coded character set<\/a>,&#8221; there is no loss of expressiveness by restricting to ANSI.<\/p>\n<p>Run this new program and now you can click in the client area and drag\/drop the (invisible) object onto Internet Explorer, where it will navigate to Microsoft&#8217;s home page. (If your system supports Active Desktop, you can also drag\/drop the invisible object to the desktop and create an Active Desktop component.)<\/p>\n<p>Okay, so we have one version of the program that can drag a URL to Internet Explorer, and another version that can drag a URL to Firefox. Next time, we&#8217;ll combine them to have a single data object that can drop to both. It&#8217;s quite embarrassingly simple (because I planned it that way).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s still just a string.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25,139],"class_list":["post-23133","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code","tag-what-a-drag"],"acf":[],"blog_post_summary":"<p>It&#8217;s still just a string.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/23133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=23133"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/23133\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=23133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=23133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=23133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}