1. Gord Cross
  2. PowerBuilder
  3. Thursday, 17 January 2019

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
2
Votes
Undo

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
I was using 12.5 on Windows 10 and it worked from the IDE.
  1. Roland Smith
  2. Friday, 18 January 2019
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. Roland Smith
  2. Friday, 18 January 2019
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. René Ullrich
  2. Monday, 5 August 2019
There are no comments made yet.
  1. Thursday, 17 January 2019
  2. PowerBuilder
  3. # Permalink
Chris Pollach Accepted Answer Pending Moderation
0
Votes
Undo

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
I had no problems running from the IDE.
  1. Roland Smith
  2. Friday, 2 August 2019
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. Chris Pollach
  2. Friday, 2 August 2019
There are no comments made yet.
  1. Friday, 2 August 2019
  2. PowerBuilder
  3. # 1
John Vanleeuwe Accepted Answer Pending Moderation
0
Votes
Undo

Hi Gord,

 

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

 

Thanks.

 

John

Comment
Try the code I posted.
  1. Roland Smith
  2. Friday, 2 August 2019
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. John Vanleeuwe
  2. Friday, 2 August 2019
I would imagine that the built in drag settings/code would interfere with it.
  1. Roland Smith
  2. Friday, 2 August 2019
There are no comments made yet.
  1. Friday, 2 August 2019
  2. PowerBuilder
  3. # 2
Chris Pollach Accepted Answer Pending Moderation
0
Votes
Undo

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
Thanks Chris ... if I can't get it to work this way, I'll look into it.
  1. Gord Cross
  2. Thursday, 17 January 2019
There are no comments made yet.
  1. Thursday, 17 January 2019
  2. PowerBuilder
  3. # 3
  • Page :
  • 1


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