Visual Basic Concepts

Using the SysInfo Control

The SysInfo control can be used to detect system events such as desktop resizing, resolution changes, time changes, or to provide operating system platform and version information. You can also use it to manage changes to AC and battery power or changes in hardware configuration.

In Windows 95 (or later), whenever a new device is added to the system it is automatically detected. Your applications can benefit from this ‘plug and play’ technology by using the properties and events of the SysInfo control. Applications written specifically for notebook computers, for instance, can respond when a PC card is inserted or removed from the PC card slot.

The SysInfo control is invisible at run time.

Possible Uses

  • To determine operating system platform and version

  • To detect desktop and monitor size and resolution changes

  • To detect and manage plug and play devices

  • To monitor battery and power status

SysInfo Control Features

Using the SysInfo control, you can monitor information provided by the operating system as well as respond to system-generated events. The features of this control fall into one of the following groups:

  • Operating system properties (OSVersion and WorkAreaHeight properties, for example).

  • Events tied to changes in the system (DisplayChanged, TimeChanged, and SettingChanged events, for example).

  • Plug and Play events (DeviceArrival, DeviceRemoveComplete events, for example).

  • Power status events and properties (PowerSuspend and PowerResume events and ACStatus and BatteryStatus properties, for example).

The following sections describe the uses of these events and properties in the contexts described above.

Operating System Properties and Events

The operating system properties and events of the SysInfo control can be used to detect the current operating system and version, some global setting changes, or changes to desktop size and resolution.

Operating System Platform and Version Properties

The following table lists the properties which can be used to determine the current operating system platform and version:

Category Item Description
Properties OSPlatform Returns a value that identifies the operating system under which the application is currently running.
  OSVersion Returns a value that identifies the version of the operating system under which the application is currently running.
  OSBuild Returns a value that provides the build number of the operating system under which the application is currently running.

For More Information   "SysInfo Scenario 1: Detect the Current Operating System and Version" provides examples of how these properties are used.

Desktop Size and Screen Resolution Properties and Events

The following table lists the operating system properties and events that specifically apply to managing desktop and screen resolution changes:

Category Item Description
Properties ScrollBarSize Returns the system metric for the width of a scroll bar in twips.
  WorkAreaHeight Returns the height of the visible desktop adjusted for the taskbar found in Windows 95, Windows NT 4.0, and later systems.
  WorkAreaLeft Returns the coordinate for the left edge of the visible desktop adjusted for the taskbar found in Windows 95, Windows NT 4.0, and later systems.
  WorkAreaTop Returns the coordinate for the top edge of the visible desktop adjusted for the taskbar found in Windows 95, Windows NT 4.0, and later systems.
  WorkAreaWidth Returns the width of the visible desktop adjusted for the taskbar found in Windows 95, Windows NT 4.0, and later systems.
Events DisplayChanged Occurs when system screen resolution changes.
  SysColorsChanged Occurs when a system color setting changes, either by an application or through the Control Panel.

The DisplayChanged event is triggered when the user changes the screen resolution. Using the WorkAreaHeight, WorkAreaWidth, WorkAreaRight, and WorkAreaLeft properties with the DisplayChanged event you can determine the current system metrics (the usable screen area) and adjust accordingly. If the taskbar is visible in Windows 95, Windows NT 4.0, or later systems, it will be excluded from the calculation of usable screen area.

If the user changes the scroll bar size using the Display settings in the Windows 95 or Windows NT 4.0 (or a later system) Control Panel, it is possible that the display area will need to be updated so that the new scroll bars will be positioned correctly. You can use the ScrollBarSize property with the DisplayChanged event to adjust to this change.

For More Information   The section "SysInfo Scenario 2: Adjust to Changes in Screen Size and Resolution" provides examples of how these properties and events are used.

Managing Hardware Configuration and Plug and Play Events

If the operating system supports this feature, the plug and play events provide you with a way to manage changes in a system’s hardware configuration. For instance, if the hardware profile has changed, if the system is docked or undocked, or if a PC card has been added to or removed from a PC slot.

The following table lists the SysInfo control events that specifically apply to managing hardware configuration and Plug and Play devices.

Events Description
ConfigChanged Occurs when the hardware profile on the system has changed.
ConfigChangeCancelled Occurs when the operating system sends a message that a change to the hardware profile was cancelled.
DeviceArrival Occurs when a new device is added to the system.
DeviceEventOther A notification event that does not map onto the general events.
DevModeChange Occurs when the user changes device mode settings.
DeviceQueryRemove Occurs just before a device is removed from the system.
DeviceQueryRemoveFailed Occurs if code in the DeviceQueryRemove event cancelled the removal of a device.
DeviceRemoveComplete Occurs after a device is removed.
DeviceRemovePending Occurs after all applications have given approval to remove a device and the device is about to be removed.
QueryChangeConfig Occurs on a request to change the current hardware profile.

The ConfigChanged event notifies you when the hardware profile in Windows 95 (or a later system) has changed. Notebook computers often have separate hardware profiles for their docked and undocked configurations. When docked, the notebook may include a network connection, an external monitor, or access to a compact disc drive, for example.

The device-specific events of the SysInfo control give you feedback on changes to devices within a hardware configuration. You can write your application to dynamically make use of hardware when it’s added to the system.

Using Power Status Properties and Events

The power status events and properties can be used to monitor AC and battery power states on a desktop or notebook computer. Features like power suspend, power resume, and battery status are more likely to be implemented on a notebook computer, however, they have application across all types of computers.

The following table lists the events and properties of the SysInfo control which pertain to battery and power states:

Category Item Description
Properties ACStatus Returns a value that indicates whether the system is using AC or battery power.
  BatteryFullTime Returns a value that indicates the full charge life of the battery.
  BatteryLifePercent Returns the percentage of full battery power remaining.
  BatteryLifeTime Returns a value that indicates the remaining life of the battery.
  BatteryStatus Returns a value that indicates the status of the battery’s charge.
Events PowerQuerySuspend Occurs when system power is about to be suspended.
  PowerResume Occurs when the system comes out of suspend mode.
  PowerStatusChanged Occurs when there is a change in the power status of the system.
  PowerSuspend Occurs immediately before the system goes into suspend mode.

The power events are especially useful in providing your application with a safety net should power be suspended. The PowerSuspend event notifies your application that power is about to be suspended. You can then store the application state or any unsaved files before this occurs.

The PowerStatusChanged event informs you of changes in the AC and battery power status. If battery power is running dangerously low you can still save your data.

For More Information   The section "SysInfo Scenario 3: Monitor Battery Power Status" provides examples of how some of these properties and events are used to monitor and manage changes in battery and AC power.