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
1
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
Hi Gord;

The DragDropFiles used to work in older PB IDE versions but since 12.x (that I can remember) and newer MS-Windows O/S versions only in a PB App EXE.

Regards ... Chris
  1. Chris Pollach
  2. Thursday, 17 January 2019
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
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;

      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. # 1
  • Page :
  • 1


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