Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File to Clip

Status
Not open for further replies.

TariqMehmod

Programmer
Mar 4, 2004
100
PK
Respected Seniors,

First of all I refer to this link


The codes in above thread send image to whatsapp perfectly,
Now I want to send a PDF to whatsapp.

I found this link fruitful


Link

But do not know how to pass file reference in parameter in above codes.

The link has a function like this

Code:
 FUNCTION CopyFiles2Clipboard(taFileList)

I think it copies list of files, but I want to pass a single file in function parameter like this

Code:
 cFile=getfile()
How is it possible, please help

Please help

Best Regards
 
To use the function as it is, simply put your single file name in an array that is dimensioned to just have 1 item:

Code:
Dimension Filelist[1]
Filelist[1] = getfile()
CopyFiles2Clipboard(@FileList)

Chriss
 
Respected Sir,

I have replaced as

Code:
 *--------------------------------------------------------------
*FUNCTION CopyFiles2Clipboard(taFileList)

* replaced above commented line as follows
FUNCTION CopyFiles2Clipboard(@FileList) 
*--------------------------------------------------------------

and

Code:
 *----------------------------------------------------------------------------------------
*!*	* Add zero delimited file list
*!*	FOR i= 1 TO ALEN(taFileList,1)
*!*		* 1-D and 2-D (1st column) arrays
*!*		lcDropFiles = lcDropFiles + IIF(ALEN(taFileList,2)=0, taFileList[i], taFileList[i,1]) + CHR(0)
*!*	ENDFOR

* replaced above commented lines as follows
Dimension Filelist[1]
Filelist[1] = getfile()
*-----------------------------------------------------------------------------------------

But no changes

The oriiginal codes are as follows

Code:
 * Copy list of files into Clipboard
FUNCTION CopyFiles2Clipboard(taFileList)
LOCAL lnDataLen, lcDropFiles, llOk, i, lhMem, lnPtr
#DEFINE CF_HDROP 15
 
*  Global Memory Variables with Compile Time Constants
#DEFINE GMEM_MOVABLE 	0x0002
#DEFINE GMEM_ZEROINIT	0x0040
#DEFINE GMEM_SHARE	0x2000
 
* Load required Windows API functions
=LoadApiDlls()
 
llOk = .T.
* Build DROPFILES structure
lcDropFiles = ;
		CHR(20) + REPLICATE(CHR(0),3) + ; 	&& pFiles
		REPLICATE(CHR(0),8) + ; 		&& pt
		REPLICATE(CHR(0),8)  			&& fNC + fWide
* Add zero delimited file list
FOR i= 1 TO ALEN(taFileList,1)
	* 1-D and 2-D (1st column) arrays
	lcDropFiles = lcDropFiles + IIF(ALEN(taFileList,2)=0, taFileList[i], taFileList[i,1]) + CHR(0)
ENDFOR
* Final CHR(0)
lcDropFiles = lcDropFiles + CHR(0)
lnDataLen = LEN(lcDropFiles)
* Copy DROPFILES structure into the allocated memory
lhMem = GlobalAlloc(GMEM_MOVABLE+GMEM_ZEROINIT+GMEM_SHARE, lnDataLen)
lnPtr = GlobalLock(lhMem)
=CopyFromStr(lnPtr, @lcDropFiles, lnDataLen)
=GlobalUnlock(lhMem)
* Open clipboard and store DROPFILES into it
llOk = (OpenClipboard(0) <> 0)
IF llOk
	=EmptyClipboard()
	llOk = (SetClipboardData(CF_HDROP, lhMem) <> 0)
	* If call to SetClipboardData() is successful, the system will take ownership of the memory
	*   otherwise we have to free it
	IF NOT llOk
		=GlobalFree(lhMem)
	ENDIF
	* Close clipboard 
	=CloseClipboard()
ENDIF
RETURN llOk
 
FUNCTION LoadApiDlls
*  Clipboard Functions
DECLARE LONG OpenClipboard IN WIN32API LONG HWND
DECLARE LONG CloseClipboard IN WIN32API
DECLARE LONG EmptyClipboard IN WIN32API
DECLARE LONG SetClipboardData IN WIN32API LONG uFormat, LONG hMem
*  Memory Management Functions
DECLARE LONG GlobalAlloc IN WIN32API LONG wFlags, LONG dwBytes
DECLARE LONG GlobalFree IN WIN32API LONG HMEM
DECLARE LONG GlobalLock IN WIN32API LONG HMEM
DECLARE LONG GlobalUnlock IN WIN32API LONG HMEM
DECLARE LONG RtlMoveMemory IN WIN32API As CopyFromStr LONG lpDest, String @lpSrc, LONG iLen
RETURN

Please help me
 
Don't change this original code at all. There are no changes necessary, because you provide an array as the function needs it.

The code I gave is the usage of the function.



Chriss
 
Sir whee should I paste your following codes in original codes.

Code:
 Dimension Filelist[1] Filelist[1] = getfile() CopyFiles2Clipboard(@FileList)

Regards

 
Sir I placed it on topmost line but it does not work. Can you please place it in suitable place in original codes so that i should copy a single file to clipboard.

Please
 
My code doesn't belong into the code of the function definition. The function definition doesn't need any change at all. It can stay as it is, as you copied it from Bereznikers blog.

You have to put my code wherever you want to use the function. And that's up to you, I don't know where in your application you want to copy a file to the clipboard. It's complete already, you just put it where you want to use it. I can't make it any simpler, sorry. If you want the user to pick a file for the clipboard with a button, then put it into the click event of that button.

Chriss
 
Sir may I ask the difference between putting this line in a function or under a commandbutton

Code:
 cFile=getfile()

I think the basic purpose is to get the file path in cFile variable.

Regards
 
Chris, the OP makes it very hard to help him doesn't he?
Over 57 posts back and forth on his last question...

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Griff, yes.

TariqMehmod,

Sir, please compare yourself what differs in these lines of code:

Code:
cFile=getfile()

Code:
Dimension Filelist[1]
Filelist[1] = getfile()
CopyFiles2Clipboard(@FileList)

The most important difference is, your code just stores the filename of the file a user picks with the getfile() dialog into the variable cFile. Nothing further happens with it. My code makes the call to the function you posted and that puts the file into the clipboard. You just have to put it anywhere you want to let the user pick a file for the clipboard.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top