Real Software Forums
http://forums.realsoftware.com/

Names, absolute path of files copied in to clipboard
http://forums.realsoftware.com/viewtopic.php?f=13&t=47888
Page 1 of 1

Author:  Shahid [ Wed May 15, 2013 6:31 pm ]
Post subject:  Names, absolute path of files copied in to clipboard

Hello,
The file names and full path for any files copied in to clipboard from within "Windows Explorer" could be read in a VB6 application as described at web link below. How can the same be done in RealBasic in Windows, Linux and MAC if the one or more files are copied in to clipboard from Windows Explorer, File Broswer?

http://stackoverflow.com/questions/2913 ... -clipboard

Thanks,

Shahid.

Author:  charonn0 [ Thu May 16, 2013 3:48 pm ]
Post subject:  Re: Names, absolute path of files copied in to clipboard

Not sure how to do this in Mac OS X or Linux, but the Windows code from that Stack Exchange article was pretty easy to translate:

Function GetFiles() As String()
Declare Function IsClipboardFormatAvailable Lib "user32" (uFormat As Integer) As Boolean
Declare Function OpenClipboard Lib "user32" (Hwnd As Integer) As Boolean
Declare Function GetClipboardData Lib "user32" (uFormat As Integer) As Integer
Declare Function CloseClipboard Lib "user32" () As Integer
Declare Function DragQueryFile Lib "shell32" Alias "DragQueryFileW" (drop_handle As Integer, UINT As Integer, lpStr As Ptr, ch As Integer) As Integer

Const CF_HDROP = 15

Dim hDrop, i As Integer
Dim aFiles() As String
Dim sFileName As New MemoryBlock(1024)

If Not IsClipboardFormatAvailable(CF_HDROP) Then Return aFiles
If Not OpenClipboard(0) Then Return aFiles
hDrop = GetClipboardData(CF_HDROP)

If hDrop > 0 Then
Dim fileCount As Integer = DragQueryFile(hDrop, -1, Nil, 0)
For i = 0 To fileCount
Call DragQueryFile(hDrop, i, sFileName, sFileName.Len)
aFiles.Append(sFileName.WString(0))
Next
End If
Call CloseClipboard()

Return aFiles
End Function

Author:  Shahid [ Sat May 18, 2013 2:07 pm ]
Post subject:  Re: Names, absolute path of files copied in to clipboard

Hello,
Thank you.

I will try the migrated code provided for RB Windows.

Thanks,

Shahid.

Author:  Shahid [ Mon Jun 03, 2013 9:54 am ]
Post subject:  Re: Names, absolute path of files copied in to clipboard

Hello,
The GetClipboardData(CF_HDROP) always seem to return a value of zero in RB while on VB6 it returns a non-zero value and works fine.

Any guidelines on how to fix this please?

Thanks and Regards,

Shahid.

Author:  charonn0 [ Mon Jun 03, 2013 12:33 pm ]
Post subject:  Re: Names, absolute path of files copied in to clipboard

What does GetLastError() say?

Author:  Shahid [ Tue Jun 04, 2013 2:53 am ]
Post subject:  Re: Names, absolute path of files copied in to clipboard

Hello,
GetLastError() also returs a zero value.

Here is the code. The "Integer" had to be changed to "Int32" and the "IsClipboardFormatAvilable" return type was changed to "Boolean" to make it work because when the old VB6 code was checked then that is how "IsClipboardFormatAvailable" was declared there.

//
// Start of file.
//
Function ClipboardHasFile() As Boolean
Dim blnReturn As Boolean
blnReturn = False
#If Not (TargetLinux) then
Soft Declare Function IsClipboardFormatAvailable Lib "user32" (uFormat As Int32) As Boolean
' Decode files in clipboard by reading the names of files
Const CF_HDROP = 15
blnReturn = IsClipboardFormatAvailable(CF_HDROP)
#Else
//
// Linux version
//
#endif
Return blnReturn
//
// End of file.
//
End Function

//
// Start of file.
//
Function ClipboardGetFiles() As String
Dim strFileNameArray() As String
#If Not (TargetLinux) then
Soft Declare Function IsClipboardFormatAvailable Lib "user32" (uFormat As Int32) As Boolean
' Decode files in clipboard by reading the names of files
Const CF_HDROP = 15
//Dim CF_HDROP As UInt32 = 15
Soft Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Int32) As Int32
Soft Declare Function CloseClipboard Lib "user32" () As Int32
Soft Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Int32) As Int32
Soft Declare Function GetLastError Lib "kernel32" () As Int32
' Other required Win32 APIs
Soft Declare Function DragQueryFile Lib "shell32.dll" Alias "DragQueryFileA" (ByVal hDrop As Int32 _
, ByVal UINT As Int32, ByVal lpStr As CString _
, ByVal ch As Int32) As Int32
Dim lngDropHandle As Int32
Dim lngNumFileNames As Int32
Dim strFileName As New MemoryBlock(1024)
Dim lngLoop As Int32
Dim lngError As Int32
' Make sure there is file data.
If ClipboardHasFiles = True Then
' File data exists. Get it.
' Open the clipboard.
If OpenClipboard(0) > 0 Then
' The clipboard is open.
' Get the handle to the dropped list of files.
lngDropHandle = GetClipboardData(CF_HDROP)
If lngDropHandle = 0 Then
lngError = GetLastError()
Else
' Get the number of dropped files.
//lngNumFileNames = DragQueryFile(lngDropHandle, -1, vbNullString, 0)
lngNumFileNames = DragQueryFile(lngDropHandle, -1, "", 0)
' Get the file names.
ReDim strFileNameArray(lngNumFileNames)
For lngLoop = 0 To lngNumFileNames-1
' Get the file name.
Call DragQueryFile( lngDropHandle, lngLoop - 1, _
strFileName, strFileName.Len)
' Truncate at the NULL character.
//strFileNameArray(lngLoop) = Left$(strFileName, InStr(strFileName, vbNullChar) - 1)
strFileNameArray.Append(strFileName.WString(0))
Next
End If
' Close the clipboard.
Call CloseClipboard
End If
End If
#Else
//
// Linux Version
//
#Endif
Return strFileNameArray
//
// End of file.
//
End Function


Thanks and Regards,

Shahid.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/