{"id":26,"date":"2008-11-08T22:22:00","date_gmt":"2008-11-08T22:22:00","guid":{"rendered":"http:\/\/projects-sanil.co.cc\/ProjectsBlog\/post.aspx?id=7fa7510f-1374-435a-91a5-60427aa23416"},"modified":"2008-11-08T22:22:00","modified_gmt":"2008-11-08T22:22:00","slug":"draw-on-your-desktop","status":"publish","type":"post","link":"https:\/\/inullable.in\/blog\/?p=26","title":{"rendered":"Draw on your desktop"},"content":{"rendered":"<p>\n&nbsp;\n<\/p>\n<p>\nOn a lonely sunday, was just trying to create another prank that would lead my friends to yell and cry at me&#8230;\n<\/p>\n<p>\nSo, started playing with the native window APIs\n<\/p>\n<p>\nI got these info from MSDN Library under win32 API reference (available on msdn.com).\n<\/p>\n<p>\nThe method was supposed to return handle to window having title(string) passed to the function.\n<\/p>\n<p>\nBut, with some curiosity, I tried to get desktop, via this function, and It happened to work as follows\n<\/p>\n<p>\n<strong><font color=\"#8080ff\">int hwn = FindWindow(null,&quot;Desktop&quot;);<\/font><\/strong>\n<\/p>\n<p>\n(later out, I found a direct function, for getting Desktop window -&gt; <font color=\"#8080ff\"><strong>int hwn = GetDesktopWindow()<\/strong>&nbsp;<\/font>&nbsp; )\n<\/p>\n<p>\nonce you have a handle to a window, you can create a Graphic context to that window by using a call to static function\n<\/p>\n<p>\n<strong><font color=\"#8080ff\">Graphics G = Graphics.FromHwnd((IntPtr) hwn);<\/font><\/strong>\n<\/p>\n<p>\nHere is the way to declare these functions inyour .NET code\n<\/p>\n<div id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e29a3444-759e-4638-886a-4bd977c2a21d\" class=\"wlWriterSmartContent\" style=\"margin: 0px; display: inline; padding: 0px\">\nTechnorati Tags: <a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/C++\">C++<\/a>,<a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/P\/invoke\">P\/invoke<\/a>,<a rel=\"tag\" href=\"http:\/\/technorati.com\/tags\/.NET\">.NET<\/a>\n<\/div>\n<p>\nyou need to include namespace <strong>System.Runtime.InteropServices<\/strong>\n<\/p>\n<p>\n[DllImport(&quot;user32&quot;)] <br \/>\npublic static extern int FindWindow(string A, String B);\n<\/p>\n<p>\n[DllImport(&quot;user32&quot;)] <br \/>\npublic static extern int MoveWindow(int hwnd, int x, int y, int b, int h, int BRepaint);\n<\/p>\n<p>\n[DllImport(&quot;user32&quot;)] <br \/>\npublic static extern bool SetWindowText(int hWnd, string lpString);\n<\/p>\n<p>\n[DllImport(&quot;user32&quot;)] <br \/>\npublic static extern bool AnimateWindow(int hwn, int A, int B);\n<\/p>\n<p>\n[DllImport(&quot;user32&quot;)] <br \/>\npublic static extern int GetDesktopWindow();\n<\/p>\n<p>\nUser32.dll is the dll (dynamic link library) in which these functions are defined.\n<\/p>\n<p>\nthe above technique is called as Platform Invoke (PInvoke)\n<\/p>\n<p>\nhere is a snapshot:\n<\/p>\n<p>\n<a href=\"http:\/\/projects-sanil.co.cc\/ProjectsBlog\/image.axd?picture=WindowsLiveWriter\/Drawonyourdesktop_445E\/Desktop_thumb2_2.jpg\"><img loading=\"lazy\" style=\"border: 0px\" src=\"http:\/\/projects-sanil.co.cc\/ProjectsBlog\/image.axd?picture=WindowsLiveWriter\/Drawonyourdesktop_445E\/Desktop_thumb2_thumb.jpg\" border=\"0\" alt=\"Desktop_thumb2\" width=\"588\" height=\"441\" \/><\/a>\n<\/p>\n<p>\n<strong>To download the code, go to <\/strong><a href=\"http:\/\/sanilsingh.brinkster.net\/downloads\/DesktopDraw.zip\"><strong>http:\/\/sanilsingh.brinkster.net\/downloads\/DesktopDraw.zip<\/strong><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; On a lonely sunday, was just trying to create another prank that would lead my friends to yell and cry at me&#8230; So, started playing with the native window APIs I got these info from MSDN Library under win32 API reference (available on msdn.com). The method was supposed to return handle to window having [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,201],"tags":[],"_links":{"self":[{"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=\/wp\/v2\/posts\/26"}],"collection":[{"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26"}],"version-history":[{"count":0,"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=\/wp\/v2\/posts\/26\/revisions"}],"wp:attachment":[{"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/inullable.in\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}