Kevin Ragsdale: Visual FoxPro 9.0

Don’t Be So Hard On Yourself (or, ShellExecute() to the Rescue!)

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 FoxWikiGoogle 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:

 

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: