Archive for May, 2009

Introduction to DirectWrite

Microsoft has added two interesting new API’s to Windows 7: Direct2D and DirectWrite. Direct2D replaces GDI and GDI+. It can render more accurate results and has support for hardware acceleration on your graphics hardware. DirectWrite is a new API to render text. It makes it easy to render paragraphs of text that can contain different formatting, coloring, fonts etc. It supports horizontal and vertical alignments, even vertical centering of a paragraph with multiple lines which was not possible with the old text API, etc. This article will give an introduction to the new DirectWrite API. Read the rest of this entry »

  • Share/Save/Bookmark

How To Use UpdateLayeredWindow

In this post I will briefly explain how to use layered windows and specifically how to use UpdateLayeredWindow.

The first thing you need to do is add the WS_EX_LAYERED style to your window. This can for example be done with a call to CreateWindowEx:

hWnd = CreateWindowEx(WS_EX_LAYERED, szWindowClass, szTitle, 0,
         CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

After your window is created we will load a PNG file with an alpha channel and use UpdateLayeredWindow to render the PNG on the window using the alpha channel of the PNG file as the transparency level for the window. This is done as follows:

// Load our PNG image
CImage img;
img.Load("circle.png");
// Get dimensions
int iWidth = img.GetWidth();
int iHeight = img.GetHeight();
// Make mem DC + mem  bitmap
HDC hdcScreen = GetDC(NULL);
HDC hDC = CreateCompatibleDC(hdcScreen);
HBITMAP hBmp = CreateCompatibleBitmap(hdcScreen, iWidth, iHeight);
HBITMAP hBmpOld = (HBITMAP)SelectObject(hDC, hBmp);
// Draw image to memory DC
img.Draw(hDC, 0, 0, iWidth, iHeight, 0, 0, iWidth, iHeight);

// Call UpdateLayeredWindow
BLENDFUNCTION blend = {0};
blend.BlendOp = AC_SRC_OVER;
blend.SourceConstantAlpha = 255;
blend.AlphaFormat = AC_SRC_ALPHA;
POINT ptPos = {0, 0};
SIZE sizeWnd = {iWidth, iHeight};
POINT ptSrc = {0, 0};
UpdateLayeredWindow(hWnd, hdcScreen, &ptPos, &sizeWnd, hDC, &ptSrc, 0, &blend, ULW_ALPHA);

SelectObject(hDC, hBmpOld);
DeleteObject(hBmp);
DeleteDC(hDC);
ReleaseDC(NULL, hdcScreen);

Because I’m using CImage, you need to include the atlimage.h header.

That’s all that is required for the basics of UpdateLayeredWindow.

NOTE: The example above does not include any error checking. That is left for the reader as an excercise.

  • Share/Save/Bookmark

Visual C++ 2010 Beta 1 and the Windows 7 RC SDK

The Visual C++ 2010 Beta 1 release contains the Windows 7 Beta SDK. For Direct2D and DirectWrite there were some breaking changes between the beta version of the SDK and the RC version of the SDK. So if you want to use those new Direct2D and DirectWrite APIs, you definitely need the latest Windows 7 RC SDK. There are some manual steps involved in getting that to work with Visual C++ 2010. For detailed explanation please check out Using the Windows 7 RC SDK in Visual C++ 2010 Beta 1 on the Visual C++ Team Blog.

  • Share/Save/Bookmark

Visual Studio 2010 and .NET FX 4 Beta 1 Released :)

Visual Studio 2010 Beta 1 and .NET FX 4 Beta 1 have been released and is available for download if you have an MSDN subscription. The beta 1 will be publicly released very soon. Check out http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx for more information.

  • Share/Save/Bookmark

Preview of Upcoming Direct2D/DirectWrite Article

I’m working on a new article to be published on Codeguru. The new article will be about using Direct2D and DirectWrite on Windows 7 from C++. 

I was really impressed while playing with those new APIs. The two APIs combined are pretty powerful and allow you to easily render complicated formatted text. The screenshot below shows what the demo application that will be included with the article is capable of rendering. The code behind everything you see in the screenshot is pretty simple.

The demo will show rendering paragraphs of text with different fonts, font sizes, styles (bold, italic, underlined…), font colors, text alignment and so on. It also shows that mixing left-to-right and right-to-left text is not a problem and how to render fancy text using special typgraphic features that are present in certain fonts. Hit testing will also be included which can for example be used to embed interactive hyperlinks into DirectWrite rendered text. Click on the screenshot to see a full sized version :)

 

NOTE: I have no idea what the Arabic piece of text is saying, so do not blame me if it says something wrong. It’s just for demonstration purposes.

  • Share/Save/Bookmark

Windows 7 on Track for Holiday Season

It seems that Microsoft Windows 7 is on track to be released in time for the holiday season of 2009. At the TechEd North America 2009 in Los Angeles, Bill Veghte said:

Microsoft is committed to ensuring that IT professionals and developers continue to have the platform and technologies to drive maximum value and business results. Getting the most out of IT investments is even more important in today’s economy.

and

With early RC testing and extensive partner feedback we’ve received, Windows 7 is tracking well for holiday availability.

Read the full press release.

  • Share/Save/Bookmark

EasyBCD: Easily Manage The Vista Bootloader

A friend of mine pointed me to EasyBCD to easily make changes to the Windows Vista Bootloader. This is expecially useful if you have installed Windows 7 in a VHD for example. If you want to remove your VHD installation, simply delete the VHD file and then use EasyBCD to remove the Windows 7 boot entry from the Bootloader.

  • Share/Save/Bookmark

Windows 7 RC Installed in VHD

I downloaded the freshly released Windows 7 Release Candidate from MSDN and was thinking on how to test it. First I thought to install it in a virtual machine, however, that means I would not be able to test with Aero enabled. A friend of mine suggested to use a new feature in the Windows 7 bootloader that allows you to boot an operating system installed inside a VHD (Virtual Hard Disk Image). On his blog he explains the steps involved in getting this to work. I followed his steps and everything went without a hitch and Windows 7 was up and running in no time, including Aero :)

The benefit of using a VHD is that you don’t need to repartition your drives. The VHD is just 1 big file but when booting from the VHD, everything looks and feels as if the operating system was installed on its own physical drive/partition.

I did encounter one anomaly while using Windows 7 booting from VHD. The Windows Experience Index cannot be computed. When asking Windows 7 RC to compute the WEI score, it gives an error saying that it cannot properly assess hard drive speed, but other than that, everything seems to be working smoothly. :)

Over the coming days I will keep testing Windows 7 RC. One thing I stumbled upon today is that Windows 7 RC seems to have built-in support for playing XVID movies. It even shows thumbnails for XVID movies in the Windows Explorer.

  • Share/Save/Bookmark

Windows 7 Release Candidate

The Windows 7 Release Candidate has been made available to MSDN and Technet subscribers. It will be available to the general public on May 5th. This RC will expire on June 1 2010. There is also a dedicated forum for Windows 7 at http://social.technet.microsoft.com/Forums/en/category/w7itpro

  • Share/Save/Bookmark

Possible KSOD (blacK Screen Of Death) Solution for Windows Vista

A few days ago, my Windows Vista on my notebook started to have the KSOD (blacK Screen Of Death) syndrome. This syndrome is that after typing your username and password on the login screen, you are presented with a black screen and a mouse, nothing else. When searching on the internet for solutions I found out that quite a few people experienced the same issue with all kinds of different solutions. I tried some suggestions like System Restore, file system check, registry changes etc etc, but nothing was working for me.

When you are presented with a KSOD, you can try to press the left SHIFT button a few times to trigger the sticky keys feature of windows. This will popup a window that contains a link. You can then click this link and from there you are able to launch different applications. Of course, if you disabled sticky keys, you are out of luck…

After wasting almost a whole day on trying everything I could think of, I stumbled upon a blog where they said that it might be related to the eventlog. To test this, I wanted to disable the eventlog. Unfortunately you cannot disable the eventlog from a running Windows because some other services are relying on it. I booted into “safe mode with command prompt”, because normal safe mode would also give me the KSOD. I disabled the eventlog and rebooted the machine and to my surprise everything worked :)

The next step was to delete all eventlog files from C:\Windows\System32\Winevt\logs, switch on the eventlog again, reboot and everything was again working :)

  • Share/Save/Bookmark