WPF uses HWNDs, but sparingly.

A fellow by the name of Patrick Sears asked me a question about the relationship between WPF and HWNDs.  I’m posting the answer here, for all to read.


In your intro to WPF, you state:[^]

“Another benefit of using vector graphics is it works well with high-resolution displays; something which is becoming a problem for the antiquated HWND technology as the resolution of display units improves.”

I read something to the same effect on another blog, basically that WPF is not HWND based. What is the basis for this statement? Windows (Vista included) itself is still HWND based, is it not? How can the operating system fundamentally render a window without an HWND?


The OS can’t render a window without an HWND.  WPF uses HWNDs very sparingly.  One prime example of HWNDs in WPF is the Window class.  It is a normal Windows window…receiving WM_WHATEVERs just like any other window.

Saying that WPF is not based on HWNDs has meaning within a window.  In Win32, MFC, WinForms, etc. every pixel in a Window was “owned” by a control.  Since a control was really just another window (and a window is an HWND), one could say that every pixel was owned by one and only one HWND.  That means that the graphical rendering of a Window’s client area was pretty much limited by the rendering capabilities of an HWND.  That does not include things like transformations, animations, occlusion (one pixel being rendered as a combination of two or more overlapping visual elements), etc.

WPF’s vector based rendering system introduces an array of rendering capabilities which HWNDs never even dreamed of.  Since pretty much every visual element in WPF is rendered via the vector graphics system (one notable exception being the Popup class), an entire WPF UI can make use of those features out-of-the-box.

5 Responses to WPF uses HWNDs, but sparingly.

  1. Patrick says:


    Great answer! That makes perfect sense now. It also gives some indication of how much more powerful the rendering model is now, too – you get the power of DirectX without actually having to use DirectX. I am really looking forward to learning to harness this stuff – I’m already blown away by what MS has managed to do.

  2. Josh Smith says:


    I agree. WPF is an amazing step forward for creating UIs on Windows. That’s why I’ve been a WPF fanatic for over a year now! 😀


  3. Hi Josh, sorry this is off-topic, but I couldn’t find another mechanism to contact you.

    I have a simple question, is it possible to display nesting lines in WPF TreeView controls? I must be blind, I can’t find out how to do this in the documentation.


    Eric Bergman-Terrell

  4. Josh Smith says:


    This question was answered a while back on the WPF Forum: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1170341&SiteID=1


%d bloggers like this: