Mike Ormond's Blog

Musings on mobile development and Windows Phone 7 in particular.

More on the mouse wheel

More on the mouse wheel

  • Comments 4

Daniel left a comment on my post about mouse wheel support saying he'd managed to get it working in managed code so I decided to take another look. It turns out that the object to which you attach your handler is critical and differs between IE and Firefox:

HtmlPage.Document.AttachEvent("onmousewheel", 
    new EventHandler<HtmlEventArgs>(this.MouseScrollWheel)); // IE
HtmlPage.Window.AttachEvent("DOMMouseScroll", 
    new EventHandler<HtmlEventArgs>(this.MouseScrollWheel)); //FF

So you need to attach to the onmousewheel event on the Document object for IE and the DOMMouseScroll event on the Window object for FireFox (I haven't tried Safari I'm afraid). That said, this didn't get me very much further as I can't recover the scroll wheel data for Firefox. My MouseScrollWheel handler looks like this:

private void MouseScrollWheel(object sender, HtmlEventArgs e)
{
    ScriptObject eventobject = e.EventObject;

    double wheelAmount =
        eventobject.GetProperty("detail") != null ?
        (double)eventobject.GetProperty("detail") * -1.0 :
        (double)eventobject.GetProperty("wheelDelta") / 40.0;

    if (wheelAmount > 0)
        Zoom(1.1);
    else
        Zoom(0.9);

    e.PreventDefault();
}

as IE uses the events wheelDelta property and Firefox uses the detail property (there is also a difference in scaling between the two hence the twiddle factors). There's a good tutorial on the scroll wheel here. The trouble is, the detail property is always 0.0 for me so this solution works in IE but not in Firefox (well it works in Firefox but the image zooms out irrespective of which way you turn the scroll wheel!). Ideas anyone?

Technorati Tags: ,,
  • Hi Mike,

    Further to my earlier email, it seems that Joe's post doesn't have the DeepZoom stuff, in it, but MIke's does: http://blogs.msdn.com/mharsh/archive/2008/03/05/slides-and-demos-from-my-mix-08-talk.aspx

    As I recall, the scroll helper in Mike's demo zoomz on the mouse position instead of the top left like yours does :).

  • Hi Derek. Thanks - I did see Mike's post but it was taking an age to download so I gave up :-). Will try again some other time. I didn't want to zoom on the mouse position - I wanted to zoom on the current centrepoint but that's not quite working as you point out. There's something wrong with my viewport origin calculations. I'll look at it again when I have a chance... Mike

  • Misc Funny Little Logic Errors More on the mouse wheel Powershell 2008 Scripting Games - My solutions

  • Jeff Paries with OOJS part 2, Chrishayuk with a fix to a listbox stretch problem, Karen Corby gives up

Page 1 of 1 (4 items)