We wanted to give our Visual Foxpro application a quick face lift when it’s running under modern operating systems. An easy way to do this is to change the font to Segoe UI which is the Windows 8 default font. This gives the forms a cleaner, more modern look.

However, this font isn’t available before windows Vista so we don’t want to just make a global change to all the forms. We decided to do it dynamically at run time.

We first created a procedure called SetFormProps that takes a reference to the form. The procedure checks the what operating system is in use, then changes the font and background color of the form appropriately. We decided that a white background looked more modern than the battleship gray we get by default. We did find that the white background didn’t work very well under remote desktop services, so we disable it in that case.

First, create a SetFormProps procedure that can be called from the Init for all forms:

procedure SetFormProps
	lparameters CallingForm
	local TermServices

	* GetSystemMetrics(4096) returns 1 if we're running in remote desktop services
	DECLARE INTEGER GetSystemMetrics IN user32 INTEGER nIndex
	m.TermServices = GetSystemMetrics(4096) = 1

        * Check if we're running under an O/S before Vista, or under terminal services.
	if val(os(3)) < 6  or m.TermServices
		** Set the default font to Tahoma

		m.CallingForm.setall("FontName", "Tahoma")
		m.CallingForm.setall("FontName", "Courier New", "listbox")
		m.CallingForm.setall("FontName", "Courier New", "editbox")
	else
		** Set the default font to Segoe UI

		m.CallingForm.setall("FontName", "Segoe UI")
		m.CallingForm.setall("FontName", "Courier New", "listbox")
		m.CallingForm.setall("FontName", "Courier New", "editbox")
		m.CallingForm.backcolor = rgb(255,255,255)
		m.CallingForm.setall("BackColor", rgb(255,255,255), "Page")

We need a mono-spaced font for list and edit boxes, so we make sure they stay set to Courier New.

Then, we add a call to SetFormProps to the Init method of the forms in our base classes, like this:

do SetFormProps with this

Leave a Reply

Your email address will not be published.