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
)
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):
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):
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
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'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.