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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Emailing Reports - Invoices, Orders, stuff like that without all the hassle

Status
Not open for further replies.

GriffMG

Programmer
Mar 4, 2002
6,305
FR
I'm sure you are all doing this already and I am WAAAAAAAYYYYY behind the curve, but...
Recently a new customer took one of my older systems and adopted it - he is a bit dyslexic
and struggled with printing to pdf (via PrimoPDF), naming the file, opening a new email, looking
for the file he'd just made attaching it and then sending. He wanted a 'one button' approach.

I really didn't want to add all the stuff to control his email package, don't know what he is using,
or talk to his exchange server - because these days peoples antivirus and spam programs make that a pain.

He nagged a bit so I did a search and found some code that puts named files on the PCs clipboard using
API calls. This made it so easy to implement I've been throwing it into everything, people love it - I've
been giving it away, calling it a 'treat' AND letting them take the credit in their own organisations
for coming up with it - so they then go and show everyone how to use it.

Anyway, firstly you need two functions available globally in your systems (these I copied from here
)

Code:
* Copy list of files into Clipboard
FUNCTION CopyFiles2Clipboard(taFileList)
LOCAL lnDataLen, lcDropFiles, llOk, i, lhMem, lnPtr
EXTERNAL ARRAY taFileList

#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

You also need XFRX to generate the actual PDFs and then I added an option to my printing routines
to acually do the work.

You need to include these two lines near the top of your printing code (to help VFP compile sweetly):

Code:
DIMENSION lArrFiles[1]
EXTERNAL ARRAY lArrFiles

Then I put this code (or a variation of it) in the section that controls output (I have preview, print and excel options that sort of thing):

Code:
		SELECT OPTQSDT
		SET LIBRARY TO (m.WHEREAMI+"XFRXLIB.FLL")
		m.COPYNO = 0
		LOSESSION=  XFRX('XFRX#INIT')
		LNRETVAL = LOSESSION.SETPARAMS(m.TEMPDIR+"Quotation "+m.QUOTENO+".pdf",m.TEMPDIR,.T.,,,,"PDF")
		IF LNRETVAL = 0
			LOSESSION.PROCESSREPORT("QUOTATION","OPTQSDT.QUOTENO = m.QUOTENO")
			LOSESSION.FINALIZE()
			lArrFiles[1] = m.TEMPDIR+"Quotation "+M.QUOTENO+".pdf"
			CopyFiles2Clipboard(@lArrFiles)
			MESSAGEBOX("Quotation On Clipboard Now",48,"Ready")
		ENDIF
		RELEASE LOSESSION
		SET LIBRARY TO

The m.WHEREAMI variable is a reference to where the .exe is running from
The m.TEMPDIR variable is just where temp files are stored.

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 not good for you.
 
I forgot to say, once the message comes up 'Quotation in Clipboard Now', the user just switches to their email,
starts a new message and uses the paste option (often works with Ctrl-V) to pop the quote on the email.

Works with all the installed email clients I've tried, don't know about the online ones.



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 not good for you.
 
Hi Olaf,

My point was that using this technique I do not need to know what email client he is using; Outlook, Notes, Thunderbird
and Calypso all work with no mods at all, and the code literally takes a few moments to implement in existing VFP
applications from VFP 6 onwards (tried in VFP 6 and 9) no configuration issues, no IT involvement, and the users love it.

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 not good for you.
 
Well, MAPI also is capable of automating any mail client, as long as it's mapi complient. Only web mail wouldn't be and I'm not sure which web mail services offer drag&drop or copy&paste of attachments.

Bye, Olaf.
 
Works with all the installed email clients I've tried, don't know about the online ones.

Since the only functionality you are using within the email system is the ability to paste from the clipboard, the technique should work universally throughout Windows. It's hard to imagine an email client that doesn't support pasting from the clipboard - as do all Windows-based web browsers, so it won't be a problem for on-line email systems either.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Well, Mike

if it would be about pasting text, OK. But files, attachments, no. I think GMAIL suporrts dragging and also pasting a file into a mail and redirecting that as upload to make it an attachment, outlook supports that and embeds an icon in the mail and puts the file as mail attachment, but this isn't a function most web mail clients would support, I don't think so.

Bye, Olaf.
 
Actually I just tried it in gmail and that doesn't work out, also in OWA (outlook web access).
The clipboard has the files in it and works to paste them into a windows explorer folder, so the code is ok, but pasting files is a functionality like drag&drop mainly working in desktop apps.

It's not bad, but limited.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top