TomLebowski
26-01-2010, 18:12
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.
' 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
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
' 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
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