{"id":604,"date":"2010-11-30T20:22:56","date_gmt":"2010-12-01T01:22:56","guid":{"rendered":"http:\/\/anvil-of-time.com\/wordpress\/?p=604"},"modified":"2021-03-10T18:12:06","modified_gmt":"2021-03-10T23:12:06","slug":"powerbuilder-dragging-files-onto-the-application","status":"publish","type":"post","link":"https:\/\/anvil-of-time.com\/powerbuilder\/powerbuilder-dragging-files-onto-the-application\/","title":{"rendered":"PowerBuilder &#8211; Dragging Files onto the Application"},"content":{"rendered":"<p>Many applications I&#8217;ve worked on have had internal drag\/drop capabilities.  By &#8216;internal&#8217; I mean you can drag items from one place to another from within the application itself.  Now what if you want to drag files from an explorer window into your application and perform some processing?  This functionality is not as common.<\/p>\n<p>The solution involves three Windows API calls, one of which has a Unicode and an ANSI version.  If you are using the PFC you can add these to your environment object so the appropriate version is called depending upon the operating system of the user.<\/p>\n<p>The API methods<\/p>\n<pre name=\"code\" class=\"VB\">subroutine DragAcceptFiles(long l_hWnd,boolean fAccept) library &quot;shell32.dll&quot;\nsubroutine DragFinish(long hDrop) library &quot;shell32.dll&quot;\nfunction int DragQueryFileW(long hDrop,int iFile,ref string szFileName,int cb) library &quot;shell32.dll&quot;\nfunction int DragQueryFileA(long hDrop,int iFile,ref string szFileName,int cb) library &quot;shell32.dll&quot;<\/pre>\n<p>To allow items to be dragged onto your application you must first call the DragAcceptFiles method.  This should be put in the open\/postopen type event of the app.<\/p>\n<pre name=\"code\" class=\"VB\">DragAcceptFiles(handle(this), true)<\/pre>\n<p>Now create an user event mapped to the pbm_dropfiles Event ID.  Put the following in it:<\/p>\n<pre name=\"code\" class=\"VB\">integer\tli_i, li_numFiles, li_rc\nstring \tls_File\n\nls_File = Space(1024)\n\n\/\/ first call gets number of files dragged\n\/\/ unicode API call\nli_numFiles = DragQueryFileW(handle, 4294967295, ls_File, 1023)\n\/\/ ansi API call\n\/\/li_numFiles = DragQueryFileA(handle, 4294967295, ls_File, 1023) \n\nFOR li_i = 0 To li_numFiles - 1\n\tls_File = Space(1024)\n\t\/\/ subsequent calls get file names from dragged object\n\tli_rc = DragQueryFileW( handle, li_i, ls_File, 1023 )\n\t\/\/ add file to listbox\n\tlb_1.AddItem(ls_File)\nNEXT \n\nDragFinish(handle)<\/pre>\n<p>This example is populating a listbox with the file names dragged onto the application.<\/p>\n<p>The MSDN reference for DragQueryFile can be found <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb776408%28VS.85%29.aspx\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many applications I&#8217;ve worked on have had internal drag\/drop capabilities. By &#8216;internal&#8217; I mean you can drag items from one place to another from within the application itself. Now what if you want to drag files from an explorer window into your application and perform some processing? This functionality is not as common. The solution&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,10],"tags":[12,16,42],"_links":{"self":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/604"}],"collection":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/comments?post=604"}],"version-history":[{"count":11,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/604\/revisions"}],"predecessor-version":[{"id":1890,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/604\/revisions\/1890"}],"wp:attachment":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/media?parent=604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/categories?post=604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/tags?post=604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}