bulamb0d
New Member
Hello everyone!
Posts: 8
|
Post by bulamb0d on Apr 28, 2019 16:37:48 GMT 1
copy all text below and save with .g32 to test it.
// Demonstrates the use of the Drag and Drop
// functions located in Shell32. It will
// not accept folder and .lnk files.
LoadForm frm1
~DragAcceptFiles(lb1.hWnd, True)
Do
Sleep
Until Me Is Nothing
Sub frm1_MessageProc(ByRef hWnd As Long, ByRef Mess As Long, ByRef wParam As Long, ByRef lParam As Long, ByRef RetVal As Long, ByRef Valid As Boolean)
If Mess = WM_DROPFILES
ExtractFilenamesfromDrag(wParam)
EndIf
End Sub
'
'
Sub ExtractFilenamesfromDrag(ByVal hDrop As Int)
Local pt As POINT
Local Int nFiles, nSkip
Local FName As String
~DragQueryPoint(hDrop, pt)
' get number of files dropped into window
nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, 0, 0) //
If nFiles >= 0
For nSkip = 0 To nFiles - 1
FName = Space$(255) + #0 //Allways initiaslize FName every loop.
' get filename
~DragQueryFile(hDrop, nSkip, FName, Len(FName) - 1)
FName = ZTrim(FName)
If lb1.Find(FName) = -1 //check if file/s already add in listbox.
If GetAttr(FName) And 16 Then // check if its directory.
Else
If Upper(Right(FName, 4)) = ".LNK" //check if its .lnk files.
Else
lb1.AddItem FName ' Add FName and to listbox
EndIf
EndIf
EndIf
Next
EndIf
'##E#
'##B#
~DragFinish(hDrop)
End Sub
Type POINT
x As Long
y As Long
End Type
Declare LIB "shell32.dll"
Declare FunctionA ExtractIcon _
(ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Declare FunctionA DragQueryFile _
(ByVal HDROP As Long, ByVal UINT As Long, ByVal lpStr As String, ByVal ch As Long) As Long
Declare Function DragQueryPoint (ByVal HDROP As Long, lpPoint As POINT) As Long
Declare Sub DragFinish (ByVal hDrop As Long)
Declare Sub DragAcceptFiles (ByVal hwnd As Long, ByVal fAccept As Long)
$DatFile
$FormVersion = 2
:{frm1 105
EAAAAAAAAAAAAAA64XEAA9TRvAQFmJXbxAgElCAAE00UgMFalxGbgQEbnBAAAAACAAAgPAAAACAA
AEAAHAAgAAAbiFDANAAgOOEAAI1QAgkxFBAoXT0EAMICAAAgFAAAACAAAAAAAEQB
$LanguageId = 0409
$DatFile
|
|
|
Post by scalion on Apr 30, 2019 20:25:23 GMT 1
Excellente démonstration, fonctionnelle, simple, efficace. Juste ce qu'il faut ! Plutôt que de faire un fastidieux copier / enregistrer / ouvrir depuis le post de bulamb0d
Merci pour ce code bulamb0d et bonne journée.
|
|
bulamb0d
New Member
Hello everyone!
Posts: 8
|
Post by bulamb0d on May 1, 2019 16:26:45 GMT 1
your welcome scallion...
google translate.... Excellent demonstration, functional, simple, efficient. Just the right thing! Rather than make a tedious copy/save/open from the post of bulamb0d
Download directly: DragAndDrop. G32 (2.1 KB)
Thanks for this code bulamb0d and good day.
|
|
|
Post by (X) on Aug 2, 2022 0:47:41 GMT 1
Excellente démonstration, fonctionnelle, simple, efficace. Juste ce qu'il faut ! Plutôt que de faire un fastidieux copier / enregistrer / ouvrir depuis le post de bulamb0d
Merci pour ce code bulamb0d et bonne journée.
Est-ce que ça marche avec Win10? Je n'y arrive pas... --------------------- Does this work under Win10? I can't get it to work...
|
|
|
Post by dragonjim on Aug 2, 2022 10:07:44 GMT 1
It does for me. Open up a File Explorer window on one side of the screen, then run the code and put the form on the other. Then try and drag a file from the Explorer window to the Form...
|
|
|
Post by (X) on Aug 2, 2022 12:52:55 GMT 1
I see the drag and drop icon appear but when I release the mouse button the WM_DROPFILES message is never sent and no filename appears in the list box.
Do you see a filename appear in the list box?
I am tracing the _Mess message variable and looking for the WM_DROPFILES (563 | 0x233) message but I never see it.
Do If (_Mess == WM_DROPFILES) Trace WM_DROPFILES Sleep Until Me Is Nothing
|
|
|
Post by dragonjim on Aug 2, 2022 13:19:37 GMT 1
Yes, I see the filename appear - or multiple filenames if I drag across a group (just tried it on a different computer and it still works).
Try putting a Trace in the ExtractFilenamesfromDrag sub-routine...
|
|
|
Post by (X) on Aug 2, 2022 14:26:17 GMT 1
I tried reinstalling GFA and downloading a fresh copy of the Demo. Still no filename appears. Exact same behaviour on another PC. No filename appears.
(BTW, I am trying to drag and drop the DragAndDrop.G32 file.) I see the icon change no DnD but no filename is added.
I can perform a DnD from Explorer to another subdirectory or to Desktop, so it's not as if DnD is disabled completely.
|
|
|
Post by (X) on Aug 2, 2022 15:51:45 GMT 1
I got the original demo working by fiddling with the Windows 10 DEP (Data Execution Prevention) setting (by including the DragAndDrop.exe to be excluded from DEP)
|
|
|
Post by (X) on Aug 2, 2022 17:14:18 GMT 1
I tried to download the latest GFA version from Sjouke's site and it seems to have reverted to an older version instead of the one advertised: Download GFA-BASIC 32 2.62.2621 - 14 March 2022.
|
|
|
Post by dragonjim on Aug 2, 2022 21:52:59 GMT 1
I got the original demo working by fiddling with the Windows 10 DEP (Data Execution Prevention) setting (by including the DragAndDrop.exe to be excluded from DEP) Interesting...this may be worth noting for the future. Glad you managed to get it working.
|
|
|
Post by scalion on Aug 3, 2022 7:21:31 GMT 1
Excellente démonstration, fonctionnelle, simple, efficace. Juste ce qu'il faut ! Plutôt que de faire un fastidieux copier / enregistrer / ouvrir depuis le post de bulamb0d
Merci pour ce code bulamb0d et bonne journée.
Est-ce que ça marche avec Win10? Je n'y arrive pas... --------------------- Does this work under Win10? I can't get it to work...
Yes that's work perfectly on my win10. What happened when you tried ?
|
|
|
Post by dragonjim on Aug 3, 2022 8:50:49 GMT 1
I tried to download the latest GFA version from Sjouke's site and it seems to have reverted to an older version instead of the one advertised: Download GFA-BASIC 32 2.62.2621 - 14 March 2022. Try again. This issue should be fixed now. If not, please let me know.
|
|
|
Post by (X) on Aug 11, 2022 13:30:36 GMT 1
This is the demo I came up with, (based of course on the original post):
The file: Screen capture: The code: '################################################################### ' ' DISCLAIMER: THIS CODE IS OFFERED AS IS FOR EDUCATIONAL PURPOSES. ' YOU ARE FREE TO USE, COPY AND DISTRIBUTE. ' THE USE OF THIS CODE IS AT YOUR OWN RISK. ' I ACCEPT NO LIABILITY NOR MAKE ANY CLAIM OF ' CORRECTNESS OR SUITABILITY IN PART OR IN WHOLE. ' '################################################################### ' ' FILENAME Demo Drag And Drop by (X).G32 ' ' DESCRIPTION Demonstrates the use of the Drag and Drop functions ' located in Shell32. It will not accept folder and ' .lnk files. ' ' BASED ON https://gb32.proboards.com/thread/187/source-code-drag-files-listbox ' ' AUTHOR (X) ' EMAIL xman.gb32@gmail.com ' WEBSITE https://gb32.proboards.com/ ' STARTED 2022-08-10 ' UPDATED <ISO date> ' ' $ManifestOff $Library "GfaWinX" $Library "UpdateRT" UpdateRuntime Mode Date "-"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Load form... ' LoadForm frm1
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Enable drag and drop for specified control... ' ~DragAcceptFiles(lb1.hWnd, True)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Main loop... ' Do Sleep Until frm1 Is Nothing
$Group "EVENTS" Sub frm1_Load With frm1 .Caption = App.Name EndWith EndSub
Sub frm1_MessageProc(ByRef hWnd As Long, ByRef Mess As Long, ByRef wParam As Long, ByRef lParam As Long, ByRef RetVal As Long, ByRef Valid As Boolean) If (Mess == WM_DROPFILES) ExtractFilenamesfromDrag(wParam) EndIf End Sub
Sub frm1_ReSize Dim m! = 10 With lb1 .Left = m .Top = m .Width = frm1.ScaleWidth - 2 * m .Height = frm1.ScaleHeight - 2 * m EndWith EndSub
$Group "DECLARATIONS" Declare LIB "shell32.dll" Declare FunctionA ExtractIcon (ByVal hInst%, ByVal lpszExeFileName As String, ByVal nIconIndex%) As Long Declare FunctionA DragQueryFile (ByVal hDrop%, ByVal UINT%, ByVal lpStr As String, ByVal ch%) As Long Declare Function DragQueryPoint (ByVal hDrop%, lpPoint As POINT) As Long Declare Sub DragFinish (ByVal hDrop%) Declare Sub DragAcceptFiles (ByVal hwnd%, ByVal fAccept%)
$Group "PROCEDURES" Sub ExtractFilenamesfromDrag(ByVal hDrop As Int) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Define a few local variables... ' Local pt As POINT Local Int nFiles, nSkip Local FName As String '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Pass the location (x,y point) the files were dropped... ' ~DragQueryPoint(hDrop, pt) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Get number of files dropped into window ' nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, 0, 0) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Check if any files are selected... ' If (nFiles => 0) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Go through all the selected files... ' For nSkip = 0 To nFiles - 1 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Always initiaslize FName every loop. ' FName = Space$(255) + #0 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Get filename ' ~DragQueryFile(hDrop, nSkip, FName, Len(FName) - 1) FName = ZTrim(FName) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Check if file is already added in listbox. ' If lb1.Find(FName) = -1 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Check if it is a directory. ' If GetAttr(FName) And 16 Then // Do nothing... Else If Upper(Right(FName, 4)) = ".LNK" //check if its .lnk files. // Do nothing... Else '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Add FName and to listbox ' lb1.AddItem FName EndIf EndIf EndIf Next EndIf '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Lets finish this! ' ~DragFinish(hDrop) End Sub
|
|