Archive for February, 2009Pause Before Exiting a Console ApplicationA 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. Using the Windows Vista/Windows 7 Built-In Buffered Animation APIWindows 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. (*) 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. Using Windows Vista Built-In Double BufferingThe 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. Wallpaper Cycler: Bug Fixes and New FeaturesThe following new features have been implemented in Wallpaper Cycler:
I made the following bug fixes for Wallpaper Cycler:
|
Recent Entries
- Breaking Change for RValue References in Visual Studio 2010 RC
- Visual Studio 2010 Licensing White Paper
- Visual Studio 2010 and .NET Framework 4 Release Candidate
- Microsoft Office 2010 Beta
- Trip to Budapest Photo Album
- Happy New Year 2010
- Axialis Black Friday till Cyber Monday Promotion
- Trip to Warsaw Photo Album
- Trip to Tokyo Photo Album
- Trip to Panama Photo Album
