Sunday, April 02, 2023

Move VFP to Another Monitor

Like many developers, I have two monitors (some have even more). I like to open Outlook, VFP, and Visual Studio on my primary monitor and my browser, Word, Excel, and other apps on the other one. Sometimes, though, I want two VFP windows open, one on the primary monitor and one on the other, because I'm working on two different versions of an application at the same time. Or sometimes I have VS open on the primary monitor and want VFP open on the other one so I can work on both at the same time.

After opening VFP and dragging it to the other monitor for the 100th time, a lightbulb came on: use a hotkey to toggle VFP between the two monitors. I created this as a Thor tool and assigned Alt-2 to it. Here's the code:
Lparameters lxParam1

* Standard prefix for all tools for Thor, allowing this tool to
*   tell Thor about itself.

If Pcount() = 1						  ;
		And 'O' = Vartype (lxParam1)  ;
		And 'thorinfo' == Lower (lxParam1.Class)

	With lxParam1
		* Required
		.Prompt		   = 'Move VFP to Other Monitor'
		* Optional
		Text to .Description NoShow
Move VFP to Other Monitor
		.CanRunAtStartUp = .F.

		* These are used to group and sort tools when they are displayed in menus or the Thor form
		.Source		   = "Doug's Tools"

	Return lxParam1

If Pcount() = 0
	Do ToolCode
	Do ToolCode With lxParam1


* Normal processing for this tool begins here.                  
Procedure ToolCode
	Lparameters lxParam1
		if _screen.Left > 1900
			_screen.Left = 2
			_screen.Left = 1922
		endif _screen.Left > 1900
		_screen.Visible     = .T.
		_screen.Top         =   54
		_screen.Width       = 1916
		_screen.Height      =  950
		_screen.WindowState = 2
			&& this is needed to force thw window to draw properly
		_screen.WindowState = 0
Your dimensions might be different so adjust this code as necessary. Also, you might not want the tool to be in the Thor menu under "Doug's Tools", so set Source to something appropriate.

UPDATE: it turns out a Windows hotkey will do this: Win+Shift+Arrow Key. Thanks to Jochen Kirst├Ątter (JoKi) for pointing this out.

New VFPX Project: List Manager

Many tables have columns containing a small range of values. For example, for a customer type column in a customer table, the acceptable values might be "Business", "Consumer", and "Government". Your choices for data entry into such columns are:
  • Allow the user to type a value. This is bad idea because the user may not know what the acceptable values are or may type them incorrectly.

  • Hard-code the values in a combobox. Adding values to the list means changing the program and deploying an update.

  • Create lookup tables for the values. If there are a lot of such columns, that's a lot of tables and maintenance forms for those tables to create.
List Manager is a new VFPX project that manages lists of lookup values and provides controls so users can select values from these lists.  A single table contains all of the lookup values for an application and a single maintenance form allows users to add, edit, or remove values.

Users can select a single value from a specific type of lookup:

or select multiple values into a comma-separated string: