C++ killed my grandpappy - Is C++ hard and where are the C++ coders hiding?
After learning BASIC and ASM, for a job I started coding in C, when Hello World on Windows was 92 lines of code. (Apparently Hello World is easier now, says Pete Brown)
One of my first big projects was an app called Foolproof that kept kids in high school from breaking into their school's lab computers. It had a C core engine, a TurboVision DOS component and a 16-bit Windows C++ App. I did the DOS, Win16 and later the Win32 API all in C++. Later I did some VB3, then Delphi, then worked at Nike doing Java (right when RMI was starting, and HotJava when we wrote once and debugged everywhere) until I finally ended up in managed code, mostly doing C#.
Some folks don't know Microsoft has a free C++ Express Edition of Visual Studio 2010 and that it's one of the most used free versions out there. Someone is coding C++, and they are doing a lot of it.
Are you coding in C++, Dear Reader? What are you doing?
Most "managed people" cringe at the idea of using C++, thinking it's perhaps a language of the past and that it's not even possible to write Windows Apps in C++ without a Master's Degree. ;)
However, I just noticed there's a new project called Hilo with source to show people how to use the shiny new things in Windows 7 from C++ and how to make modern Windows applications that have animations and magical stuff that managed people assume belongs only to them.
The first drop of "Hilo" is apparently the first of many, all moving towards building a larger application. This first sample is a content browser (touch enabled!) for looking at videos and photos (yeah, yeah, I know) but you could totally use it to browse other stuff or use it as underlayment for your own app. This from the Windows Team Blog:
The main technologies used in Hilo: Direct2D, Windows Animation Manager, Windows Touch, Libraries and the Shell API.
- Direct2D: For high performance and high-quality rendering of graphics.
- Windows Animation Manager: To give the application a unique personality and to improve the user experience.
- Windows Touch: To provide a more natural user interface through which the user can just “point” and “do”.
- Libraries: To enable the application to provide users with a single, coherent view of their files.
- Shell API: To navigate the images, to optimize by using the pre-built thumbnail cache and also to provide icons from actual content.
Even if you're not going to start coding C++, it's always a good idea to "see how the other half lives." For me, it's a return to what I thought I knew, and a way to look at C++ with fresh eyes.
What surprised me was that this app was written against Windows itself, with no frameworks. I always assumed you kind of needed MFC or some other library to be productive.
I'm not sure why I remember it this way, but C++ always made me think of regular expressions, and I assumed my code would **be &all like->this.you~know? You do need to know more about Windows, to be sure, as there is likely a decade of managed programmers who have forgotten what a message pump is, but it wasn't as scary as I had remembered.
Just download C++ Express, then the Hilo source, and build it. It has some cool effects with the carousel, like inertia when it spins, scaling, Z-ordering, hardware graphics acceleration. Now all they need is a designer! ;)
As an interesting example, it uses Direct 2D and has an animation for the orbit of the carousel. I removed all the if (SUCCEEDED(hr)) code from this snippet below because that's still the one thing about C++ on Windows that irks me. Don't judge then, judge me for yanking it for brevity.
This source is extremely defensive, dutifully checking HResults at every step. I mean, seriously, if it doesn't Succeed, what are you going to do about it? If (NOTSCREWED(hr)), you know.
For this source, the salient point is that there's some nice high-level Animation constructs like timers, transitions and storyboards. For some wrongheaded reason I thought it'd be a pile of math so I was pleasantly surprised.
HRESULT OrbitAnimation::Setup(D2D1_ELLIPSE targetEllipse, double targetOpacity, double duration)
HRESULT hr = S_OK;
// Animation objects
// Transition objects
// Initialize animation variables if necessary
if (nullptr == m_centerX)
hr = Initialize(targetEllipse, targetOpacity);
// Retrieve animation objects
hr = AnimationUtility::GetAnimationManager(&animationManager);
hr = AnimationUtility::GetTransitionLibrary(&transitionLibrary);
hr = AnimationUtility::GetAnimationTimer(&animationTimer);
// Initialize storyboard
hr = animationManager->CreateStoryboard(&storyboard);
// Create one transition for each orbit variable
hr = transitionLibrary->CreateLinearTransition(duration, targetEllipse.point.x, ¢erXTransition);
hr = storyboard->AddTransition(m_centerX, centerXTransition);
hr = transitionLibrary->CreateLinearTransition(duration, targetEllipse.point.y, ¢erYTransition);
hr = storyboard->AddTransition(m_centerY, centerYTransition);
hr = transitionLibrary->CreateLinearTransition(duration, targetEllipse.radiusX, &radiusXTransition);
hr = storyboard->AddTransition(m_radiusX, radiusXTransition);
hr = transitionLibrary->CreateLinearTransition(duration, targetEllipse.radiusY, &radiusYTransition);
hr = storyboard->AddTransition(m_radiusY, radiusYTransition);
hr = transitionLibrary->CreateLinearTransition(duration, targetOpacity, &opacityTransition);
hr = storyboard->AddTransition(m_opacity, opacityTransition);
hr = AnimationUtility::ScheduleStoryboard(storyboard);
I was also pleased to see that intellisense worked nicely for everything typed as well as -> deferenced pointers, as seen in the screenshot below. Call me an intellicrack addict or weak-minded but it does speed things up once you know what you're looking for. The C++ Express SKU was a small download as well.
I'm not saying it's all puppies and cotton candy, but it's not the post-apocalyptic-Where-is-John-Connor-wasteland I thought it would be. I'll be giving C++ another look as I aim to learn (or relearn) another programming language this year (along with Scala). I'll report back as this application gets bigger and more interesting.
- Developing C++ Applications for Windows 7
- Chapter 1: Introducing Hilo
The first Hilo sample application—the Hilo Browser—implements a touch-enabled user interface for browsing and selecting photos and images.
- Chapter 2: Setting up the Hilo Development Environment
This article outlines how to set up a workstation for the development environment so that you can compile and run the Hilo Browser sample application.
- Chapter 3: Choosing Windows Development Technologies.
This article describes the rationale for the choice of the development technologies used to implement the Hilo applications.
- Windows Developer Application Gallery
- Visual C++ blog post
- Windows Team blog post
- Jason Zander’s blog post
- Project Hilo page on CodeGallery
- Project Hilo on Twitter
- Pete Brown