So, What Are The “Default” Colors Anyway?

The default colors are driven by the values returned by the GetSysColor function in the Windows API. We’ll be using GetSysColor when creating custom controls later in the series.

I’ve included a form, frmGetColors.scx (the download link is at the end of this post), which shows all of the current GetSysColor values based on the current Windows color scheme (or theme).

The form (pictured below) includes some Windows Event Binding code (which I stole leveraged from Tamar’s BINDEVENTS session), to automatically update the form when the Windows theme changes.

frmGetColors shows current Windows color scheme values

frmGetColors shows current Windows color scheme values

To use the GetSysColor function in Visual FoxPro, simply DECLARE the function, and then call it with one of the API Param numbers shown in the figure above:

DECLARE INTEGER GetSysColor IN WIN32API INTEGER nIndex
?GetSysColor(15) && 3DFACE (Buttons, forms)

More information about the GetSysColor Windows API function at MSDN

Download the frmGetColors.zip file here

 

 

 

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:

  • 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)
Print menu example

 

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: