{"id":4393,"date":"2013-05-13T07:00:00","date_gmt":"2013-05-13T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/05\/13\/how-can-i-display-a-live-screenshot-of-a-piece-of-another-application\/"},"modified":"2013-05-13T07:00:00","modified_gmt":"2013-05-13T07:00:00","slug":"how-can-i-display-a-live-screenshot-of-a-piece-of-another-application","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130513-00\/?p=4393","title":{"rendered":"How can I display a live screenshot of a piece of another application?"},"content":{"rendered":"<p><P>\nToday&#8217;s Little Program takes a rectangular portion of another application\nand continuously replicates it in its own client area.\nYou might want to do this if you want to monitor a portion\nof an application like\na custom progress bar,\nand the application doesn&#8217;t use the Windows&nbsp;7 taskbar progress\nindicator feature.\n(Maybe it&#8217;s an old application.)\n<\/P>\n<P>\nTake our\n<A HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2003\/07\/23\/54576.aspx\">\nscratch program<\/A>\nand make the following changes:\n<\/P>\n<PRE>\n#define STRICT\n#include &lt;windows.h&gt;\n#include &lt;windowsx.h&gt;\n#include &lt;ole2.h&gt;\n#include &lt;commctrl.h&gt;\n#include &lt;shlwapi.h&gt;\n<FONT COLOR=\"blue\">#include &lt;stdio.h&gt;\n#include &lt;dwmapi.h&gt;<\/FONT><\/p>\n<p>HINSTANCE g_hinst;                          \/* This application&#8217;s HINSTANCE *\/\nHWND g_hwndChild;                           \/* Optional child window *\/\n<FONT COLOR=\"blue\">HTHUMBNAIL g_hthumb;<\/FONT><\/p>\n<p>BOOL\nOnCreate(HWND hwnd, LPCREATESTRUCT lpcs)\n{\n  <FONT COLOR=\"blue\">DWM_THUMBNAIL_PROPERTIES props = {};\n  HWND hwndTarget;\n  if (sscanf(reinterpret_cast&lt;PCSTR&gt;(lpcs-&gt;lpCreateParams),\n               &#8220;%p %ld %ld %ld %ld&#8221;, &amp;hwndTarget,\n               &amp;props.rcSource.left, &amp;props.rcSource.top,\n               &amp;props.rcSource.right, &amp;props.rcSource.bottom) == 5) {\n    DwmRegisterThumbnail(hwnd, hwndTarget, &amp;g_hthumb);\n    props.dwFlags = DWM_TNP_VISIBLE | DWM_TNP_RECTSOURCE |\n                    DWM_TNP_RECTDESTINATION;\n    props.rcDestination = props.rcSource;\n    OffsetRect(&amp;props.rcSource,\n               -props.rcSource.left, -props.rcSource.top);\n    props.fVisible = TRUE;\n    DwmUpdateThumbnailProperties(g_hthumb, &amp;props);\n  }<\/FONT>\n  return TRUE;\n}  <\/p>\n<p>void\nOnDestroy(HWND hwnd)\n{\n  <FONT COLOR=\"blue\">if (g_hthumb) DwmUnregisterThumbnail(g_hthumb);<\/FONT>\n  PostQuitMessage(0);\n}<\/p>\n<p>int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev,\n                   LPSTR lpCmdLine, int nShowCmd)\n{\n   &#8230;<\/p>\n<p>        hwnd = CreateWindow(\n            &#8220;Scratch&#8221;,                      \/* Class Name *\/\n            &#8220;Scratch&#8221;,                      \/* Title *\/\n            WS_OVERLAPPEDWINDOW,            \/* Style *\/\n            CW_USEDEFAULT, CW_USEDEFAULT,   \/* Position *\/\n            CW_USEDEFAULT, CW_USEDEFAULT,   \/* Size *\/\n            NULL,                           \/* Parent *\/\n            NULL,                           \/* No menu *\/\n            hinst,                          \/* Instance *\/\n            <FONT COLOR=\"blue\">lpCmdLine<\/FONT>);\n    &#8230;\n}\n<\/PRE>\n<P>\nOur Little Program passes its command line through to the\n<CODE>WM_CREATE<\/CODE> message, which parses it as a\npointer (for Visual C++, a hex value with no <CODE>0x<\/CODE> prefix)\nand four integers representing the left, top, right, and bottom coordinates\na rectangle within that window.\n(For example, to get the upper left 100 pixels of the window,\npass <CODE>0 0 100 100<\/CODE>.)\nIt creates a thumbnail from that window and positions it inside\nthe scratch window.\n<\/P>\n<P>\nUse Spy or whatever program to get a window handle and run the progarm\nwith the window handle and four integers (described above).\nA live slice of the window will appear in the scratch program.\n<\/P>\n<P>\nMaking it easier to select the target window and a rectangle from it\nis left as an exercise.\nThis is just a Little Program.\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today&#8217;s Little Program takes a rectangular portion of another application and continuously replicates it in its own client area. You might want to do this if you want to monitor a portion of an application like a custom progress bar, and the application doesn&#8217;t use the Windows&nbsp;7 taskbar progress indicator feature. (Maybe it&#8217;s an old [&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-4393","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Today&#8217;s Little Program takes a rectangular portion of another application and continuously replicates it in its own client area. You might want to do this if you want to monitor a portion of an application like a custom progress bar, and the application doesn&#8217;t use the Windows&nbsp;7 taskbar progress indicator feature. (Maybe it&#8217;s an old [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/4393","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=4393"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/4393\/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=4393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=4393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=4393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}