{"id":2490,"date":"2012-05-15T02:19:23","date_gmt":"2012-05-14T17:19:23","guid":{"rendered":"http:\/\/nanoappli.com\/blog\/?p=2490"},"modified":"2012-05-15T02:19:23","modified_gmt":"2012-05-14T17:19:23","slug":"cwebbrowser%e3%82%b3%e3%83%b3%e3%83%88%e3%83%ad%e3%83%bc%e3%83%ab%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e3%80%81%e6%8c%87%e5%ae%9a%e3%81%97%e3%81%9f%e3%82%b5%e3%82%a4%e3%83%88%e5%85%a8","status":"publish","type":"post","link":"http:\/\/nanoappli.com\/blog\/archives\/2490","title":{"rendered":"[C#]WebBrowser\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3092\u4f7f\u7528\u3057\u3066\u3001\u6307\u5b9a\u3057\u305f\u30b5\u30a4\u30c8\u5168\u4f53\u306e\u753b\u50cf\u3092\u53d6\u5f97(DLL\u5316\u3057\u307e\u3057\u305f)"},"content":{"rendered":"<p>\nWebBrowser\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3092\u4f7f\u7528\u3057\u3066\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089\u6307\u5b9a\u3057\u305f\u30b5\u30a4\u30c8\u5168\u4f53\u306e\u753b\u50cf\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<br \/>\n<br \/>\n\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306f\u3001\u4ee5\u4e0b\u306e\u901a\u308a\u3002<br \/>\n<pre lang=\"csharp\">\nusing System;\nusing System.Drawing;\nusing System.Runtime.InteropServices;\nusing System.Windows.Forms;\nusing System.Runtime.InteropServices.ComTypes;\n\nnamespace SiteCaptureSharp {\n    \/\/*************************************************************************\n    \/\/\/ <summary> Web\u30b5\u30a4\u30c8\u306e\u753b\u50cf\u30a4\u30e1\u30fc\u30b8\u30ad\u30e3\u30d7\u30c1\u30e3\u51e6\u7406\u3092\u7ba1\u7406\u3057\u307e\u3059\n    \/\/\/ <\/summary>\n    \/\/*************************************************************************\n    public class CaptureManager {\n        [DllImport(\"ole32.dll\")]\n        private static extern int OleDraw( IntPtr pUnk, int dwAspect, IntPtr hdcDraw, ref Rectangle lprcBounds );\n\n        \/\/*********************************************************************\n        \/\/\/ <summary>\u3000\u6307\u5b9a\u3055\u308c\u305fWeb\u30b5\u30a4\u30c8\u3092bitmap\u753b\u50cf\u3068\u3057\u3066\u53d6\u5f97\u3059\u308b\n        \/\/\/ <\/summary>\n        \/\/\/ <param name=\"url\">\u30ad\u30e3\u30d7\u30c1\u30e3\u5bfe\u8c61\u306e\u30b5\u30a4\u30c8URL<\/param>\n        \/\/\/ <returns>         \u30da\u30fc\u30b8\u306e\u753b\u50cf<\/returns>\n        \/\/*********************************************************************\n        public static Bitmap getBitmapFromUrl(string url ) {\n            bool   isCaptured = false;\n            Bitmap bitmap = null;\n\n            \/\/------------------------------------------------\n            \/\/ Web\u30b5\u30a4\u30c8\u60c5\u5831\u53d6\u5f97\u7528\u306e\u30d6\u30e9\u30a6\u30b6\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3092\u4f5c\u6210\n            \/\/------------------------------------------------\n            \n            WebBrowser browser = new WebBrowser();\n            browser.ScrollBarsEnabled      = false;\n            browser.ScriptErrorsSuppressed = true;\n\n            \/\/---------------------------------------------\n            \/\/ \u6307\u5b9aURL\u3078Navigate()\u5b8c\u4e86\u6642\u306e\u30cf\u30f3\u30c9\u30e9\u3092\u767b\u9332\n            \/\/---------------------------------------------\n            browser.DocumentCompleted += (sender, e) => {\n                if ( e.Url.Equals( \"about:blank\" ) ) {\n                    return;\n                }\n\n                try {\n                    \/\/ \u30ad\u30e3\u30d7\u30c1\u30e3\u30b5\u30a4\u30ba\u3092\u6307\u5b9a\n                    browser.Width  = browser.Document.Body.ScrollRectangle.Width;\n                    browser.Height = browser.Document.Body.ScrollRectangle.Height;\n\n                    \/\/ \u30ad\u30e3\u30d7\u30c1\u30e3\u306e\u4fdd\u5b58\u5148bitmap\u3092\u751f\u6210\n                    bitmap = new Bitmap( browser.Width, browser.Height );\n                    \n                    \/\/ \u751f\u6210\u3057\u305fbitmap\u306bWeb\u30da\u30fc\u30b8\u306e\u753b\u50cf\u3092\u4fdd\u5b58\n                    Graphics graphic = null;\n                    IntPtr   ptrObj  = IntPtr.Zero;\n                    IntPtr   ptrHdc  = IntPtr.Zero;\n                    try {\n                        graphic = Graphics.FromImage( bitmap );\n                        ptrHdc  = graphic.GetHdc();\n                        ptrObj  = Marshal.GetIUnknownForObject( browser.ActiveXInstance );\n                        Rectangle rect = new Rectangle(0, 0, browser.Width, browser.Height );\n\n                        \/\/ ptrObj\u753b\u50cf\u5185\u306erect\u3067\u6307\u5b9a\u3057\u305f\u9818\u57df\u3092,HDC\u306e\u30a8\u30ea\u30a2\u306b\u8cbc\u4ed8\n                        OleDraw( ptrObj, (int)DVASPECT.DVASPECT_CONTENT, ptrHdc, ref rect );\n                    } finally {\n                        if ( ptrObj != IntPtr.Zero ) {\n                            Marshal.Release( ptrObj );\n                        }\n                        if ( ptrHdc != IntPtr.Zero ) {\n                            graphic.ReleaseHdc( ptrHdc );\n                        }\n                        if ( graphic != null ) {\n                            graphic.Dispose();\n                        }\n                    }\n                } finally {\n                    isCaptured = true;\n                }\n            };\n    \n            \/\/------------------------------------------------\n            \/\/ \u6307\u5b9a\u3055\u308c\u305f\u30da\u30fc\u30b8\u3078\u9077\u79fb       \n            \/\/------------------------------------------------\n            browser.Navigate( url );\n            while( !isCaptured ) {\n                \/\/ \u6307\u5b9aURL\u306e\u30ed\u30fc\u30c9&\u30ad\u30e3\u30d7\u30c1\u30e3\u304c\u5b8c\u4e86\u3059\u308b\u306e\u3092\u5f85\u3064\n                Application.DoEvents();\n                System.Threading.Thread.Sleep( 20 );\n            }\n\n            \/\/ \u53d6\u5f97\u3057\u305fbmp\u60c5\u5831\u3092\u8fd4\u3059\n            return bitmap;\n        }\n    }\n}\n<\/pre>\n<br \/>\n\u901a\u5e38\u3001WinForm\u3067\u6307\u5b9a\u3057\u305f\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u306e\u753b\u50cf\u304c\u6b32\u3057\u3044\u5834\u5408\u306f\u3001Control.DrawToBitmap()\u3067\u53d6\u5f97\u53ef\u80fd\u306a\u306e\u3067\u3059\u304c\u3001WebBrowser\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u306f\u3001\u30da\u30fc\u30b8\u306b\u3088\u3063\u3066\u306f\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3067\u753b\u50cf\u304c\u53d6\u308c\u306a\u3044\u5834\u5408\u304c\u3042\u308b\u70ba\u3001Win32API\u306eOleDraw()\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n<br \/>\n<br \/>\n<br \/>\n\u307e\u305f\u3001\u547c\u3073\u5143\u5074\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u3059\u3002<br \/>\n\u30b7\u30f3\u30d7\u30eb\u306b\u30011\u884c\u3067bitmap\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<br \/>\n<pre lang=\"csharp\">\nBitmap bitmap = SiteCaptureSharp.CaptureManager.getBitmapFromUrl( \"http:\/\/www.yahoo.co.jp\/\" );\nif ( bitmap != null ) {\n    bitmap.Save( \"c:\\\\test.bmp\" );\n}\n<\/pre>\n<br \/>\n<br \/>\n<br \/>\nDLL\u7248\u3082\u4f5c\u3063\u305f\u306e\u3067\u3001DLL\u3060\u3051\u6b32\u3057\u3044\u5834\u5408\u306f<a href=\"http:\/\/nanoappli.com\/blog\/archives\/2469\">\u3053\u3061\u3089\u306e\u30da\u30fc\u30b8<\/a>\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\nCaptureManager\u306f\u3001\u524d\u8ff0\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u3072\u3068\u3064\u3060\u3051\u5b58\u5728\u3059\u308b\u3001\u30b7\u30f3\u30d7\u30eb\u306a\u30af\u30e9\u30b9\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WebBrowser\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3092\u4f7f\u7528\u3057\u3066\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089\u6307\u5b9a\u3057\u305f\u30b5\u30a4\u30c8\u5168\u4f53\u306e\u753b\u50cf\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002 \u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306f\u3001\u4ee5\u4e0b\u306e\u901a\u308a\u3002 using System; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; using System.Runtime.InteropServices.ComTypes; namespace SiteCaptureSharp { \/\/*******************************************************\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[5],"tags":[81],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":2469,"url":"http:\/\/nanoappli.com\/blog\/archives\/2469","url_meta":{"origin":2490,"position":0},"title":"\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u304b\u3089,\u6307\u5b9a\u3057\u305fURL\u306e\u30da\u30fc\u30b8\u5168\u4f53\u306e\u753b\u50cf\u3092\u4fdd\u5b58\u3059\u308b","date":"2012\u5e745\u670815\u65e5","format":false,"excerpt":"\u7279\u5b9a\u306eWeb\u30b5\u30a4\u30c8\u306e\u5185\u5bb9\u5168\u4f53\u3092\u3001\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u304b\u3089jpg\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u53d6\u5f97\u3057\u305f\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001 \u3084\u308a\u2026","rel":"","context":"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/05\/20120515_02-303x500.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2189,"url":"http:\/\/nanoappli.com\/blog\/archives\/2189","url_meta":{"origin":2490,"position":1},"title":"[C#]WebBrowser\u3067,\u6307\u5b9a\u3055\u308c\u305falt\u5c5e\u6027\u3092\u6301\u3064\u30bf\u30b0\u3092\u81ea\u52d5\u30af\u30ea\u30c3\u30af\u3059\u308b","date":"2012\u5e744\u670816\u65e5","format":false,"excerpt":"WebBrowser\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3092\u4f7f\u7528\u3057\u3066\u7279\u5b9a\u306e\u30da\u30fc\u30b8\u3092\u8868\u793a\u3057\u305f\u5f8c\u306b\u3001\u7279\u5b9a\u306e\u753b\u50cf\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u4e8b\u306b\u3059\u2026","rel":"","context":"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/04\/20120416_02-290x290.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2259,"url":"http:\/\/nanoappli.com\/blog\/archives\/2259","url_meta":{"origin":2490,"position":2},"title":"[C#]\u6307\u5b9a\u3055\u308c\u305fURL\u306e\u753b\u50cf\u3092Image\u578b\u3068\u3057\u3066\u53d6\u5f97\u3059\u308b","date":"2012\u5e744\u670828\u65e5","format":false,"excerpt":".NetFramework\u306b\u7528\u610f\u3055\u308c\u3066\u3044\u308bSystem.Drawing.Image\u30af\u30e9\u30b9\u306f\u3001From\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2476,"url":"http:\/\/nanoappli.com\/blog\/archives\/2476","url_meta":{"origin":2490,"position":3},"title":"[C#]WebBrowser\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u4f7f\u7528\u6642\u3001&#8221;Web\u30da\u30fc\u30b8\u3078\u306e\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\u306f\u53d6\u308a\u6d88\u3055\u308c\u307e\u3057\u305f&#8221;\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u6642\u306f?","date":"2012\u5e745\u670815\u65e5","format":false,"excerpt":"WebBrowser\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3092\u4f7f\u7528\u3057\u3066Navigate()\u3067\u30b5\u30a4\u30c8\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u6642\u3001 \"Web\u30da\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5776,"url":"http:\/\/nanoappli.com\/blog\/archives\/5776","url_meta":{"origin":2490,"position":4},"title":"[C#]ManicTime\u98a8\u306a,\u4f7f\u7528\u30a2\u30d7\u30ea\u8a18\u9332\u30bd\u30d5\u30c8\u3092\u81ea\u4f5c\u3059\u308b","date":"2012\u5e7411\u670817\u65e5","format":false,"excerpt":"Windows\u3067ManicTime\u3068\u3044\u3046\u30bd\u30d5\u30c8\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001PC\u3067\u4f7f\u7528\u3057\u3066\u3044\u305f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30ed\u30b0\u2026","rel":"","context":"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/11\/20121117_02.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":7847,"url":"http:\/\/nanoappli.com\/blog\/archives\/7847","url_meta":{"origin":2490,"position":5},"title":"[WordPress]All in one SEO pack\u3067\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30c9\u304b\u3089Twitter\u30ab\u30fc\u30c9\u753b\u50cf\u3092\u30bb\u30c3\u30c8\u3059\u308b\u65b9\u6cd5","date":"2017\u5e741\u67083\u65e5","format":false,"excerpt":"WordPress\u3067SEO\u5bfe\u7b56\u3084\u3001Facebook\/Twitter\u306a\u3069\u306e\u30bd\u30fc\u30b7\u30e3\u30eb\u30b5\u30a4\u30c8\u5411\u3051\u306e\u30bf\u30b0\u3092\u2026","rel":"","context":"","img":{"alt_text":"170102_2_2","src":"https:\/\/i0.wp.com\/nanoappli.com\/blog\/wp-content\/uploads\/2017\/01\/170102_2_2-500x449.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts\/2490"}],"collection":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/comments?post=2490"}],"version-history":[{"count":4,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts\/2490\/revisions"}],"predecessor-version":[{"id":2494,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts\/2490\/revisions\/2494"}],"wp:attachment":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/media?parent=2490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/categories?post=2490"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/tags?post=2490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}