I’ve got a bad habit of always trying to reinvent the wheel, even when I’ve got a perfectly good wheel right in front of me.
I just wrapped up some work on a Visual FoxPro app that uses a lot of rich-text format (RTF) files, and I was hitting a brick wall when it came to printing the documents.
I tried the FoxWiki, Google searches, even went back to my KiloFox book (excerpt here), but I just couldn’t find the right method to make the program do what I wanted it to do.
Then I thought, “Hmmm… every Windows computer has an RTF editor, right? And this editor has all the print functionality built-in. Very interesting…”
Plus, if the user has word-processing software (Office, OpenOffice, etc.) and it’s properly registered as the handler for RTF files, it’ll have all the print functionality built-in, too.
So, instead of pulling out the remaining few hairs on my head, I decided to go the ShellExecute() route, and set the menu up to open the user’s default RTF application in two different ways:
- EDIT mode – (The Print menu item – the user can do what they want with the document, then select the printer, etc.)
- PRINT mode (The Quick Print menu item – open the app, and print the document to the default Windows printer)
So, I went from researching and trying all kinds of workarounds to this:
ShellExecute(FindWindow(0,_SCREEN.Caption),"Open",lcTempFile,"",JUSTPATH(lcTempFile),1)
and
ShellExecute(FindWindow(0,_SCREEN.Caption),"Print",lcTempFile,"",JUSTPATH(lcTempFile),1)
And immediately felt relieved for being just a little less hard on myself…
On a side note, the app uses the CommandBars Library from Alex Grigorjev. I was lucky enough to still have an active subscription when he released Version 7.0 (which includes the Ribbon interface).
VERY HIGHLY RECOMMENDED!!!
More info on the CommandBars library:
- The FoxShow (Episode #8: VFP Letter, Interfaces, CommandBars and Variables)
- Screencast on using the library from from Andrew MacNeill