Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Sep 23, 2017 7:53 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Names, absolute path of files copied in to clipboard
PostPosted: Wed May 15, 2013 6:31 pm 
Offline

Joined: Wed May 15, 2013 6:07 pm
Posts: 13
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Names, absolute path of files copied in to clipboard
PostPosted: Thu May 16, 2013 3:48 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
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

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: Names, absolute path of files copied in to clipboard
PostPosted: Sat May 18, 2013 2:07 pm 
Offline

Joined: Wed May 15, 2013 6:07 pm
Posts: 13
Hello,
Thank you.

I will try the migrated code provided for RB Windows.

Thanks,

Shahid.


Top
 Profile  
Reply with quote  
 Post subject: Re: Names, absolute path of files copied in to clipboard
PostPosted: Mon Jun 03, 2013 9:54 am 
Offline

Joined: Wed May 15, 2013 6:07 pm
Posts: 13
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Names, absolute path of files copied in to clipboard
PostPosted: Mon Jun 03, 2013 12:33 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
What does GetLastError() say?

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: Names, absolute path of files copied in to clipboard
PostPosted: Tue Jun 04, 2013 2:53 am 
Offline

Joined: Wed May 15, 2013 6:07 pm
Posts: 13
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group