Hello,
This is post of the onging discussion from “Real Software” forum at link below, having similar subject/title (Names, absolute path of files copied in to clipboard).
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?
Did not want to post the same in forums for all three targets so only posted in “Linux”. I need this for Windows and Linux to begin with. So please do share the details. There is some of the code posted in “Real Software” forum (at the link provided above) for WIndows that does not work in RB but works fine in VB6.
I currently use a variant of the function from the first post and use it without issues, and I have a complement for Mac OS X:
dim c as new Clipboard
[code] #if TargetMacOS then
if c.RawDataAvailable(“furl”) then
self.pboard = NSPasteboard.GeneralPboard
dim types as NSArray = pboard.Types
for i as integer = 0 to types.Count-1
dim origType as String = types.CFStringRefValue(i)
dim type as String = origType
if type.InStr("CorePasteboardFlavorType") = 1 then
// get the hex code past this word
dim hexCode as String = type.NthField(" ",2)
if hexCode.Left(2) = "0x" then
dim mb as new MemoryBlock(4)
mb.LittleEndian = false
mb.UInt32Value(0) = Val("&h"+hexCode.Mid(3))
dim code as String = mb
type = "'" + code + "'"
end
end if
select case type
case "NSFilenamesPboardType"
dim s as String = self.pboard.DataForType(origType).Data
if s.Len > 0 then
dim x as new XmlDocument
x.LoadXml(s)
dim filepaths() as FolderItem
dim e as XmlNode = x.FirstChild.FirstChild.FirstChild
while e<>Nil
dim f as new FolderItem(e.FirstChild.Value,FolderItem.PathTypeShell)
if f <> nil and f.Exists then filepaths.Append f
e = e.NextSibling
wend
dim ok as boolean
if filepaths.Ubound > -1 then
// Process your folderitems
end if
end if
end select
next #endif[/code]
[quote=14649:@Eduardo Gutierrez de Oliveira] if type.InStr(“CorePasteboardFlavorType”) = 1 then
// get the hex code past this word
dim hexCode as String = type.NthField(" “,2)
if hexCode.Left(2) = “0x” then
dim mb as new MemoryBlock(4)
mb.LittleEndian = false
mb.UInt32Value(0) = Val(”&h"+hexCode.Mid(3))
dim code as String = mb
type = “’” + code + “’”
end
[/quote]
While this thread is about Linux and Windows, I just wanted to comment on this code in case other people read this. The Clipboard class already takes care of this on OS X and you shouldn’t need all this extra code. You especially shouldn’t reference CorePasteboardFlavorType, since it’s more or less an implementation detail of OS X’s pasteboard system.
[quote=14654:@Eduardo Gutierrez de Oliveira]Thank you, Joe.
Some of this code is historical and I haven’t revised it in a while, as it works. I’ll check and remove unnecessary redundancies.
Would be nice to have a “FolderItemAvailable” in the clipboard class as we get on dropped objects :)[/quote]
If I remember right, not too costly just to get the FolderItem and compare against Nil. However, please take this to another thread if you want to continue discussion on OS X related things.
That was I who posted the RB code in “Real Software” forum and it does not work as expected. 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. And GetLastError() also returs a zero in RB.
That was I who posted the RB code in “Real Software” forum and it does not work as expected. 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. And GetLastError() also returs a zero in RB.[/quote]
My mistake, then. I guess people are not using the function in my app then.
I’ll revisit then. Will keep on the lookout for a linux alternative.