don't be sure, but try your example instead of textbox with "listbox"
I am still at work and cannot check whole example. but perhaps this evening, later.
frank
hello. I tried to make drag & drop example. found something with vb and other app`s. now it`s only the textmessage missing I would like to see for file I dropped into dialog box. perhaps somebody can check my example.
[code=thinbasic]' Empty GUI script created on 01-23-2010 15:53:51 by (ThinAIR)
Uses "ui", "file"
%Attribute_Directory = 16
%textboxOne = 170
%CloseButton = 180
%MyPropertylist = 200
%MassiveFiles = 100
%myListbox = 300
Declare Function DragQueryFile Lib "shell32" Alias "DragQueryFileA" ( _
ByVal wHandle As Long, _
ByVal NumFiles As Long, _
ByVal NameBuffer As String, _
ByVal BufferLen As Long) As Long
Declare Sub DragFinish Lib "shell32" Alias "DragFinish" (ByVal wHandle As Long)
'- get property exists ?
'- pRoot = PropertyList_GetPropertyRoot(hWnd, ctrlID)
'------------------------------------------------------------------------------
Function GetDroppedFiles(ByVal hDrop As Long) As Long
hDrop = 10 '- only for dummy testing !
Local myDroppedFiles() As String
Local count As DWord
Local fString As Asciiz
Local n As Long
Local hDlg As Long
count = DragQueryFile(hDrop, %MassiveFiles, fString, 0)
If count > 0 Then
ReDim myDroppedFiles(count-1)
For n = 1 To count-1
count = DragQueryFile(hDrop,n, fString,Len(fString)-1)
myDroppedFiles(n) += Peek$(StrPtr(fString),count) & $CRLF
Function=%TRUE
Next n
End If
End Function
'------------------------------------------------------------------------------
Sub myListDroppedFiles()
Local myFileList As String
Local myDroppedFiles() As String
Local getAttr() As String
Local retVal As Long
Local n As Long
For n = 1 To UBound(myDroppedFiles)
retVal = GetAttr(myDroppedFiles(n)) '- how to get property and attributes ?
If retVal = %Attribute_Directory Then
myFileList = myFileList & "[ " & myDroppedFiles(n) & " ]" & $CRLF
Else
myFileList = myFileList & " " & myDroppedFiles(n) & " " & $CRLF
End If
Next n
MsgBox 0, "hello, you have copied: " + myFileList,%MB_OK,"Thinbasic Drag & Drop demo." 'str$(myFileList)
End Sub
'------------------------------------------------------------------------------
CallBack Function GetDroppedCallback()
Local hDlg As Long
Select Case CBMSG
Case %WM_DROPFILES
If GetDroppedFiles(CBWPARAM) Then myListDroppedFiles
DragFinish (CBWPARAM)
End Select
End Function
'------------------------------------------------------------------------------
Function tbmain() As Long
Local hDlg As Long
Local result As Long
Dialog New 0, "my drag drop demo", -1,-1, 280, 180, %DS_CENTER Or %WS_SYSMENU , %WS_EX_ACCEPTFILES To hDlg
Control Add Label, hDlg, -1, "Try and drop files on this form" & _
$CRLF & "Try muliple files and directorys at this place", 20, 20, 180, 40
Control Add Textbox, hDlg, %textboxOne, "drag to this place!", 40,40,100,100
Control Add Button, hDlg, %CloseButton, "Click to kill", 170, 130, 60, 24, Call cbDialog()
Control Add PropertyList, hdlg, %MyPropertylist, "properties", 160, 40, 80, 70, %WS_TABSTOP ', call cbPropList
Dialog Show Modal hDlg Call GetDroppedCallback
End Function
'------------------------------------------------
' Callback function used to handle dialog events
'------------------------------------------------
CallBack Function cbDialog() As Long
Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %CloseButton Then Dialog End CBHNDL
Case %WM_DESTROY
MsgBox 0, "Window is to be destroyed."
End Select
End Function[/code]
I am not sure if textbox can be best choice for message feedback of what kind of file I dropped into dialog . found no perfect answer.
tom
don't be sure, but try your example instead of textbox with "listbox"
I am still at work and cannot check whole example. but perhaps this evening, later.
frank
you can't always get what you want, but if you try sometimes you might find, you get what you need
Hi Tom,
I already started to fix your script and will get back to you in about 3-4 hours.
The problem is in the way you call the API and some other little stuff from the porting you did.
I am at work now and have to head home. As soon as my little one hits the bed, I will work further
on it.
Cheers
Michael
hi tom, may be I have one solution for you
[code=thinbasic]' Empty GUI script created on 01-23-2010 15:53:51 by (ThinAIR)
Uses "ui", "file"
%Attribute_Directory = 16
%textboxOne = 170
%CloseButton = 180
%MyPropertylist = 200
%MassiveFiles = &HFFFF '100
%myListbox = 300
Declare Function DragQueryFile Lib "shell32" Alias "DragQueryFileA" ( _
ByVal wHandle As Long, _
ByVal NumFiles As Long, _
ByVal NameBuffer As String, _
ByVal BufferLen As Long) As Long
Declare Sub DragFinish Lib "shell32" Alias "DragFinish" (ByVal wHandle As Long)
'- get property exists ?
'- pRoot = PropertyList_GetPropertyRoot(hWnd, ctrlID)
'------------------------------------------------------------------------------
'-- deleted
'------------------------------------------------------------------------------
CallBack Function GetDroppedCallback()
Local hDlg As Long
hDlg = CBHNDL
Local lParam As Long
lParam = CBWPARAM
Local myFileList As String
Local myDroppedFiles() As String
Local getAttr() As String
Local retVal,n As Long
Local leny As Long
Local counter As Long
Local drop As Long
Local fstring As String
For n = 1 To UBound(myDroppedFiles)
retVal = GetAttr(myDroppedFiles(n)) '- how to get property and attributes ?
If retVal = %Attribute_Directory Then
myFileList = myFileList & "[ " & myDroppedFiles(n) & " ]" & $CRLF
Else
myFileList = myFileList & " " & myDroppedFiles(n) & " " & $CRLF
End If
Next n
'MsgBox 0, "hello, you have copied: " + myFileList,%MB_OK,"Thinbasic Drag & Drop demo." 'str$(myFileList)
Select Case CBMSG
Case %WM_DROPFILES
drop = DragQueryFile(CBWPARAM, %MassiveFiles, %NULL, 0)
If drop > 0 Then
For Counter = 0 To (drop-1)
leny = DragQueryFile(lParam, Counter, %NULL, 0)
DragQueryFile(lParam, Counter, fString, leny+1)
LISTBOX Add CBHNDL, %myListbox, Peek$(StrPtr(fString),leny)
Next
End If
DragFinish(CBWPARAM)
Case %WM_CREATE
Case %WM_INITDIALOG
Control Add LISTBOX, CBHNDL, %myListbox, , 40, 40, 100, 100, 0, %WS_EX_LEFT
Case %WM_DESTROY
End Select
End Function
'------------------------------------------------------------------------------
Function tbmain() As Long
Local hDlg As Long
Local result As Long
Dialog New 0, "my drag drop demo", -1,-1, 280, 180, %DS_CENTER Or %WS_SYSMENU , %WS_EX_ACCEPTFILES To hDlg
Control Add Label, hDlg, -1, "Try and drop files on this form" & _
$CRLF & "Try muliple files and directorys at this place", 20, 20, 180, 40
'Control Add Textbox, hDlg, %textboxOne, "drag to this place!", 40,40,100,100
Control Add Button, hDlg, %CloseButton, "Click to kill", 170, 130, 60, 24, Call cbDialog()
Control Add PropertyList, hdlg, %MyPropertylist, "properties", 160, 40, 80, 70, %WS_TABSTOP ', call cbPropList
Dialog Show Modal hDlg Call GetDroppedCallback
End Function
'------------------------------------------------
' Callback function used to handle dialog events
'------------------------------------------------
CallBack Function cbDialog() As Long
Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %CloseButton Then Dialog End CBHNDL
Case %WM_DESTROY
MsgBox 0, "Window is to be destroyed."
End Select
End Function[/code]
try and use this, I have looked at some older and saved examples at my old machine and tried to fix your example for example using "listbox" !
necessary callback statements I have done all in one callback function part and deleted your "Function GetDroppedFiles(ByVal hDrop As Long) As Long " complete
if you choose one thinbasic file example and drag it into your form / dialog there will be shown a pathname and your thinbasic script wasn't really easy.
frank
you can't always get what you want, but if you try sometimes you might find, you get what you need
Hi Tom, this one works. Besides that you called the API wrongly, your dummy HDrop entry at the beginning of GetDroppedFiles threw my mind a little as I didn't see it at first.
[code=thinbasic]
' Empty GUI script created on 01-23-2010 15:53:51 by (ThinAIR)
Uses "ui", "file"
%Attribute_Directory = 16
%textboxOne = 170
%CloseButton = 180
%MyPropertylist = 200
'%MassiveFiles = 100
%myListbox = 300
Declare Function DragQueryFile Lib "shell32" Alias "DragQueryFileA" ( _
ByVal wHandle As DWord, _
ByVal NumFiles As DWord, _
ByVal NameBuffer As DWord, _
ByVal BufferLen As Long) As DWord
Declare Sub DragFinish Lib "shell32" Alias "DragFinish" (ByVal wHandle As Long)
Dim myDroppedFiles(1) As String
'- get property exists ?
'- pRoot = PropertyList_GetPropertyRoot(hWnd, ctrlID)
'------------------------------------------------------------------------------
Function GetDroppedFiles(ByVal hDrop As DWord) As Long
'hDrop = 10 '- only for dummy testing !
'Local myDroppedFiles() As String
Local filecount, count2 As DWord
Local fString As Asciiz * 512
'Local fString As String
Local n As Long
Local hDlg As Long
Local maxfiles As DWord
maxfiles = &hFFFFFFFF
'count = DragQueryFile(hDrop, %MassiveFiles, fString, 0)
filecount = DragQueryFile(hDrop, &hFFFFFFFF, 0, 0)
Function=%FALSE
If count > 0 Then
'ReDim myDroppedFiles(count-1)
ReDim myDroppedFiles(count)
'For n = 1 To count-1
For n = 0 To count-1
count2 = DragQueryFile(hDrop,n, StrPtr(fString),512)
myDroppedFiles(n+1) += Peek$(StrPtr(fString),count2)
Next n
Function=%TRUE
End If
End Function
'------------------------------------------------------------------------------
Sub myListDroppedFiles()
Local myFileList As String
'Local myDroppedFiles() As String
Local getAttr() As String
Local retVal As Long
Local n As Long
Local fileCount As Long
fileCount = UBound(myDroppedFiles)
For n = 1 To filecount
'retVal = GetAttr(myDroppedFiles(n)) '- how to get property and attributes ?
'If retVal = %Attribute_Directory Then
' myFileList = myFileList & "[ " & myDroppedFiles(n) & " ]" & $CRLF
'Else
myFileList = myFileList & " " & myDroppedFiles(n) & " " & $CRLF
'End If
Next n
MsgBox 0, "hello, you have copied "&Str$(filecount)&" files: " &$CRLF& myFileList,%MB_OK,"Thinbasic Drag & Drop demo." 'str$(myFileList)
End Sub
'------------------------------------------------------------------------------
CallBack Function GetDroppedCallback()
Local hDlg As Long
Select Case CBMSG
Case %WM_DROPFILES
If GetDroppedFiles(CBWPARAM) Then myListDroppedFiles
DragFinish (CBWPARAM)
End Select
End Function
'------------------------------------------------------------------------------
Function tbmain() As Long
Local hDlg As Long
Local result As Long
Dialog New 0, "my drag drop demo", -1,-1, 280, 180, %DS_CENTER Or %WS_SYSMENU , %WS_EX_ACCEPTFILES To hDlg
Control Add Label, hDlg, -1, "Try and drop files on this form" & _
$CRLF & "Try muliple files and directorys at this place", 20, 20, 180, 40
Control Add Textbox, hDlg, %textboxOne, "drag to this place!", 40,40,100,100
Control Add Button, hDlg, %CloseButton, "Click to kill", 170, 130, 60, 24, Call cbDialog()
Control Add PropertyList, hdlg, %MyPropertylist, "properties", 160, 40, 80, 70, %WS_TABSTOP ', call cbPropList
Dialog Show Modal hDlg Call GetDroppedCallback
End Function
'------------------------------------------------
' Callback function used to handle dialog events
'------------------------------------------------
CallBack Function cbDialog() As Long
Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %CloseButton Then Dialog End CBHNDL
Case %WM_DESTROY
MsgBox 0, "Window is to be destroyed."
End Select
End Function
[/code]
thanks frank, michael for help!
I've seen my mistakes. stupid things. I like franks solution one percent more because there are the file I wanted to show via drag in my dialog form (here: listbox!) . michaels solution I like too, interesting part for
does "&hFFFFFFFF = -1" value ? I can remember this from earlier c++ years. thanks for this alternative solution, I like thinbasic and to get very fast replies. I will study more about thinbasic gui's and dialog callbacks, I am not very fit with callback functions, listbox, listviews, sorry.maxfiles = &hFFFFFFFF
'count = DragQueryFile(hDrop, %MassiveFiles, fString, 0)
filecount = DragQueryFile(hDrop, &hFFFFFFFF, 0, 0)
tom
No problem I tend not to read between the lines and add stuff that wasn't asked for on my own.Originally Posted by TomLebowski
That depends on which data type you use. As a LONG type, it represents -1. As a DWORD, which does not have negative numbers, the value is 4294967295.Originally Posted by TomLebowski
Bookmarks