{"id":18683,"date":"2009-03-30T10:00:00","date_gmt":"2009-03-30T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/03\/30\/what-is-the-implementation-of-wm_printclient\/"},"modified":"2009-03-30T10:00:00","modified_gmt":"2009-03-30T10:00:00","slug":"what-is-the-implementation-of-wm_printclient","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20090330-00\/?p=18683","title":{"rendered":"What is the implementation of WM_PRINTCLIENT?"},"content":{"rendered":"<p><P>\nVia the suggestion box,\n<A HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/pages\/407234.aspx#548488\">\nMartin Filteau asks<\/A>\n<\/P>\n<BLOCKQUOTE CLASS=\"q\">\n<P>\nCould you explain the implementation of WM_PRINTCLIENT?\n<\/P>\n<P>\nIt seems that even MS got it wrong in the LISTBOX control.\n<\/P>\n<P>\nTry to AnimateWindow a window that as a LISTBOX control as a child.\nThe LISTBOX displays correctly if it is NOT empty.\nHowever, if it is empty&#8230; nothing is drawn.\n<\/P>\n<P>\nI got a similar problem when embedding an Internet Explorer control.\n<\/P>\n<P>\nThanks.\n<\/P>\n<P>\n-mf\n<\/P>\n<\/BLOCKQUOTE>\n<P>\nAs I noted back in 2003,\n<A HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2003\/07\/23\/54576.aspx\">\nthe implementation of <CODE>WM_PRINTCLIENT<\/CODE> is the same as\nthat of <CODE>WM_PAINT<\/CODE><\/A>.\nIn particular, the implementation of <CODE>WM_PRINTCLIENT<\/CODE> for\nan empty window is&#8230; to paint nothing.\nThat&#8217;s why the window is empty.\n<\/P>\n<P>\nIn other words, the listbox control is correct to draw nothing when it\nis empty.\nTo draw the empty set, you draw nothing!\n<\/P>\n<P>\nLet&#8217;s make some changes to\n<A HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2003\/07\/23\/54576.aspx\">\nthe scratch program<\/A>\nto show that animating\na window with an empty listbox as a child works just fine.\n<\/P>\n<PRE>\nBOOL\nOnCreate(HWND hwnd, LPCREATESTRUCT lpcs)\n{\n    <FONT COLOR=\"blue\">RECT rc;\n    GetClientRect(hwnd, &amp;rc);\n    g_hwndChild = CreateWindow(\n        TEXT(&#8220;listbox&#8221;), NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP,\n        0, 0,\n       (rc.right &#8211; rc.left)\/2, rc.bottom &#8211; rc.top,\n       hwnd, (HMENU)1, g_hinst, 0);<\/FONT><\/p>\n<p>    return TRUE;\n}<\/p>\n<p>BOOL\nInitApp(void)\n{\n    &#8230;\n    wc.hbrBackground = (HBRUSH)(COLOR_<FONT COLOR=\"blue\">APPWORKSPACE<\/FONT> + 1);\n    &#8230;\n}<\/p>\n<p>int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,\n                   LPSTR lpCmdLine, int nShowCmd)\n{\n    &#8230;\n        <FONT COLOR=\"blue\">\/\/ <STRIKE>ShowWindow(hwnd, nShowCmd);<\/STRIKE>\n        AnimateWindow(hwnd, 2000, AW_VER_POSITIVE);<\/FONT>\n    &#8230;\n}\n<\/PRE>\n<P>\nJust to emphasize that the white background in the listbox is really\nbeing drawn by the listbox&#8217;s <CODE>WM_ERASEBKGND<\/CODE> handler\nand isn&#8217;t just leftover pixels from its parent window,\nI&#8217;ve positioned the listbox so it covers only half of the parent\nwindow and set the parent window&#8217;s\nbackground to the application workspace color.\n(If your application workspace color is the same as\nthe window color, then set the parent background color to something else.\nI can&#8217;t believe I had to write that.)\n<\/P>\n<P>\nWith that simple set-up, we ask <CODE>AnimateWindow<\/CODE> to show\nour window, and specify a custom animation time so it&#8217;s easier to\nsee that the color is correct throughout the entire animation.\nThe listbox child window does appear correctly:\nAll you get is the window background.\nNothing is drawn. just like it&#8217;s supposed to be.\n<\/P>\n<P>\n(This particular entry falls into another category of frustrating\ncomment: The comment that claims that something doesn&#8217;t work when it does,\nand forces me to write a test program to prove it.)\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Via the suggestion box, Martin Filteau asks Could you explain the implementation of WM_PRINTCLIENT? It seems that even MS got it wrong in the LISTBOX control. Try to AnimateWindow a window that as a LISTBOX control as a child. The LISTBOX displays correctly if it is NOT empty. However, if it is empty&#8230; nothing is [&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-18683","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Via the suggestion box, Martin Filteau asks Could you explain the implementation of WM_PRINTCLIENT? It seems that even MS got it wrong in the LISTBOX control. Try to AnimateWindow a window that as a LISTBOX control as a child. The LISTBOX displays correctly if it is NOT empty. However, if it is empty&#8230; nothing is [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/18683","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=18683"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/18683\/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=18683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=18683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=18683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}