Archive for February, 2009

Some holidays :)

On wednesday my holidays are starting :)

I’m flying to New York and will stay a few days in New York. After that I’m flying to Seattle to attend the Microsoft Global MVP Summit 2009. After the summit, I’m flying to Miami and will stay around 1 week there. I’m looking forward to my trip :)

  • Share/Save/Bookmark

Pause Before Exiting a Console Application

A console application should always be designed to do whatever it is supposed to do and then exit without asking the user to press any key. The reason for this is that console applications are often used within scripts to automate several tasks. Obviously, you don’t want one console application launched by the script to wait until the user presses any key because that would be against the whole purpose of writing that script in the first place. However, sometimes it might be useful to pause the console application right before exiting. I wrote a small article that explains a way to add this support to your application elegantly without breaking support for scripting.

The article also shows how to detect that a new console was spawned on Windows. When you have a console application on Windows and you launch it by double-clicking its icon in Windows Explorer, a new console will be created but will disappear at the end of the execution and you probably won’t be able to read anything from the console. However, when you run your console application by typing the command in an existing console, your application will write all its output to that console and, when finished, you will be returned to the console prompt without the console being closed. There is a trick that can be used on Windows to automatically detect whether a new console window was opened or if your application was started from inside an existing console. The trick is to find out the cursor position in your console at the very beginning of your program. If the cursor position is (0,0), it is highly likely that a new console window was spawned. The article contains some source code to demonstrate this trick.

Read the full article.

  • Share/Save/Bookmark

Using the Windows Vista/Windows 7 Built-In Buffered Animation API

Windows Vista comes with a built-in buffered animation API. This API makes it easy to make animations without flickering(*). I wrote a new article on CodeGuru that explains how to use this Buffered Animation API with C++.

The article comes with an example application to illustrate the Windows Vista buffered animation technique. The example will draw a new colored random rectangle in the window each time you press the spacebar. The new rectangle will smoothly fade onto the window. The buffered animation is used for this fading effect.

Read the full article.

(*) Note: While writing the article, I found an issue with the DWM in Windows Vista. After discussing with someone from Microsoft, it seems the buffered animation API is relying on some buffering from the DWM; however, on Windows Vista this is causing some flickering. They also told me that the buffered animation was not designed for big or full-screen animations but rather for small animations like fading buttons. To reduce the flickering as much as possible, only use the buffered animation on small rectangles and use a short animation interval, for example 500 milliseconds, which is more than enough for GUI related animations anyway.

The good news is that I tested the application on Windows 7 Beta and it works without any flickering. So, it seems that the DWM issue has been fixed on Windows 7.

  • Share/Save/Bookmark

Using Windows Vista Built-In Double Buffering

The solution to fixing flickering issues when drawing graphics is to use double buffering. Double buffering basically means that an off-screen buffer is created. Everything is rendered to this off-screen buffer and, when drawing is completed, this off-screen buffer is copied to the screen. The end result is that you do not see any flickering and you do not see the drawing being created part by part. A little unknown fact is that Windows Vista has built-in support for double buffering, so managing off-screen buffers, copying data, and so forth are all managed by Windows for you. I wrote an article including an example on how to use this built-in support for double buffering with C++. This article has been published on CodeGuru.

Read the full article.

  • Share/Save/Bookmark

Wallpaper Cycler: Bug Fixes and New Features

The following new features have been implemented in Wallpaper Cycler:

  • You can now rotate any image by 90°, 180° or 270°.
  • The N/A that was rendered to the desktop when something went wrong with processing a news feed can now be disabled in the global WPC settings. When disabled, WPC will not render any text when a news feed error happens.
  • Also allow F2 and Slow Double Click to rename wallpapers, however, in that case a dialog pops up in which you do the renaming, because a warning message has to be displayed.
  • You can now press CTRL+C in the EXIF data dialog to copy the selected EXIF data to the clipboard.
  • A new option in Tools > Program Settings > Miscellaneous to disable the error balloons that are shown when something goes wrong while downloading a news feed.
  • Added a button to the toolbar to quickly change the cycling settings (delay between wallpapers).
  • Added a button to the toolbar to quickly change the cycling sound.

I made the following bug fixes for Wallpaper Cycler:

  • Error messages during rendering appeared behind main WPC window, causing confusion.
  • Calendar template “Bright” has 2 times the year at the top.
  • Cycling is working now on Windows 7 :)
  • The “Random” screensaver transition effect was not that ‘random’ + sometimes a bit slow.
  • Wallpaper Cycler can rerender the wallpaper automatically when the screen resolution has changed. This is an old feature, but is now enabled by default.
  • The “Spiral In” and “Box In” screensaver transition effects left a 3-5 pixel horizontal line in the middle of the screen when running at 1440×900.
  • Link targets didn’t work on wallpaper objects, calendar objects and frame objects.
  • Removed font references to Californian in templates since that’s not a font installed by default on Windows.
  • The text object renderer in a layout again properly calculates the bounding box.
  • WPC would crash when a layout contained a calendar object that was too small to render all days.
  • WPC would crash when a layout contained an object with a width or height of 0.
  • Rendering of gradients was broken after adding the rotation option to wallpapers.
  • The small preview image in the OSD was sometimes cut off.
  • The pick background/text color dialogs now correctly keep aspect ratio of the image.
  • The info panel will now allow you to quickly check if a wallpaper is linked to a layout either directly or indirectly through one of its parent categories.
  • The RSS feeds again show a brief description of a feed entry and not the entire entry.
  • View Details/Thumbnails now have an icon in the Wallpapers menu.
  • Open a wcl, then go to File>Open, click Cancel, previous WCL was closed.
  • Removed dots behind “move layout up…”, “move layout down…” menu items.
  • An issue with resizing the main window and the tiling combo box in the Info Panel.
  • Share/Save/Bookmark