September 2009 - Posts

Zune Fail

The Zune hardware products are fantastic. The new Zune HD is particularly impressive. The Zune software is a joy to use when compared to that other product that controls 99% of the market. But until Microsoft figures out how to make the Zune Marketplace and the Zune Pass subscription service available in the rest of the world (outside of the USA) this isn’t going to go anywhere.

With the Zune 3.0 I could at least browse the marketplace even if I couldn’t purchase anything. I could for example use it to search for podcasts. That doesn’t even seem to work anymore with Zune 4.0.

Make it happen. Pretty please.

Posted by KennyKerr with 2 comment(s)

Direct2D and the Desktop Window Manager

Many moons ago, when Windows Vista was still in beta, I wrote an article showing readers how to program with the Desktop Window Manager (DWM). I also followed up with another article showing readers how to display controls on glass. Both articles focused on User32/GDI which at the time was still the way to go for native application developers.

With the introduction of Windows 7 comes a brand new graphics platform for the application developer and that of course is Direct2D. So far MSDN Magazine has published two introductory articles I wrote about Direct2D. If you haven’t already done so please read Introducing Direct2D and Drawing with Direct2D. I’ll wait.

The upcoming December issue of the magazine will feature the next installment which covers some more advanced topics related to interoperability, but for now I thought I’d update the DWM saga for Direct2D as it’s just so simple. Whereas GDI barely tolerated the DWM, Direct2D just loves it.

Let’s say you just want to render the entire client and non-client area as a seamless sheet of glass and then use Direct2D to draw on top. Start by instructing the DWM to extend the frame into the client area as follows:

MARGINS margins = { -1 };

Verify(DwmExtendFrameIntoClientArea(windowHandle,
                                    &margins));

Now all you need to do is instruct Direct2D to use the same pixel format used when alpha blending with GDI, namely pre-multiplied BGRA:

const D2D1_PIXEL_FORMAT format =
    D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM,
                      D2D1_ALPHA_MODE_PREMULTIPLIED);

The format is used when initializing the render target properties:

const D2D1_RENDER_TARGET_PROPERTIES targetProperties =
    D2D1::RenderTargetProperties(D2D1_RENDER_TARGET_TYPE_DEFAULT,
                                 format);

The render target properties are then provided to the Direct2D factory object to create the render target as usual:

Verify(m_d2dFactory->CreateHwndRenderTarget(targetProperties,
                                            windowProperties,
                                            &m_target));

And that’s all there is to it. You can now render portions of your window with glass simply by using a brush or bitmap’s alpha channel. You might for example clear the render target before drawing as follows:

m_target->Clear(D2D1::ColorF(0.0f, 0.0f, 0.0f, 0.0f));

Hope that helps.

Posted by KennyKerr with no comments
Filed under: , ,

WinUnit is Now on CodePlex

I’m totally hooked on WinUnit. As someone who writes a lot of native code it’s just absolutely essential. Up until now the only place to get it was via the download for the article that Maria wrote for MSDN Magazine.

Well I just found out via John Robbins that Maria finally got around to making a permanent home for WinUnit over on CodePlex.

http://winunit.codeplex.com/

Thanks Maria!

Posted by KennyKerr with no comments
Filed under: ,

Windows with C++: Drawing with Direct2D

My latest Windows with C++ column, "Drawing with Direct2D", just went live on the redesigned MSDN Magazine website. This is really a continuation of my previous column where I introduced Direct2D. From the article:

It is helpful to think about Direct2D as a hardware-accelerated 2-D rendering API. Of course, it supports software fallback, but the point here is that Direct2D is about rendering. Unlike other graphics APIs on Windows, Direct2D takes a componentized approach to graphics. It does not provide its own APIs for encoding and decoding bitmaps, text layout, font management, animation, 3-D and so on. Rather, it focuses on rendering and control over the graphics processing unit (GPU) while providing first class hooks to other APIs that focus on things like text layout and imaging. Direct2D does, however, provide primitives for representing different types of brushes as well as simple and complex shapes, the building blocks for any 2-D graphics application.

In this article, I'm going to show you how to draw with Direct2D. I'll begin by introducing Direct2D's color structure and then
show you how to create various types of brushes. Unlike most of the other graphics APIs on Windows, Direct2D doesn't provide a "pen" primitive, so brushes are pretty important as they're used for all outline and filling tasks. With that out of the way, I'll show you how to draw primitive shapes.

I hope you enjoy it. Right now I’m finishing up the December issue of Windows with C++ where I dive into Direct2D interoperability.

Here are links to some of the most recent Windows with C++ columns:

June 2009 – Introducing Direct2D

April 2009 – The Virtual Disk API in Windows 7

February 2009 – Visual C++ 2010 and the Parallel Patterns Library

December 2008 – x64 Debugging With Pseudo Variables and Format Specifiers

October 2008 – Exploring High-Performance Algorithms

August 2008 – Asynchronous WinHTTP

And here is a complete list.

Posted by KennyKerr with no comments
Filed under: , ,
More Posts