The Windows Programs in the Registry
Let’s take a look at one fine, upstanding citizen, and see whether you can learn anything about registry duties. If any program ought to be well-behaved under Windows 95, it’s WordPad. Figure 10-6 on page 603 shows an abbreviated version of WordPad’s registry entries on my machine, and the following list provides some explanation.
-
The DOC extension is registered as the official extension for several document types, including Microsoft Word for Windows and WordPad. DOC is a popular extension, and your machine might have other document entries.
-
WordPad is OLE-enabled so that you can embed or link WordPad documents. This is the purpose of the entry in the CLSID branch. We’re not particularly interested in this capability right now, but you can see the general idea.
-
The DOC extension is registered under QuickView so that WordPad files can be browsed when you select Quick View from a document’s context menu. It would be nice if you could enable a QuickView viewer for document types that your programs create. I’ll talk about that briefly later.
-
The document type Wordpad.Document.1 has several entries. Notice that the CLSID entry has a GUID pointing to the OLE CLSID entries. (See the second item in this list.) The DefaultIcon entry provides the location of the WordPad document icon, which is embedded as resource 1 in WORDPAD.EXE. The command entries for open, print, and printto give the command line that is invoked if you choose Open or Print from the document context menu or if you drag the document to a Printer object. If you thought command lines were out of fashion
under the enhanced Windows interface, think again. It’s a good idea
to add similar command-line options and command entries to any program that creates and manages documents.
-
All the permanent WordPad settings from dialog boxes and toolbars are saved in the registry rather than in INI files. If you use the new
Settings functions, all your 32-bit settings are saved in the same place.
-
WordPad stores its location in the App Paths branch of HKEY_LOCAL_MACHINE. This allows Windows to find and run WordPad even if
it isn’t in the PATH environment variable. For example, you can type WordPad from the Run item of the Start menu or use the Start command in a command-line session. Under MS-DOS first and later under Windows, it seemed that every setup program tried to insinuate its startup directory into the PATH environment, resulting in endless paths of long-forgotten directories. The App Paths entry allows programs to stop this rudeness, although I wouldn’t bet much that they will. By
default, setup programs created with the Setup Wizard or the Setup Toolkit will register the App Paths for you.
You have two types of registry settings: document and application. None of the sample programs in this book create their own document types, but most programs in real life do. About document types, I’ll say only that you should study the Windows interface guidelines and do the right thing. If you can write one item to the registry, you can write anything. Let’s concentrate on the application settings. The most common ones—those holding permanent program
settings—are handled for you by GetSetting, GetAllSettings, SaveSetting, and DeleteSetting.
You’ll find a small difference between the recommended settings location (followed by WordPad) and the location that is used by Visual Basic programs. The Windows interface guidelines recommend that the settings be placed under a CompanyName branch in the Software branch of HKEY_CURRENT_USER. Visual Basic settings are placed in a branch called VB and VBA Program Settings. So if your application name is the same as someone else’s Visual Basic program name, your settings could conflict with theirs. Another possibility is that multiple users might log on to the same machine. If you want settings to apply to all users of a machine rather than to the current user only, you should save the settings in HKEY_LOCAL_MACHINE. If you have any doubts about Visual Basic’s default location for settings, you should write your own registry functions to put program settings where you want them.
Figure 10-6. WordPad registry entries.
For some reason, registry editors tend to be crude and ugly. The Windows 95 editor is a step in the right direction, but it still has a long way to go to meet my user interface standards. It should be as easy to use as the Windows Explorer, and it should provide a good way to switch between related entries. So what’s the problem? All you need is a tree view on the left, a list view on the right, a toolbar, a status bar, and a few menu items. No problem.