Jaime Rodriguez On Windows Phone, Windows Presentation Foundation, Silverlight and Windows 7
HTML is quite easy for people to get started with, pretty broadly known, light weight, rich enough (if you work hard at it or have nice graphics), etc.. so there is a good set of reasons why the sidebar folks chose HTML as the presentation technology [ I am guessign here]
However, there are some things that are a little harder to do with HTML [at least they are for me] ... for example, charting (pie charts) ...I tried using VML for this, and had issues.. (it was a little unstable on how it rendered, some times it would stop rendering, I could not figure why)... so for these very extreme scenarios, I am thinking ActiveX might be OK... Note that by no means I am advocating activex as the best choice for gadgets, imho the activex registration (regsvr32) breaks the easy, per-user, non-impactful deployment model for gadgets... but I am thinking that there are enterprises (say internal, lob gadgets) that can get away with an impactful deployment model (via MSI or SMS) and benefit from the rich visualization of an activex -say for some BI KPIs...
Here is what I created code to do:
For reference, here are some good articles in creating .NET Activex controls for IE... I used a little bit from all of these..
http://msdn.microsoft.com/msdnmag/issues/02/01/UserCtrl/
http://www.codeproject.com/cs/miscctrl/exposingdotnetcontrols.asp
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/om/event_model.asp
http://www.cisco-cert.com/dotnet_general/574541-How-to-fire-Javascript-events-from-a--NET-winforms-user-control-back-to-Javascript-in-IE
Come on dude, get to it... show us the code!.. OK .. here you go ... All of the code is commented, please go through it in the project... here I am showing only the 4 tasks above.. |f you are to reuse this, you will have to replace all the lines that have a TODO with your own guids or your own names code
// Outgoing interface, wired via ComSourceInterfaces on my main class -- see step 3
In my class, I had to expose the events ( showing only RightClick here... the rest you can see in the code)
// Right Mouse Click will be passed to the gadget... I was hoping I could popup the context menu.. protected override void OnMouseClick(MouseEventArgs e){base.OnMouseClick(e);if (e.Button == MouseButtons.Right){// Did any one subscribe ??? if (RightClickRelay != null){ new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert(); // fire the event .. RightClickRelay(e.X, e.Y);CodeAccessPermission.RevertAssert();} } }
2 -- Exposing an interface for gadget to call my Activex ..
to wire the interface, simply implement it in my class ... (see step3 )
3.- Creating the activex .. it is simply a .NET Class Library with a UserControl and some attributes:
// TODO: Replace GUID [Guid("A4B9C3C2-8DAC-451a-AEC1-DE3B042FB311")]// TODO: Replace Prog Id [ProgId("WindowsFormsUserControl.UserControl")]//Wire up my eventing interface ..(ComSource)... [ClassInterface(ClassInterfaceType.None), ComSourceInterfaces(typeof(IGadgetControlEvents))][ComVisible(true)]public partial class UserControl1 : UserControl, IGadgetIncoming
5.- Using the object from my gadget
<!-- using the object tag to call my ActiveX -->
<object id="sample" classid="clsid:A4B9C3C2-8DAC-451a-AEC1-DE3B042FB311"height="126" width="126" style="background-color:Transparent;" onclick="alert('clicked');" > </object><script>
<!-- one of several ways to sync event; another way is using the FOR statement --> function
---
So, the control is pretty trivial... download the sample code, replace the TODOs ( use GuidGen to generate your guids) and you will reuse it ... There were however a couple of note worthy issues I have not figured out .. [will get to these as soon as I have time ]
None of these are blockers, in fact some of the MS gadgets themselves (notes) have these issues but I would like to solve them for a different post ...
You can download the code for this project here... There are two directories in the download, the sample.gadget and the ActiveX code itself..
For dev/test deployment, the project in Visual Studio is using the "Register for COM Interop" checkbox in the Build section of the Project properties to do the registration ... if you are not rebuilding it, or installing it in a box where you are not building it, you will have to register it manually from a .NET Command prompt (or a command prompt with regasm in the path).. regasm /register /codebase WindowsFormsuserControl.dll
This leaves the whole topic of how to deploy at run-time... are you going to need admin, etc.. I will have to get back to these questions in a future (but will try to not make it to far into the future) post.. .
Cheers,
In my earlier post , I talked about WPF in the Sidebar by using the IFRAME to host XBAPs. In this post,
Karsten Januszewski vient de poster, sur son blog, la 2ème partie de son article consacrée à la réalisation...
to override the default gadget context menu, add an 'oncontextmenu' handler to your HTML element, and inside that handler, (in addition to showing your custom context menu), set 'window.event.returnValue' to 'false' so the default context menu doesn't show up.