Click here to Skip to main content
15,896,201 members
Articles / Web Development / HTML

Mouse Gestures for Internet Explorer

Rate me:
Please Sign up or sign in to vote.
4.84/5 (99 votes)
21 Sep 200514 min read 1.3M   13.4K   235  
Adding mouse gesture recognition to Internet Explorer.
///////////////////////////////////////////////////////////////
//
// TrailWindow.h
//
// Created: 28/06/2005
// Copyright (c) 2005 Ralph Hare (ralph.hare@ysgyfarnog.co.uk)
// All rights reserved.
//
// The code and information is provided "as-is" without
// warranty of any kind, either expressed or implied.
//
///////////////////////////////////////////////////////////////

#ifndef __TRAILWINDOW_H_4AC74882_21E3_469D_A937_32CAD7268D0C_
#define __TRAILWINDOW_H_4AC74882_21E3_469D_A937_32CAD7268D0C_

#include "MouseTrail.h"
#include "CriticalSection.h"
#include <atlmisc.h>

/**
 * @brief Concrete implementation of the MouseTrail interface
 *
 * The TrailWindow creates a transparent window that covers the whole
 * screen. When the user performs a mouse gesture, the gesture path
 * is fed to TrailWindow and drawn over the active window(s).
 *
 * The mouse trail is drawn to a memory DC before being blitted to
 * the windows DC.
 **/
class TrailWindow : 
    public CWindowImpl< TrailWindow >,
    public MouseTrail
{
public:
    TrailWindow( COLORREF clr, long thickness, BYTE transparency, long fadeSpeed );
    ~TrailWindow();

BEGIN_MSG_MAP( ToolTip )
    MESSAGE_HANDLER( WM_DISPLAYCHANGE, OnDisplayChange )
    MESSAGE_HANDLER( WM_TIMER, OnTimer )
END_MSG_MAP()

public:
    static CWndClassInfo & GetWndClassInfo();

    void UpdateSettings( COLORREF clr, long thickness, BYTE transparency, long fadeSpeed );

private:
    LRESULT OnDisplayChange( UINT, WPARAM, LPARAM, BOOL & );
    LRESULT OnTimer( UINT, WPARAM, LPARAM, BOOL & );
    
// MouseTrail
private:
    virtual void Begin( HWND hWnd );
    virtual void End();
    virtual void Update( const Path &path );
    virtual void Show();
    virtual void Hide();

private:
    void SetTransparency( BYTE transparency );
    void DrawTrail( HDC hDC );
    void UpdateBitmap();

private:
    WTL::CSize              m_offset;           /// < the co-ordinates of the top-left of the window
                                                ///   that the path is relative to
    WTL::CPoint             m_lastPoint;        /// < the last point on the path we drew
    std::vector< POINT >    m_path;             /// < the adjusted path

    WTL::CDC        m_memDC;                    /// < the memory DC
    WTL::CBitmap    m_bitmap;                   /// < a bitmap compatible with the current DC, large
                                                ///   enough to cover the entire screen
    WTL::CPen       m_pen;                      /// < the pen to draw the trail
    WTL::CPen       m_penEnd;                   /// < a pen for drawing the end marker
    WTL::CBrush     m_brush;                    /// < a brush to draw the beginning & end markers
    WTL::CRect      m_rcWnd;                    /// < the size of the TrailWindow
    WTL::CRect      m_rcExtents;                /// < the bounding rect for the path

    long    m_penWidth;
    BYTE    m_transparency;
    int     m_fadeIncrement;                    /// < the increment in transparency to be used
                                                ///   when fading the window. The bigger the number,
                                                ///   the faster the fade
    double  m_sensitivity;                      /// < the number of pixels the mouse has to move
                                                ///   before the path is updated

    CriticalSection     m_csShow;
};

#endif // __TRAILWINDOW_H_4AC74882_21E3_469D_A937_32CAD7268D0C_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions