1. Gord Cross
  2. PowerBuilder
  3. Thursday, 17 January 2019 17:30 PM UTC

Hi,

A fairly thorough search on the internet has yielded several old posts about how to accomplish this. The most recent post I found, uses the STD framework, which isn't an option for me so I haven't tried that one but none of the others work. Using PowerBuilder Classic.

All examples basically rely on 2 external functions:

function ulong DragQueryFileA( ulong hDrop, ulong iFile, ref string LPTSTR, ulong cb ) library 'shell32.dll' alias for "DragQueryFileA;Ansi"

subroutine DragAcceptFiles(ulong h, boolean b ) library 'shell32.dll'

 

Then calling DragAcceptFiles(...) in the open and close events of the window, and calls to DragQueryFileA (...) in a user event mapped to pbm_dropfiles. From my testing, the pbm_dropfiles event never fires when the files are dropped onto the window.

Can anyone provide a current, working example, that simply uses the shell32.dll functions or similar windows API? 

Thanks in advance 

 

 

 

Accepted Answer
Roland Smith Accepted Answer Pending Moderation
  1. Thursday, 17 January 2019 18:11 PM UTC
  2. PowerBuilder
  3. # Permalink

I got it working. Here is the source of a window.

forward
global type w_main from window
end type
type lb_files from listbox within w_main
end type
type cb_cancel from commandbutton within w_main
end type
end forward

global type w_main from window
integer width = 3305
integer height = 1844
boolean titlebar = true
string title = "Drag Files"
boolean controlmenu = true
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
lb_files lb_files
cb_cancel cb_cancel
end type
global w_main w_main

type prototypes
Subroutine DragAcceptFiles(Long hWnd, Boolean fAccept) Library "shell32.dll"
Function ULong DragQueryFile(Long hDrop, ULong iFile, Ref String lpszFile, ULong cch) Library "shell32.dll" Alias For "DragQueryFileW"

end prototypes
on w_main.create
this.lb_files=create lb_files
this.cb_cancel=create cb_cancel
this.Control[]={this.lb_files,&
this.cb_cancel}
end on

on w_main.destroy
destroy(this.lb_files)
destroy(this.cb_cancel)
end on

event open;// Enable Drag Accept Files
DragAcceptFiles(Handle(lb_files), True)

end event

event close;// Disable Drag Accept Files
DragAcceptFiles(Handle(lb_files), False)

end event

type lb_files from listbox within w_main
event wm_dropfiles pbm_dropfiles
integer x = 37
integer y = 32
integer width = 3186
integer height = 1508
integer taborder = 10
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
boolean vscrollbar = true
boolean sorted = false
borderstyle borderstyle = stylelowered!
end type

event wm_dropfiles;// WM_DROPFILES

Constant ULong FILECOUNT = 4294967295
ULong lul_size = 260, lul_index, lul_chars, lul_idx, lul_max
String ls_FileName

lul_max = DragQueryFile(handle, FILECOUNT, ls_FileName, lul_size)

For lul_idx = 1 To lul_max
	lul_index = lul_idx - 1
	ls_FileName = Space(lul_size)
	lul_chars = DragQueryFile(handle, lul_index, ls_FileName, lul_size)
	lb_files.AddItem(ls_FileName)
Next

end event

type cb_cancel from commandbutton within w_main
integer x = 2889
integer y = 1600
integer width = 334
integer height = 100
integer taborder = 10
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Cancel"
boolean cancel = true
end type

event clicked;Close(Parent)

end event

 

Comment
  1. Roland Smith
  2. Friday, 18 January 2019 00:03 AM UTC
I was using 12.5 on Windows 10 and it worked from the IDE.
  1. Helpful
  1. Roland Smith
  2. Friday, 18 January 2019 15:57 PM UTC
I just tried it in 2017-R3 and it works fine from the IDE. I have not seen any differences based on file type, that must be an issue with your code.
  1. Helpful
  1. René Ullrich
  2. Monday, 5 August 2019 07:25 AM UTC
One more thing:

You should call DragFinish(handle) as last statement in your wm_dropfiles event.

// subroutine DragFinish (long hDrop) library "shell32.dll"

