The Display-Aware Application
You can use the following techniques to create a display-aware application:
Before performing actions that might interrupt a presentation in progress, check WM_SETTINGCHANGE to see if the user is working with presentation settings turned on.
- Get information about the display on which your application is shown, such as the screen orientation.
- Monitor the WM_DISPLAYCHANGE notification to detect when settings change or when a display is added or removed.
You can design your application to determine the display configuration when the user starts it, and to detect changes after startup. You should also design the application to recheck the display configuration when the computer resumes from sleep.
Testing for presentation settings
People don't want disruptions when they're using their mobile PCs to give a presentation. Before displaying notifications, applications should check WM_SETTINGCHANGE to determine whether the user turned on presentation settings. This way, you avoid causing embarrassment and frustration for the user.
Users can turn on presentation settings in Windows Vista when they connect their mobile PC to a network projector, connect to an additional display, or use Windows Mobility Center. Turning on presentation settings changes several options to prevent disruptions; for example, the screen saver is turned off, the display remains on, the desktop background can be changed, and volume can be muted. Notifications are delayed until presentation settings are turned off.
You can call the SHQueryUserNotificationState function immediately before displaying any notification to determine whether the user has cancelled notifications by entering presentation mode.
Getting information about the display
A mobile PC has a built-in display. The user can also connect and disconnect external displays as he or she moves from one location to another. You can check to determine on which display your application appears and how that display is configured. For example, you might check to see whether the display is in portrait orientation, and then change your window layout accordingly.
When multiple displays or projectors are set up in an extended configuration, they become part of a virtual screen that encompasses the primary display and any secondary displays. Window positions are stated in terms of this virtual screen. The origin of the primary display is 0,0, so secondary displays that are positioned to the left of or above the primary display can have negative virtual screen coordinates.
The following illustration shows the virtual screen layout for a Tablet PC with a secondary display.
.NET Framework
You can use the Screen object in the Microsoft .NET Framework 2.0 to get information about displays. Use FromControl to determine which display is showing your application. When you use the returned Screen object, you can call the following members:
- The Bounds property returns the virtual screen coordinates and dimensions of the display.
- The WorkingArea property returns the screen dimensions without elements, such as the taskbar.
- The Primary property indicates whether the display is the primary display.
The simplest way to determine whether a display is set to portrait orientation is to compare its height to its width-if the height is larger, assume portrait orientation. For example, the following C# sample uses the Bounds property to test the orientation of the current screen (the one that's showing the form):
private bool IsPortrait()
{
Screen s = Screen.FromControl(this);
return (s.Bounds.Height > s.Bounds.Width);
}
Win32 applications
There are a variety of Microsoft Win32 APIs that you can call to get information about the display. For more information, see the reference pages for the following API elements:
- EnumDisplayDevices: Enumerates the attached display devices. It populates a DISPLAY_DEVICE structure with information that includes the device name, which can be used in calls to EnumDisplaySettings.
- EnumDisplaySettings: Returns a DEVMODE structure that provides bits per pixel, width, and height for all modes that are supported by a display. You may retrieve current display device settings by assigning the value ENUM_CURRENT_SETTINGS to iModeNum.
- MonitorFromWindow: Returns a monitor handle that you can use with the GetMonitorInfo function for the display that shows the specified window.
- GetMonitorInfo: Returns a MONITORINFO structure that provides virtual screen coordinates, and indicates whether the display is primary.
- EnumDisplayMonitors: Reports information about each display that's associated with a specific display context and within an optional clipping rectangle, or for all connected displays. Information that is passed to the callback function includes a handle that you can use with GetMonitorInfo and a clipping rectangle that identifies the region of the screen in the original clipping rectangle.
Send comments about this topic to Microsoft
Build date: 2/8/2011