Registry Functions VB Help

The Windows 95/98 Registry is a hierarchical database of settings used by Windows that includes information on users, system hardware configuration, and application programs. The Registry system replaces the old INI files, where applications used to store information between sessions, used m previous versions of windows.

You access the Registry using a program called Regedit. To run Regedit follow these steps:

  1. Choose Start > Run
  2. In the Run window, type regedit and press Enter to open the Registry Editor window shown in Figure 13.9.


As you can see, if you double-click one of the items in the main Registry Editor window, the Registry stores data in a TreeView structure. The first item is usually referred to as the Registry key, and subsequent items are referred to as subkeys. The Registry keys are predefined to organize the data as follows:

  1. HKEY_CLASSES_ROOT holds OLE information about applications that have been installed or documents with particular filename extensions, such , as TXT or DOC. In addition. it maintains the list of programs that can handle each file type.
  2. HKEY_CURRENT_USER describes settings and configuration information about the user currently logged on to the computer.
  3. HKEY_lOCAL_MACHINE contains the settings for the hardware installed on the computer. The following are its subkeys:
  4. HKEY_USERS contains profiles for all users who can log on to’the machine. U only one person uses the machine, this key contains only , the .Default subkey.
  5. HKEY_CURRENT_CONFIG contains font and printer information.
  6. HKEY_DYN_DATA contains-dynamic information that should be read into the system’s RAM, because it has to be readily available to the operating system.

VB6 at Work: The Registry Project

The Registry application (see Figure 13:10) demonstrates how to create keys, store values, and get Registry data. It creates three subkeys under the HKEY_LOCAL_ MACHINE key, where it stores the dimensions of the Form from the last time it was executed:

  1. Sybex/Mastering VB 6.0
  2. Window Width
  3. Window Height

The program uses the Window Width and Window Height subkeys to store and retrieve the window width and height (the data values stored in the Registry by the Registry application are shown in Figure 13.9).

FIGURE 13.10

FIGURE 13.10

When the program starts, it attempts to retrieve the values of the subkeys Window Width and Window Height with the RegQueryValueEx() function. If these subkeys contain Values, the program simply retrieves them and sets the window width and .height. If these subkeys don’t contain values, there are no entries in the Registry. The program then gets the current window width and height and stores that information in the Registry with the RegSetValueEx() function: The RegCreateKey() function creates the specified key; if the key already exists, this function opens the key.

If you resize the window, the program saves the new window width and height to the Registry with the QueryUnload method. The next time you run the program, the application window will open at this new size. Thus, you can store you pro- gram initialization settings using the Registry and retrieve them when your application starts up. To test the Registry project, you must close the Form by clicking the Close button. If you end the application with the Run> End command in the  Visual Basic IDE, the QueryUnload event will not be triggered .

Posted on November 6, 2015 in The Windows API

Share the Story

Back to Top
Share This