If Theodore Seuss Geissel had been an MFC Programmer
by Joseph M. Newcomer
“It’s a pretty good view,”
Said young Gerald McGrew,
“And the fellow who wrote it
Seems proud of it, too.”
"But if I wrote a view,"
Said young Gerald McGrew,
"I'd make a few changes.
That's just what I'd do..."
The icons and captions and that kind of stuff
They have up here now are not quite good enough
You see things like this in just any old view.
They’re awfully old-fashioned. I want something new!
So I’d open each file, deselect every pen,
Let the resources go, and start over again.
And, somehow or other, I think I could find,
Some GUI controls of un-usual kind
A four-sided window’s no fun in the least.
The one in my view will have ten sides, at least!
Five sides on the top, and five more underneath.
Then people will stare, and they’ll all drop their teeth!
This view-coder, new-coder Gerald’s quite keen.
That’s the gol-darndest CView I ever have seen!”
My new views, McGrew’s Views, will make people talk.
My new views, McGrew’s Views, will make people gawk
At the strangest odd views that they ever saw dock.
I’ll use for my views, a new sort-of-a-class,
Derived from another view’s subclass, and then,
Another’s derived from the subclass of his,
And another from his, and another from HIS,
And so forth and downward and onward, gee whiz!
But that’s just a start, I’ll do better than that,
They’ll see me next day, using ClassWizard, that
Will let me pull classes right out of my hat!
They’ll be so surprised; they’ll all look like they’re
They’ll ask, when they see my strange GUI things run
“Where do you suppose he gets things like that from?
His GUI things all have such strange interfaces,
He must find how to build them in rather odd places!”
And that’s what I’ll do,
Said young Gerald McGrew.
If you want to make views you don’t see every day,
You have to call functions quite out-of-the-way.
You have to call functions no others have heard of
You have to fight bugs that you’ve never had word of.
You have to read Nebbett on Win32
To find out weird things that no others can do.
In the text of his tome on odd Win32
There’s some cool APIs, if you know what to do.
And if you can use then, then what-do-you-know!
There’s more than ShowWindow(SW_SHOW)!
I’ll hunt for PARAMs
in the hills of Paramus
I’ll catenate CStrings from Sebring and Paris
I’ll make a CFrameWnd with icons that dance
Like hamsters, and this will my views all enhance.
And also, a status bar, full of surprises,
Like icons, and text fonts, in three different sizes.
I’ll code in the streets, and I’ll code in the souks,
I’ll catch every message with DLL hooks
That you don’t read about in the Microsoft books.
I’ll code with the options that no one can spell,
Like PAGABLE power bids voltage farewell,
And slider controls with TICS that don’t twitch
Since spelling ain’t what made all Microsoft rich.
I’ll fill up my kits with a picker of nits,
To help me recover an app on the fritz.
It’s pretty good doing just what it permits,
Excepting it can’t set the very high bits.
I’ll sail the CWnds,
until I GetCapture
As a new wunderkind, I’ll my users enrapture.
Then people will say, “Now I like that boy’s heap.
His new will go levels recursively deep.
He’s invented some views so completely unique,
His CViews are like a large virtual boutique.
What do you suppose he will show us next week?”
I’ll handle OnPaint,
I’ll erase my background
I’ll use a DC in ways no one has found.
I’ll master PlgBlt so my icons are skewed
I’ll show menus in ways that have never been viewed.
I’ll try to avoid all those very odd classes.
The one which include all the others, and passes
A pointer to each, from a child to mother
Whose types are connected, from one to another.
Whose types are so mixed you can’t tell them apart.
Can’t tell where they end and can’t tell where they start!
And each cast is confusing, for no one’s yet found
If this type is that, or the other way ‘round.
<dynamic_cast> never quite catches them all,
So we get an ASSERT trap at each function call.
I’ll do things with brute force; I’ll do things quite coy
I’ll do things quite weird in PostNcDestroy
I’ll VERIFY calls that no others will use,
I’ll Serialize ev’ry bit I don’t lose.
For bits that are lost, cause immense devastation,
Like footprints that grow large for each application.
I’ll utilize pointers so smart they’ve got B.A.s
And each reconnoiters their heap, without delays.
From Syracuse to Santa Cruz
Why, everyone will know my views..
For programmers will oft peruse,
My Web site, which is quite abstruse,
Which very often will confuse
By demonstrating such a use
Of APIs so far obtuse
They might have come from Betelgeuse
When people see those, they will say, “Now, by thunder!
This new view, McGrew’s View, is really a wonder!”
Most bugs are quite easy, but still, in some apps
Some bugs are too dang’rous and cause a collapse.
For pointers left dangling, or freed twice, or leak
I’ll use a BoundsChecker to help me to seek.
It’s rather expensive to buy such a kit,
But with it, a coder can never get bit.
We need to catch bugs, so we’ll use an
So when something goes wrong, we will get an alert.
But only in apps built with option _DEBUG
In Release these are often swept under the rug.
I’ll avoid my main object, from
Remove it in every project I set up..
I’ll not put globals in it, ad-hoc, willy-nilly,
Because of the fact that such structure is silly.
The massive dependency map will appall,
And each of my builds would be like “Rebuild All”
Amateurs do this instead of a global
And erroneously proclaim such effort is noble.
I’ll bag a big bug
Who is very surprising,
A bug that comes up
Only when we’re resizing
A bug that is caused
When m_hWnd is NULL
So I’ll use GetSafeHwnd,
The ASSERT to forestall
So it won’t get too small
And when I’ve caught him,
Then the next thing that’s heard,
I’ll invent a amusing
form of DWORD
With zeros that grin,
And with ones that amuse,
It’ll look mighty good
In my View of McGrew’s.
I’ll bring a CStatic,
all drawn by a MaskBlt
Whose performance is really not done as a fast BLT.
So eight worker threads will accomplish the task, it
Takes effort, how much I don’t know, so don’t ask it.
I’ll make up a new
Which spirals like many a round barber’s pole.
And scrollbars with rollbars (lest they overturn),
And TreeViews that spread out two ways, like a fern.
I’ll utilize templates, exemplar abstractions,
With arg-types and val-types and virtual actions,
Create iterators, and storage compactions..
With type-safe collections nobody can quarrel,
For we get programs whose acts behave-ior-al
Do not indicate we were cran-i-o-rectoral
I’ll go to the heap and with bits I’ll hobnobj,
And avoiding the Bobj, I’ll bring back an obj.
And with it, I’ll start up a really big jobj,
That solves a completely intractable probj.
Then people will flock to my site, in a mobj,
“McGrew”, they will say, “has done more than enobj!
He writes with such vim, and he writes with such vigor,
His new view, McGrew’s View, gets bigger and bigger!”
And, speaking of views, there’s the Russian
Whose textski is redski and backgroundski blueski.
I’ll have one of them for my Viewski McGrewski.
The whole town will gasp, “Why, this geek never sleeps!
He allocates things we don’t find in most heaps!
There’s no telling WHAT that young fellow will do!”
And then, just to show them, I’ll call upon new
and Form View
to prove I’m
(it’s a group I conform to!)
And then there’s an object of which we must talk, it’s
For network connections, the CAsyncSocket.
When called from a thread, it never will block it,
Unlike the old-fashioned blocking CSocket.
If async needs to do block it responds with EWOULDBLOCK
It would block, it could block, but prefers to eschew it.
Instead when it’s ready, a callback will do it.
So a thread will continue, of control will not lose it.
So those who love GUIs will never pooh-pooh it.
And people will say, when they see my app running,
“This app never blocks, why this boy’s rather cunning!”
And cunning I am, for I spawn many threads,
So my GUI will run, and will never stop dead.
With mutexes, semaphores, sections all critical
My designs synchronize, in some ways analytical
My mutex has cute specs, to do next, in sequence
And objects, don’t object, as bad things this prevents.
No deadlock from threadlock, for sequence canonical
Avoids any problem with odds astronomical.
And people will say, “Young McGrew’s made his mark!
His GUIs all show inspirational spark.
He’s shown us so many unusual GUIs
They’ve made him the greatest of all the McGrewies!”
“WOW!” They’ll all cheer,
“Of his views, there’s no dearth!”
They’re the gol-darndest views
On the face of the Earth!”
That's what I'd do,"
Said young Gerald McGrew.
"I'd make a few changes
If I wrote a view."
The views expressed in these essays are those of the author, and in no way represent, nor are they endorsed by, Microsoft.