Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1529

[VB6] Clipboard/DataObject Extension Class

$
0
0
The attached class extends VB's Clipboard and Data objects. Change its extension from .txt to .cls after downloading.

1) Support for dragging and pasting virtual files. Virtual files exist in Windows compressed folders. They also can be transfered from any application that wishes to use the registered clipboard format. Outlook, for example, uses it when dragging emails & attachments. VB does not natively support this format

2) Support for unicode file names. The clipboard's & data object's Files collection is not unicode compatible. This class replicates the Files collection that is unicode compatible.

3) Adding custom formats and standard formats to the clipboard that VB does not support natively. This class offers two methods to add data to the clipboard and data object.

The attached class also includes, for convenience, all the methods of VB's clipboard and data objects. If you use this class, you should not need to call some methods from it and some methods from VB's objects. However, you are not prevented from using VB's methods for its objects.

Virtual files used here, do not refer to files dragged out of a WinZip file. WinZip extracts the file to a temporary folder and then provides the full path/file name of the file. The dragged data was unzipped and written to file and the file(s) are accessible to VB normally. Windows compressed folders do not do this when dropping on your form.

How does the class enable virtual file access? It uses a low-level API to communicate with VB's IDataObject. That object allows us to ask the source for specific information that VB doesn't expose. No existing APIs, that I'm aware of, expose that data either. With this IDataObject, we have full control for retrieval of anything pasted to the clipboard or dropped via OLE.

One more note about virtual files. As mentioned above, don't think of these as actual files. Think of them as simply blobs of data. The file names provided by the source application should be considered for information only. Do not consider those actual file names, they may not be. Could be an Outlook attachment name. Do not assume they do not contain invalid file name characters. To view or save these data blobs, the class includes methods for saving the blobs to file or array.

Examples of a few "file names" dragged out of a Windows compressed folder follows. Notice there is no qualified path. These are not traditional files, just blobs of data.
Code:

license.txt
readme.txt
inc\jpegdecoder.h  << sub-folder items in compressed folder
inc\jpegdecoder.inl
inc\main.h

And here's an email dragged out of Outlook Express:
Code:

Welcome to Outlook Express 6.eml
Will update the class from time to time to repair errors and/or enhance.

The code is well commented. Take the time to read thru the comments at the top of the class and those comments provided with the public methods/properties.

Change History:
27 Nov 2014. Waiting on Turkey Dinner, so enhanced it a bit
- Added methods to enumerate & retrieve pasted/dropped clipboard/data formats
26 Nov 2014
- bug located where global memory during OLE Drag/Drop may not be released
- added option to save virtual file with the embedded folder structure it may have. See SaveVirtualFileAs for more
- added code to ensure Err.LastDLLError is set if some routines fail
Attached Files

Viewing all articles
Browse latest Browse all 1529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>