This is to notify Windows you have finished with the drop handle. This frees the resources used to store information about the drop.
  1. Helpful 2
There are no comments made yet.
Stephan Schröpel Accepted Answer Pending Moderation
  1. Friday, 13 January 2023 14:13 PM UTC
  2. PowerBuilder
  3. # 1

Hello Roland

this code worked very well for years for me. Thank you. But in PB2022.1892 my user event uw_dropfiles from pbm_dropfiles does not fire any longer. This event is implemented in a w_main window. The same code in PB2021.1506 is working. Has something changed?

Thank you and have a nice weekend.

Stephan

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 2 August 2019 14:34 PM UTC
  2. PowerBuilder
  3. # 2

Hi Gord & John;

  Yes, it works OK from the STD Framework from a PB2017R3 App running on W10 ...

Note: This feature works at the "Window" Class level when only run from a compiled PB App EXE.

FYI: A new STD framework version was just released for PB2017R3. You do not have to use the framework for your App - just borrow the code.  ;-)

Tip: Search the framework for the DragAcceptFiles and DragQueryFile external declarations. Then have a look at the "wn_master" base ancestor window's "oe_drop_files" event code.

HTH

Regards ... Chris

Comment
  1. Roland Smith
  2. Friday, 2 August 2019 20:51 PM UTC
I had no problems running from the IDE.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Friday, 2 August 2019 21:11 PM UTC
I wonder if the difference is that your performing the operation on a Control (ListBox) whereas, I am performing the operation on a Window? Also, I am using the latest W10 ... build 18362.
  1. Helpful
There are no comments made yet.
John Vanleeuwe Accepted Answer Pending Moderation
  1. Friday, 2 August 2019 10:13 AM UTC
  2. PowerBuilder
  3. # 3

Hi Gord,

 

just wondering what was the cause of your problem as i am experiencing the same behaviour here :)

 

Thanks.

 

John

Comment
  1. John Vanleeuwe
  2. Friday, 2 August 2019 14:11 PM UTC
Hi Roland,



thank you for your reply.



I tried to implement parts of your code in my app on a new window, same result. the event doesn't get fired.



I must admit i didnt import the src in a brand new application or new pbl.



Even if i get your code to work in a new application , it won't fix the problem i am having in my current app.



I did copy the external function declaration , and mapped the pbm_dropfiles to my user function.



What can be the cause of this ? Can a setting or some code other than the dragaccept / dragqueryfile apis have any influcence on their behaviour ?



TIA

John
  1. Helpful
  1. Roland Smith
  2. Friday, 2 August 2019 20:51 PM UTC
I would imagine that the built in drag settings/code would interfere with it.
  1. Helpful
  1. Joerg Grunder
  2. Thursday, 31 December 2020 12:05 PM UTC
Hello everybody,



I ran into the same problem these days and tried the code of Roland Smith, mentioned above.

It works fine on PB 2019R2 and saved me lots of money, I otherwise had to pay to Novalys for an appropriate Active X.

How I did it...:

It was necessary, to create a new target-app and a new window, called "w_main".

then "edit source" of the w_main and paste the code underneath the (automatic) generated code from the assistant.

Then replace the generated code, part by part, with the code-parts of Roland.

...save, close run target and drag&drop a file from the desktop to the listbox works as promised.

See it as a "hello world"-app for this problem, to be developed to your own needs.

I describe the procedure such exactly, because often only a single detail isn't understood and nothing works at all.

On the other hand, trying the emailpop-Object of Roland, I know, that he plays "in another league". That means, sometimes his code is "art" and not easy to understand... (or not at all ;-|

Thanks to Roland for the "hello world"-app an many other helpful hints!



Greetings from germany

Jörg Grunder



  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 17 January 2019 22:12 PM UTC
  2. PowerBuilder
  3. # 4

Hi Gord;

      You are ALWAYS welcome to copy the code in the STD frameworks into your own App or framework. The STD frameworks are fully Open Source and licensed for free use and distribution under Apache 2.0.  ;-)

Regards ... Chris

Comment
  1. Gord Cross
  2. Thursday, 17 January 2019 22:18 PM UTC
Thanks Chris ... if I can't get it to work this way, I'll look into it.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.