Advanced Tips & Tricks - Explorer style copy & paste - 09/16/02 07:29 PM
This article describes something pretty darn advanced. I feel like a god for getting it working, so I just had to post it here just in case anybody would like to make use of my genius. ( I'm always the most concieted after an accomplishment)
How is this trick useful?
Well, the project I developed this for is a MP3 player/browser. Basically I want to create a windows folder which is MP3 enabled by having a built in player and display MP3 information. So this is one of many features which must work just like a real windows folder. I want the user to be able to copy files from my "mp3 folder" and paste those files into a windows folder. Also, I want to be able to copy files from a windows folder, and paste them into the mp3 folder. To do this, I must emulate window's technique. To my surprise, there was no API's that automated things. I had to get down and dirty and do things manually. Especially when copying files.
NOTE: The below code only handles copy and pasting. It does not handle cutting. If you cut a file in a windows folder, the mp3 folder treats it like it was copied. Cutting is wierd, and I've yet to master it.
To get the VB syntax for each of the below API and structures, download API-Viewer from www.allapi.net. The DROPFILES structure however cannot be found there, so I had to figure out the syntax myself. I've provided it for your convenience. Also, SetClipboardData isn't correct under windows 2k. AllAPI says it's Alias is 'SetClipboardDataA' but that doesn't exist. Remove the alias clause and it'll work fine. Not sure it it would under 9x though.
Required API:
IsClipboardFormatAvailable
OpenClipboard
GetClipboardData
EmptyClipboard
SetClipboardData
CloseClipboard
DragQueryFile
GlobalAlloc
GlobalLock
GlobalUnlock
CopyMemory
Required STRUCTURES:
POINTAPI
Type DROPFILES
pFiles As Long
pt As POINTAPI
fNC As Long
fWide As Long
End Type
Required CONSTANTS:
GMEM_MOVEABLE = &H2
GMEM_ZEROINIT = &H40
GMEM_DDESHARE = &H2000
How is this trick useful?
Well, the project I developed this for is a MP3 player/browser. Basically I want to create a windows folder which is MP3 enabled by having a built in player and display MP3 information. So this is one of many features which must work just like a real windows folder. I want the user to be able to copy files from my "mp3 folder" and paste those files into a windows folder. Also, I want to be able to copy files from a windows folder, and paste them into the mp3 folder. To do this, I must emulate window's technique. To my surprise, there was no API's that automated things. I had to get down and dirty and do things manually. Especially when copying files.
NOTE: The below code only handles copy and pasting. It does not handle cutting. If you cut a file in a windows folder, the mp3 folder treats it like it was copied. Cutting is wierd, and I've yet to master it.
To get the VB syntax for each of the below API and structures, download API-Viewer from www.allapi.net. The DROPFILES structure however cannot be found there, so I had to figure out the syntax myself. I've provided it for your convenience. Also, SetClipboardData isn't correct under windows 2k. AllAPI says it's Alias is 'SetClipboardDataA' but that doesn't exist. Remove the alias clause and it'll work fine. Not sure it it would under 9x though.
Required API:
IsClipboardFormatAvailable
OpenClipboard
GetClipboardData
EmptyClipboard
SetClipboardData
CloseClipboard
DragQueryFile
GlobalAlloc
GlobalLock
GlobalUnlock
CopyMemory
Required STRUCTURES:
POINTAPI
Type DROPFILES
pFiles As Long
pt As POINTAPI
fNC As Long
fWide As Long
End Type
Required CONSTANTS:
GMEM_MOVEABLE = &H2
GMEM_ZEROINIT = &H40
GMEM_DDESHARE = &H2000