Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to get File References from Clipboard
Message
 
 
À
08/07/2002 12:36:41
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00676199
Message ID:
00676413
Vues:
35
>I would like my users to be able to use windows explorer to select a bunch of files, click the right button and copy, then bring up my form in VFP and click the right button and paste. I can handle everything but getting the file references from the windows clipboard. What's the easiest way to do that?

I don't know what is the easiest way but if you're comfortable with Windows API than here's a sample code. You'll have to add error checking and adjust it to your requirements.
DECLARE Long OpenClipboard IN USER32 Long hWndNewOwner
DECLARE Long CloseClipboard IN USER32
DECLARE Long EmptyClipboard IN USER32

DECLARE Long GetClipboardData IN USER32 Long lnFormat
DECLARE Long EnumClipboardFormats IN USER32 Long lnFormat

DECLARE Long DragQueryFile IN Shell32 ;
	Long hDrop, Long iFile, String @ lpszFile, Long cch

* open clipboard
lnResult = OpenClipboard(_SCREEN.hWnd)

* Enumerate the file formats in the clipboard.
* Helpful for testing, otherwise is not required.
lnFormat = 0
lnFormat = EnumClipboardFormats(lnFormat)
lnCntr = 1
DO WHILE lnFormat > 0
	? lnCntr, lnFormat
	lnCntr = lnCntr + 1
	lnFormat = EnumClipboardFormats(lnFormat)
ENDDO

* Get handle on file list structure ( Format type 15)
lnHdrop = GetClipboardData (15)
IF lnHdrop > 0
	lcBuffer = SPACE(512)
	lnSize = 512
	lnFile = BITOR(0xFFFFFFFF,0)
        * Get the # of files in the list
	lnFileCount = DragQueryFile(lnHdrop, lnFile, @lcBuffer, lnSize  )

        * Get each file name
	FOR lnFile = 0 TO lnFileCount-1
		lnLen = DragQueryFile(lnHdrop, lnFile, @lcBuffer, lnSize  )
		? lnFile, LEFT(lcBuffer, lnLen)
	ENDFOR

ENDIF
* Empty clipboard
? EmptyClipboard()
* close clipboard
? CloseClipboard()
For detailed description of WInAPI functions used in this code see MSDN.
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform