Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.03.27
Differences Between GDI And WPF
BasicConcepts    

The Windows Presentation Foundation (WPF) is fundamentally different from the Graphics Device Interface (GDI) and GDI+, requiring that many aspects of programming be approached in a different way. This topic briefly outlines the major differences.

Windows

Applications built using the GDI/GDI+ API use many windows, and reside under a parent window (MDI). Applications built in WPF have one window.

Unit of Measure

Applications built with a GDI/GDI+ API use the hardware pixel as the unit of measure. In these applications, as the resolution of the display device increases, the resulting image decreases. Applications built in WPF use the device-independent unit (1/96-inch) as the unit of measure. When the DPI of the system is 96, the two are equivalent.

Control Positioning

Applications built with GDI+ use absolute positioning. When the parent is resized the child elements do not get resized along with it. Applications built in WPF can use absolute, dynamic or data-bound positioning. With either absolute or dynamic positioning the controls are positioned relative to the parent element.

Image Basis

Images formed in GDI/GDI+ are pixel-based, raster images. Those formed in WPF can be scaleable, vector images.

Rendering Engine

Both GDI and GDI+ are built on Win32. GDI is based on the concept of a device context, where applications obtain handles to the device context, and use the handles in order to interact with the device. GDI+ is a wrapper around GDI that creates a C++ Graphics object. WPF, on the other hand, is built on DirectX which means that it can take advantage of hardware acceleration when performing its drawing operations.

Rendering Mode

With GDI and GDI+, rendering uses immediate rendering: the application repaints the area that becomes invalidated. In WPF, rendering uses retained rendering: the application keeps track of the drawing information but the system performs the painting.

Painting

With GDI and GDI+, clipping is used to determine the bounds of the area that has become invalidated and needs to be painted. In WPF, painting is performed from back to front and components paint over each other.

Pens and Brushes

GDI and GDI+ use the concept of a current brush and a current pen. In WPF, the brush and pen must be passed with each drawing call.

Paint Region Optimization

Paint region optimization is an important part of painting with GDI or GDI+. In WPF it is not considered.

Events

GDI and GDI+ use events and eventhandler delegates using subscription/notification. WPF uses bubbling, tunneling, and direct event notification, and the event travels up and down the VisualTree.

Video and Audio

Direct support for video and audio is not provided by GDI+ or Windows Forms, but must be obtained through a media player like Windows Media Player. WPF supports video and audio directly.

The following table summarizes these differences in rendering:

Feature Windows Forms (using GDI/GDI+) WPF
DLLs used System.dll
System.Drawing.dll
System.Windows.Forms.dll
WindowsBase.dll
PresentationCore.dll
PresentationFoundation.dll
Windows Many windows One window
Units Hardware pixels Device-independent unit (1/96-inch)
Control positioning Absolute Absolute, Dynamic, Data-bound
Image is formed by Closely spaced rows of dots (raster-based) Mathematical equations (vector-based)
Rendering engine DirectShow DirectX (Direct3D) Media Foundation
Mode Immediate - the application repaints the area that becomes invalidated Retained - the application keeps the drawing information and the system does the repainting
Painting Clipping: bounds determined and painting occurs there Rendering performed from back to front: components paint over each other
Pen and brush Current pen and current brush Appropriate pen or brush provided with each drawing call
Painting region Minimize the region to be painted Do not need to minimize
Events Events RoutedEvents
Video and Audio Requires a player like Windows Media Player Built-in support

The Windows Presentation Foundation (WPF) is different from the Graphics Device Interface (GDI) and GDI+ APIs in two major areas: as a renderer, and as a framework.

As a renderer, WPF enables you to use:

  • Animations - animate properties with WPF's built-in support for timing and screen repainting.
  • Gradients - blend colors along an axis to add highlights, shadows and 3D effects.
  • Antialiasing - improve the look of diagonals and curves by antialiasing.
  • Scalability - scale the entire user interface instead of individual drawings.
  • Translucency - increase useable screen area by employing translucency.
  • Device independence - using device independent units means that WPF applications will scale automatically to the dpi being used by the system.

As a framework, WPF enables you to use:

  • XAML - eliminate creating mock-ups in Visio or PowerPoint. Using XAML it is possible to create the user-interface for an application directly so it is ready to be coded with the business logic.
  • Styles and templates - use styles on any UI element to maintain visual consistency.
  • Data binding - bind elements so they can present or interact with data.
  • A tool to localize your application - although with Windows Forms it is possible to use either Winres.exe or Visual Studio .NET to localize a form, in WPF you can use the LocBaml tool.