{"id":1779,"date":"2015-06-09T05:23:57","date_gmt":"2015-06-09T05:23:57","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=1779"},"modified":"2015-08-01T18:47:24","modified_gmt":"2015-08-01T18:47:24","slug":"how-to-hide-the-cursor-in-awesomium","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/stack-overflow\/how-to-hide-the-cursor-in-awesomium\/","title":{"rendered":"How to hide the cursor in Awesomium"},"content":{"rendered":"<p><a href=\"http:\/\/stackoverflow.com\/users\/534755\/nikola\"><img loading=\"lazy\" decoding=\"async\" title=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" src=\"http:\/\/stackoverflow.com\/users\/flair\/534755.png\" rel=\"lightbox[1779]\" alt=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" width=\"208\" height=\"58\" \/><\/a><br \/>\nI&#8217;m a big fan of <a href=\"http:\/\/stackoverflow.com\/\">Stack Overflow<\/a> and I tend to contribute regularly (am currently in the <a href=\"http:\/\/stackexchange.com\/leagues\/1\/alltime\/stackoverflow\/2008-07-31\/534755?sort=reputationchange#534755\">top 0.X%<\/a>).\u00a0In this category (<a href=\"http:\/\/www.nikola-breznjak.com\/blog\/category\/stack-overflow\/\">stackoverflow<\/a>)\u00a0of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread <a href=\"http:\/\/meta.stackoverflow.com\/questions\/266971\/can-i-post-so-questions-and-answers-in-a-personal-blog\/266973\">here<\/a>.<\/p>\n<p>My <a href=\"http:\/\/stackoverflow.com\/questions\/25014442\/how-to-hide-the-cursor-in-awesomium\">question<\/a> was:<\/p>\n<p>How to hide the cursor in Awesomium &#8211; I tried this:<\/p>\n<pre class=\"lang:default decode:true\">&lt;awe:WebControl x:Name=\"webBrowser\" Cursor=\"None\" Source=\"http:\/\/example.com\/\"\/&gt;<\/pre>\n<p>but the cursor still shows.<\/p>\n<p>I figured that I could alter the CSS of the page by adding the following line:<\/p>\n<pre class=\"lang:default decode:true\">*{\r\n    cursor: none;\r\n}<\/pre>\n<p>But, is there a solution for when I don&#8217;t have the access to the actual page that I&#8217;m showing?<\/p>\n<p>The answer, by user <a href=\"http:\/\/stackoverflow.com\/users\/3737186\/sjoerd2228888\">Sjoerd2228888<\/a>, was:<\/p>\n<blockquote><p>You can use a ResouceInterceptor and manipulate the page on the fly to insert custom CSS.<\/p>\n<p>EDIT:<\/p>\n<p>The following implementation should do the job. (It assumes there is a text.css file)<\/p>\n<pre class=\"font-size:9 line-height:10 lang:default decode:true \">class ManipulatingResourceInterceptor : IResourceInterceptor\r\n{\r\n    public ResourceResponse OnRequest(ResourceRequest request)\r\n    {\r\n        Stream stream = null;\r\n\r\n        \/\/do stream manipulation\r\n        if (request.Url.ToString() == \"http:\/\/your.web.url\/test.css\")\r\n        {\r\n            WebRequest myRequest;\r\n            myRequest = WebRequest.Create(request.Url);\r\n            Stream webStream = myRequest.GetResponse().GetResponseStream();\r\n            StreamReader webStreamReader = new StreamReader(webStream);\r\n            string webStreamContent = webStreamReader.ReadToEnd();\r\n\r\n            stream = webStream;\r\n\r\n            string extraContent = \"*{cursor: none;}\";\r\n\r\n            webStreamContent += extraContent;\r\n            byte[] responseBuffer = Encoding.UTF8.GetBytes(webStreamContent);\r\n\r\n            \/\/ Initialize unmanaged memory to hold the array.\r\n            int responseSize = Marshal.SizeOf(responseBuffer[0]) * responseBuffer.Length;\r\n            IntPtr pointer = Marshal.AllocHGlobal(responseSize);\r\n            try\r\n            {\r\n                \/\/ Copy the array to unmanaged memory.\r\n                Marshal.Copy(responseBuffer, 0, pointer, responseBuffer.Length);\r\n                return ResourceResponse.Create((uint)responseBuffer.Length, pointer, \"text\/css\");\r\n            }\r\n            finally\r\n            {\r\n                \/\/ Data is not owned by the ResourceResponse. A copy is made \r\n                \/\/ of the supplied buffer. We can safely free the unmanaged memory.\r\n                Marshal.FreeHGlobal(pointer);\r\n                stream.Close();\r\n            }\r\n        }\r\n        return null;\r\n    }\r\n\r\n    public bool OnFilterNavigation(NavigationRequest request)\r\n    {\r\n        return false;\r\n    }\r\n}<\/pre>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%).\u00a0In this category (stackoverflow)\u00a0of posts I will will be posting&hellip;<\/p>\n","protected":false},"author":1,"featured_media":609,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-1779","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stack-overflow"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1779","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=1779"}],"version-history":[{"count":3,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1779\/revisions"}],"predecessor-version":[{"id":1782,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1779\/revisions\/1782"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/609"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=1779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=1779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=1779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}