A program for my nieces: The ABCs, part 1


I'm going to spend the next few weeks developing a Little Program in several parts. This is a program I wrote for my nieces, who always wanted to play with my laptop (instead of playing with me).

Initially, I fired up Notepad and maximized it, and cranked the font size, but that became cumbersome, because I had to reset the font size and Word Wrap setting when they were done. On top of that, my eldest niece complained that some of the the letters were "wrong": The shape of the capital J in the font that I use does not match the shape of the capital J that my niece was taught. (The top serif didn't match.)

Having to change the font and then reset it was enough to make me decide to write my own program for my nieces to play with. I started with the scratch program and made these changes:

HFONT g_hfEdit;

#define MARGIN 20

void
OnSize(HWND hwnd, UINT state, int cx, int cy)
{
  if (g_hwndChild) {
    MoveWindow(g_hwndChild,
               MARGIN, MARGIN,
               cx - 2 * MARGIN,
               cy - 2 * MARGIN, TRUE);
    }
}

The MARGIN puts a little space around the edit control so it doesn't jam up against the edges of the screen.

void
OnNcDestroy(HWND hwnd)
{
    if (g_hfEdit) DeleteObject(g_hfEdit);
    PostQuitMessage(0);
}

    // HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
    HANDLE_MSG(hwnd, WM_NCDESTROY, OnNcDestroy);

The cleanup of the font is done in the WM_NC­DESTROY handler because that runs after the child windows have been destroyed. That way, we don't destroy a font while the edit control is still using it.

BOOL
OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
{
  g_hfEdit = CreateFont(-72, 0, 0, 0, FW_NORMAL,
                        FALSE, FALSE, FALSE, DEFAULT_CHARSET,
                        OUT_DEFAULT_PRECIS,
                        CLIP_DEFAULT_PRECIS,
                        DEFAULT_QUALITY,
                        DEFAULT_PITCH,
                        TEXT("Miriam"));
  if (!g_hfEdit) return FALSE;

  g_hwndChild = CreateWindow(
      TEXT("edit"),                   /* Class Name */
      NULL,                           /* Title */
      WS_CHILD | WS_VISIBLE |
      ES_UPPERCASE | ES_MULTILINE,    /* Style */
      0, 0, 0, 0,                     /* Position and size */
      hwnd,                           /* Parent */
      NULL,                           /* No menu */
      g_hinst,                        /* Instance */
      0);                             /* No special parameters */
  if (!g_hwndChild) return FALSE;

  SetWindowFont(g_hwndChild, g_hfEdit, TRUE);
  return TRUE;
}

When our main window is created, we create our helper edit control. It is a multi-line edit control without any scroll bars that forces its contents to uppercase, since they haven't learned lowercase letters yet.

My program doesn't do any painting, so I deleted the WM_PAINT and WM_PRINT­CLIENT handlers.

On the other hand, it needs to transfer focus to the edit control, so that switching to the application puts you in typing mode immediately:

void OnSetFocus(HWND hwnd, HWND hwndOldFocus)
{
  if (g_hwndChild) {
    SetFocus(g_hwndChild);
  }
}
    HANDLE_MSG(hwnd, WM_SETFOCUS, OnSetFocus);

Finally, I create the window as a fullscreen popup, so that all my nieces get is a clean screen with no window chrome. (I was using the new Microsoft design language before it was cool.)

    hwnd = CreateWindow(
        TEXT("Scratch"),                /* Class Name */
        TEXT("ABC"),                    /* Title */
        WS_POPUP,                       /* Style */
        0, 0,                           /* Position */
        GetSystemMetrics(SM_CXSCREEN),
        GetSystemMetrics(SM_CYSCREEN),  /* Size */
        NULL,                           /* Parent */
        NULL,                           /* No menu */
        hinst,                          /* Instance */
        0);                             /* No special parameters */

And there we have it. A simple program with an edit control that my nieces can use for typing.

They call this program ABC. Now when I go over to their house, they ask, "Can I play ABC?"

This program served well for a first pass, but my nieces naturally discovered problems with it. We'll look at them in future weeks.

Remember, since this is a Little Program, I'm skipping a lot of error checking, and I'm assuming that the system has only one monitor (because it runs on my laptop).

Comments (19)
  1. Thanks for reminding me just how much fun a small child can have with Microsoft Word.  I remember literal squeals of laughter when my son figured out how to change the font size on his own.  For several days, nothing was more hilarious that 3 point font followed by 300 point font.

  2. alegr1 says:

    > because I had to reset the font size and Word Wrap setting when they were done

    Are you saying YOU LET THEM PLAY ON YOUR ACCOUNT? I thought better of you.

  3. @alegr1: they are three year children, not hackers…

  4. AC says:

    "I was using the new Microsoft design language before it was cool."

    inb4 hipster

  5. Falcon says:

    @alegr1: There's no mention of Raymond's nieces using his account. Innocent until proven guilty, and all that…

  6. alegr1 says:

    >@alegr1: they are three year children, not hackers…

    …so thought other people, trying to recover their important files that disappeared… Seriously, children will get to the places you din't know exist. Raymond being (most likely) an administrator on his laptop doesn't help, either.

  7. alegr1 says:

    >@alegr1: There's no mention of Raymond's nieces using his account. Innocent until proven guilty, and all that…

    He would not have had to restore the Notepad settings back, otherwise.

    [The account is not an administrator, and the nieces are actually quite good at following instructions. If something funny happened (we'll see more about this in future installments), they would call me over. Also, I have a policy of not putting irreplaceable data on my laptop. Indeed, my laptop has very little data on it at all! (I treat my laptop as a temporary workplace, not a primary workplace.) -Raymond]
  8. Cd-MaN says:

    Came here to mention Baby Smash: http://www.hanselman.com/babysmash – maybe some of you with smaller children will find it useful.

  9. pete.d says:

    "The account is not an administrator, and the nieces are actually quite good at following instructions."

    I get that the concerns of security, unsupervised use of your account, etc. are overblown, and of no concern.

    Yet, this is still a great illustration of the "hammer/nail" metaphor.

    Our own kids loved using Notepad as an intro to the computer too. And yes, to suit their needs we had to change the font face and size. I could have written a whole new program for them to address that need. But as the _parent_ of said kids, I didn't exactly have a lot of spare time to waste on a project like that (granted, uncles without their own children have more time to spend on such things :) ).

    But giving each kid their own individual account fixed the problem in a matter of minutes, no coding required.

    I submit that as a programmer, one's first inclination might be to always write a program to solve a problem. But that's not always the best or most efficient way to do so!

  10. Joshua Ganes says:

    @pete.d – I would say you're reading too much into this. I assume that Raymond, as a very competent programmer, felt that this was a super-simple task. He could make a program that does exactly what he needs and less room to accidentally mess things up with unwanted features. He probably also thought that it would make a very simple example problem for this blog. Kill two birds with one stone, so to speak.

  11. John Doe says:

    Please allow me to remind everyone talking about accounts bla-bla-bla of this:

    http://www.xkcd.com/1200/

    And you can extend that: a child is going to use your local network, your internet connection, etc.

    On the other hand, I myself have been amazed with the effects of some sequences of keyboard chords a child can do, that what I really want is to log them! I mean, they get to things so much faster ;)

  12. Jeffrey Bosboom says:

    Not related to this post, but related to your niece: an old post mentioned she came up with the girl's name Alula.  Turns out the alula is a part of some birds' wings, analogous to the slats of an airplane's wings.  Not sure if that's where she got the name from, but it isn't a nonsense word.

  13. Bob says:

    You've been infected by the "design language" Microspeak.

  14. > …so thought other people, trying to recover their important files that disappeared…

    Ah, that brings back memories of the Oscar the Grouch program that someone wrote for the Macintosh many years ago.  Oscar would pop out and sing a little song when you dumped files in the trash, and then a different one (if I recall correctly), when you emptied the Trash.

    More than one parent paid the price for amusing their two or three year old by installing the program when, in their absence, the child proved his or her observational skills and made Oscar sing with no adult intervention at all…

  15. cheong00 says:

    I remembered that when I have chance to play with "LOGO" for the first time, it's quite addictable. (We only had Hercules Graphics at that time, so not much can be done and every seems interesting in the first time)

  16. Kythyria says:

    @John Doe: Absolutely every single one of the things in that comic is something that is (effectively) per-account or can be configured to be. All the major desktop OSes have facilities for keeping accounts quite firmly separate, that being the entire damn POINT of user accounts.

  17. Jeroen Pluimers says:

    Reminds me a lot of Baby Type that my friend Ray Konopka wrote: http://www.raize.com/…/babytype

  18. Pseudo-Anonymous says:

    I assume you were using the font Verdana, as you mentioned the shape of the capital J didn't match what your niece had been taught.

  19. >>Finally, I create the window as a fullscreen popup, so that all my nieces get is a clean screen with no window chrome. (I was using the new Microsoft design language before it was cool.)<<

    That's really nice shop-talking stuff. I think it was in the "What's new" section coming with Visual Studio 2012 where I read it, or somewhere else along these lines. For what it is worth, I did give VS 2012 a serious try, but reverted to VS 2010 not before long as there was just a little too much contents, and no chrome left at all as far as I am concerned.

    Rüdiger

Comments are closed.