Click here to Skip to main content
15,894,405 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.
///////////////////////////////////////////////////////////////
//
// MouseGestures.cpp
//
// Created: 01/04/2004
// Copyright (c) 2004 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.
//
///////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "resource.h"
#include "tstring.h"
#include "BrowserHelperObject.h"
#include "MouseGesturesCfg.h"

namespace
{
    LPCTSTR KEY_BHO         = _T( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects" );
    LPCTSTR KEY_EXTENSIONS  = _T( "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions" );
    LPCTSTR EXTENSION_CLSID = _T( "{4E660F19-E91E-41e1-88EF-D1DFAB118F67}" );

    tstring StringFromCLSID( const CLSID &clsid )
    {
        LPOLESTR    pclsid = NULL;

        if( FAILED( ::StringFromCLSID( clsid, &pclsid ) ) )
        {
            return _T( "" );
        }

        USES_CONVERSION;
        tstring     ret( OLE2T( pclsid ) );
        ::CoTaskMemFree( pclsid );

        return ret;
    }

    class RegKeyHelper : public CRegKey
    {
    public:
        HRESULT Open( HKEY hkeyParent, LPCTSTR keyName, bool forceOpen )
        {
            if( forceOpen )
            {
                return Create( hkeyParent, keyName );
            }

            return CRegKey::Open( hkeyParent, keyName );
        }
    };

    HRESULT Register( bool doRegister )
    {
        USES_CONVERSION;

        RegKeyHelper    bhoKey;
        if( bhoKey.Open( HKEY_LOCAL_MACHINE, KEY_BHO, doRegister ) == ERROR_SUCCESS )
        {
            tstring clsid = StringFromCLSID( __uuidof( BrowserHelperObject ) );

            if( doRegister )
            {
                CRegKey tmp;
                if( tmp.Create( bhoKey, clsid.c_str() ) == ERROR_SUCCESS )
                {
                    tmp.SetStringValue( _T( "" ), _T( "Mouse Gestures" ) );
                }
            }
            else
            {
                bhoKey.DeleteSubKey( clsid.c_str() );
            }
        }

        RegKeyHelper    extKey;
        if( extKey.Open( HKEY_LOCAL_MACHINE, KEY_EXTENSIONS, doRegister ) == ERROR_SUCCESS )
        {
            if( doRegister )
            {
                CRegKey tmp;
                if( tmp.Create( extKey, EXTENSION_CLSID ) == ERROR_SUCCESS )
                {
                    tmp.SetStringValue( _T( "" ), _T( "Mouse Gestures Menu" ) );
                    tmp.SetStringValue( _T( "MenuCustomize" ), _T( "Tools" ) );
                    tmp.SetStringValue( _T( "CLSID" ), _T( "{1FBA04EE-3024-11d2-8F1F-0000F87ABD16}" ) );
                    tmp.SetStringValue( _T( "MenuText" ), _T( "Mouse Gestures..." ) );
                    tmp.SetStringValue( _T( "MenuStatusBar" ), _T( "Configure Mouse Gestures" ) );
                    tmp.SetStringValue( 
                                _T( "ClsidExtension" ), 
                                StringFromCLSID( __uuidof( MouseGesturesCfg ) ).c_str()
                                );
                }
            }
            else
            {
                extKey.DeleteSubKey( EXTENSION_CLSID );
            }
        }

        return S_OK;
    }
}

[ module(dll, uuid = "{D06BA17F-E115-4D9D-993F-58023E9B3DC3}", 
		 name = "MouseGestures", 
		 helpstring = "Drowse: Mouse Gestures Type Library",
		 resource_name = "IDR_MOUSEGESTURES") ]
class CMouseGesturesModule
{
public:
    HRESULT RegisterAppId()
    {
        return Register( true );
    }

    HRESULT UnregisterAppId()
    {
        return Register( false );
    }

    BOOL WINAPI DllMain( DWORD dwReason, LPVOID )
    {
    //
    // conditionally load in explorer.exe
    //
        TCHAR   fileName[ MAX_PATH + 1 ] = { 0 };
        ::GetModuleFileName( NULL, fileName, MAX_PATH );
        ::PathStripPath( fileName );

        if( _tcsicmp( fileName, _T( "explorer.exe" ) ) == 0 )
        {
            return GestureManager::LoadInExplorer();
        }

        return TRUE;
    }
};
		 

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