{"id":3873,"date":"2013-07-08T07:00:00","date_gmt":"2013-07-08T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/07\/08\/a-program-for-my-nieces-the-abcs-part-1\/"},"modified":"2013-07-08T07:00:00","modified_gmt":"2013-07-08T07:00:00","slug":"a-program-for-my-nieces-the-abcs-part-1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130708-00\/?p=3873","title":{"rendered":"A program for my nieces: The ABCs, part 1"},"content":{"rendered":"<p>\nI&#8217;m going to spend the next few weeks developing a Little Program\nin several parts.\nThis is a program I wrote for my nieces,\nwho always wanted to play with my laptop\n(instead of playing with <i>me<\/i>).\n<\/p>\n<p>\nInitially, I fired up Notepad and maximized it,\nand cranked the font size,\nbut that became cumbersome, because I had to reset\nthe font size and Word Wrap setting when they were done.\nOn top of that, my eldest niece complained that some\nof the the letters were &#8220;wrong&#8221;:\nThe shape of the capital J in the font that I use\ndoes not match the shape of the capital J that my niece\nwas taught.\n(The top serif didn&#8217;t match.)\n<\/p>\n<p>\nHaving to change the font and then reset it was enough\nto make me decide to write my own program for my nieces\nto play with.\nI started with\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2003\/07\/23\/54576.aspx\">\nthe scratch program<\/a>\nand made these changes:\n<\/p>\n<pre>\n<font COLOR=\"blue\">HFONT g_hfEdit;\n#define MARGIN 20<\/font>\nvoid\nOnSize(HWND hwnd, UINT state, int cx, int cy)\n{\n  if (g_hwndChild) {\n    MoveWindow(g_hwndChild,\n               <font COLOR=\"blue\">MARGIN<\/font>, <font COLOR=\"blue\">MARGIN<\/font>,\n               cx <font COLOR=\"blue\">- 2 * MARGIN<\/font>,\n               cy <font COLOR=\"blue\">- 2 * MARGIN<\/font>, TRUE);\n    }\n}\n<\/pre>\n<p>\nThe <code>MARGIN<\/code> puts a little space around the edit control\nso it doesn&#8217;t jam up against the edges of the screen.\n<\/p>\n<pre>\nvoid\nOn<font COLOR=\"blue\">Nc<\/font>Destroy(HWND hwnd)\n{\n    <font COLOR=\"blue\">if (g_hfEdit) DeleteObject(g_hfEdit);<\/font>\n    PostQuitMessage(0);\n}\n    \/\/ <font COLOR=\"red\"><strike>HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);<\/strike><\/font>\n    <font COLOR=\"blue\">HANDLE_MSG(hwnd, WM_NCDESTROY, OnNcDestroy);<\/font>\n<\/pre>\n<p>\nThe cleanup of the font is done in the\n<code>WM_NC&shy;DESTROY<\/code> handler\nbecause that runs\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2005\/07\/26\/443384.aspx\">\nafter the child windows have been destroyed<\/a>.\nThat way, we don&#8217;t destroy a font while the edit\ncontrol is still using it.\n<\/p>\n<pre>\nBOOL\nOnCreate(HWND hwnd, LPCREATESTRUCT lpcs)\n{\n  <font COLOR=\"blue\">g_hfEdit = CreateFont(-72, 0, 0, 0, FW_NORMAL,\n                        FALSE, FALSE, FALSE, DEFAULT_CHARSET,\n                        OUT_DEFAULT_PRECIS,\n                        CLIP_DEFAULT_PRECIS,\n                        DEFAULT_QUALITY,\n                        DEFAULT_PITCH,\n                        TEXT(\"Miriam\"));\n  if (!g_hfEdit) return FALSE;\n  g_hwndChild = CreateWindow(\n      TEXT(\"edit\"),                   \/* Class Name *\/\n      NULL,                           \/* Title *\/\n      WS_CHILD | WS_VISIBLE |\n      ES_UPPERCASE | ES_MULTILINE,    \/* Style *\/\n      0, 0, 0, 0,                     \/* Position and size *\/\n      hwnd,                           \/* Parent *\/\n      NULL,                           \/* No menu *\/\n      g_hinst,                        \/* Instance *\/\n      0);                             \/* No special parameters *\/\n  if (!g_hwndChild) return FALSE;\n  SetWindowFont(g_hwndChild, g_hfEdit, TRUE);<\/font>\n  return TRUE;\n}\n<\/pre>\n<p>\nWhen our main window is created,\nwe create our helper edit control.\nIt is a multi-line edit control\nwithout any scroll bars\nthat forces its contents to uppercase,\nsince they haven&#8217;t learned lowercase letters yet.\n<\/p>\n<p>\nMy program doesn&#8217;t do any painting, so I deleted the\n<code>WM_PAINT<\/code>\nand\n<code>WM_PRINT&shy;CLIENT<\/code> handlers.\n<\/p>\n<p>\nOn the other hand,\nit needs to transfer focus to the edit control,\nso that switching to the application puts you in typing mode\nimmediately:\n<\/p>\n<pre>\n<font COLOR=\"blue\">void OnSetFocus(HWND hwnd, HWND hwndOldFocus)\n{\n  if (g_hwndChild) {\n    SetFocus(g_hwndChild);\n  }\n}\n    HANDLE_MSG(hwnd, WM_SETFOCUS, OnSetFocus);<\/font>\n<\/pre>\n<p>\nFinally, I create the window as a fullscreen popup,\nso that all my nieces get is a clean screen with no\nwindow chrome.\n(I was using the new Microsoft design language before it was cool.)\n<\/p>\n<pre>\n    hwnd = CreateWindow(\n        TEXT(\"Scratch\"),                \/* Class Name *\/\n        <font COLOR=\"blue\">TEXT(\"ABC\"),                    \/* Title *\/\n        <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2005\/05\/05\/414910.aspx\">WS_POPUP<\/a>,                       \/* Style *\/\n        0, 0,                           \/* Position *\/\n        GetSystemMetrics(SM_CXSCREEN),\n        GetSystemMetrics(SM_CYSCREEN),<\/font>  \/* Size *\/\n        NULL,                           \/* Parent *\/\n        NULL,                           \/* No menu *\/\n        hinst,                          \/* Instance *\/\n        0);                             \/* No special parameters *\/\n<\/pre>\n<p>\nAnd there we have it.\nA simple program with an edit control\nthat my nieces can use for typing.\n<\/p>\n<p>\nThey call this program\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2010\/08\/25\/10053862.aspx\">\n<i>ABC<\/i><\/a>.\nNow when I go over to their house,\nthey ask,\n&#8220;Can I play ABC?&#8221;\n<\/p>\n<p>\nThis program served well for a first pass,\nbut my nieces naturally discovered problems with it.\nWe&#8217;ll look at them in future weeks.\n<\/p>\n<p>\nRemember, since this is a Little Program,\nI&#8217;m skipping a lot of error checking,\nand I&#8217;m assuming that the system has only one monitor\n(because it runs on my laptop).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-3873","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>I&#8217;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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3873","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=3873"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3873\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=3873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=3873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=3873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}