Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Automated printing of Word doc files from Wordview
Message
 
To
09/01/1999 02:05:47
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00174307
Message ID:
00174418
Views:
23
Hi Michael,

>Essentially, I'm looking for a way to distribute Doc files and automate the printing for end users who don't have Word.

This is some demo code from my API session last DevCon. It remote controls Notepad in order to print a DOC file. Be aware that this is just a demo, but maybe it gives you some ideas.
* Einige Konstanten
#DEFINE WM_CLOSE			16
#DEFINE WM_SYSCHAR		262
#DEFINE WM_CHAR				258
#DEFINE WM_COMMAND		273
#DEFINE SW_SHOW			5
#DEFINE ALT_KEY				BitSet(0,29)
#DEFINE IDOK					1


* Wordpad starten
Local lnHWNDVfp, lnHINSTANCE
Declare Integer ShellExecute in Shell32.Dll ;
	Long Hwnd, ;
	String lpOperation, ;
	String lpFile, ;
	String lpParameters, ;
	String lpDirectory, ;
	Integer nShowCmd
Set Library to (Home()+"FoxTools.Fll") ;
	Additive
lnHWNDVfp = _WhToHwnd(_WMainWind())
lnHINSTANCE = ShellExecute( ;
	m.lnHWNDVfp, ;
	"open", ;
	"Write.Exe", ;
	"Demo.Doc", ;
	Sys(5)+CurDir(), ;
	SW_SHOW ;
)
If lnHINSTANCE <= 32
	Return
Endif


* Das Fenster suchen, maximal 5 Sekunden
Local lnHWND, lnStart
Declare Integer FindWindow in Win32API ;
	String lcClass, ;
	String lcTitle
lnStart = Seconds()
lnHWND = 0
Do While lnHWND == 0 ;
         and lnStart+5 > Seconds()
	lnHWND = ;
		FindWindow( ;
			NULL, ;
			"demo.doc - WordPad" ;
		 )
Enddo
If m.lnHWND == 0
	Return
Endif


* File|Print auswählen
Declare Integer PostMessage in Win32API ;
	Long nHWND, ;
	Long nMessage, ;
	Long wParam, ;
	Long lParam
PostMessage( ;
	m.lnHWND, ;
	WM_SYSCHAR, ;
	Asc("f"), ;
	ALT_KEY ;
)
PostMessage( ;
	m.lnHWND, ;
	WM_CHAR, ;
	Asc("p"), ;
	0;
)


* Nun den Drucker bestätigen
Local lnHWNDPrinter, lnStart
lnStart = Seconds()
lnHWNDPrinter = 0
Do While lnHWNDPrinter == 0 ;
        and lnStart+1 > Seconds()
	lnHWNDPrinter = ;
		FindWindow( NULL, "Print" )
Enddo
If m.lnHWNDPrinter == 0
	Return
Endif
PostMessage( ;
	m.lnHWNDPrinter, ;
	WM_COMMAND, ;
	IDOK, ;
	0 ;
)


* Dem Programm etwas Zeit zum 
* Drucken geben...
Inkey(1)


* Und zu guter letzt das Programm 
* beenden
PostMessage( ;
	m.lnHWND, ;
	WM_CLOSE, ;
	0, ;
	0 ;
)
Christof
--
Christof
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform