Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Mouse Gestures for Internet Explorer

, 21 Sep 2005
Adding mouse gesture recognition to Internet Explorer.
mousegestures_inst.zip
MouseGestures.exe
mousegestures_inst_1.zip
MouseGestures.exe
mousegestures_src.zip
src
gesture.weights
images
about.bmp
ClickLeftRight.bmp
ClickRightLeft.bmp
down.bmp
downarrow.bmp
downleft.bmp
downright.bmp
downup.bmp
exclamation.bmp
left.bmp
leftarrow.bmp
leftright.bmp
none.bmp
right.bmp
rightarrow.bmp
rightleft.bmp
up.bmp
uparrow.bmp
updown.bmp
upleft.bmp
upright.bmp
wheel.bmp
MouseGestures.rgs
mousegestures_src_1.zip
MouseGestures
BrowserHelperObject.rgs
gesture.weights
images
about.bmp
ClickLeftRight.bmp
ClickRightLeft.bmp
down.bmp
downleft.bmp
downright.bmp
downup.bmp
left.bmp
none.bmp
right.bmp
up.bmp
updown.bmp
upleft.bmp
upright.bmp
wheel.bmp
MouseGestures.def
MouseGestures.dsp
MouseGesturesCfg.rgs
///////////////////////////////////////////////////////////////
//
// ExplorerListDlg.cpp
//
// Created: 17/07/2003
// Copyright (c) 2003 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 "ExplorerListDlg.h"
#include "WindowHelper.h"
#include "OSUtils.h"
#include <algorithm>

namespace
{
    LPCTSTR CLASS_IE_FRAME = _T( "IEFrame" );

    BOOL __stdcall EnumWindowsProc( HWND hWnd, LPARAM lParam )
    {
        if( lParam == NULL )
        {
            return FALSE;
        }

        if( WindowHelper::GetClassName( hWnd ) == CLASS_IE_FRAME )
        {
        #ifdef _DEBUG
            ATLASSERT( ::IsBadReadPtr( 
                                reinterpret_cast< void * >( lParam ), 
                                sizeof( WindowList ) 
                                ) == FALSE );
            ATLASSERT( ::IsBadWritePtr( 
                                reinterpret_cast< void * >( lParam ), 
                                sizeof( WindowList ) 
                                ) == FALSE );
        #endif

            reinterpret_cast< WindowList * >( lParam )->push_back( hWnd );
        }

        return TRUE;
    }

    class InsertWindows : public std::unary_function< HWND, void >
    {
    public:
        InsertWindows( const CListViewCtrl &listCtrl ) :
            m_listCtrl( listCtrl )
        {
        }

        void operator()( HWND hWnd )
        {
            int len = ::GetWindowTextLength( hWnd ) + 1;
            std::vector< TCHAR >    buffer( len );

            ::GetWindowText( hWnd, &buffer[ 0 ], len );

            int item = m_listCtrl.InsertItem( 999999, &buffer[ 0 ] );
            m_listCtrl.SetItemData( item, reinterpret_cast< DWORD_PTR >( hWnd ) );
        }

    private:
        CListViewCtrl   m_listCtrl;
    };
}

BOOL ExplorerListDlg::Invoke( HWND hWndParent )
{
//
// modeless dialog as we don't get mouse button up messages
// if the cursor goes out of the client area with a modal dialog
// (even with SetCapture) ????
//
    static ExplorerListDlg  instance;

    if( instance.Create( hWndParent, NULL ) == NULL )
    {
        return FALSE;
    }

    instance.ShowWindow( SW_SHOW );

    return TRUE;
}

HWND ExplorerListDlg::Create( HWND hWndParent, LPARAM dwInitParam )
{
    m_windowList.clear();

    ::EnumDesktopWindows( 
                    NULL, 
                    EnumWindowsProc, 
                    reinterpret_cast< LPARAM >( &m_windowList ) 
                    );

    if( m_windowList.size() < 2 )
    {
        return NULL;
    }

    HWND    hWnd = CDialogImpl< ExplorerListDlg >::Create( hWndParent, dwInitParam );
    if( ::IsWindow( hWnd ) == FALSE )
    {
        return hWnd;
    }

//
// bring the window to the top
//
    ::SetWindowPos( hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );

//
// TODO: add code to size window according to width of text
// GetFont()
// GetDC() etc.
//
    m_listCtrl = GetDlgItem( IDC_LIST_EXPLORERS );
    m_listCtrl.InsertColumn( 0, _T( "" ), LVCFMT_LEFT, 350, -1 );

    std::for_each(
                m_windowList.begin(),
                m_windowList.end(),
                InsertWindows( m_listCtrl )
                );

    HWND    hWndFrame = ::GetAncestor( GetParent(), GA_ROOT );
    int     selected  = 0;

    for( int idx = m_listCtrl.GetItemCount(); --idx != -1; )
    {
        if( reinterpret_cast< HWND >( m_listCtrl.GetItemData( idx ) ) == hWndFrame )
        {
            selected = idx;
            break;
        }
    }

    m_listCtrl.SelectItem( selected );

    CenterWindow();
    SetCapture();

    m_mouseTracker.Advise( m_listCtrl, this );

    return hWnd;
}

bool ExplorerListDlg::OnMouseWheel( HWND hWnd, WORD, WORD delta, const POINT &pt )
{
    int item = m_listCtrl.GetSelectedIndex();

    if( short( delta ) < 0 )
    {
        if( ++item == m_listCtrl.GetItemCount() )
        {
            item = 0;
        }
    }
    else
    {
        if( --item == -1 )
        {
            item += m_listCtrl.GetItemCount();
        }
    }

    m_listCtrl.SelectItem( item );

    return true;
}

LRESULT ExplorerListDlg::OnRightButtonUp( UINT, WPARAM, LPARAM, BOOL & )
{
    ShowWindow( SW_HIDE );

    int     item = m_listCtrl.GetSelectedIndex();
    HWND    hWnd = reinterpret_cast< HWND >( m_listCtrl.GetItemData( item ) );

    if( ::IsIconic( hWnd ) )
    {
        WINDOWPLACEMENT pl;
        pl.length = sizeof( WINDOWPLACEMENT );

        ::GetWindowPlacement( hWnd, &pl );
        if( ( pl.flags & WPF_RESTORETOMAXIMIZED ) == WPF_RESTORETOMAXIMIZED )
        {
            ::ShowWindow( hWnd, SW_MAXIMIZE );
        }
        else
        {
            ::ShowWindow( hWnd, SW_RESTORE );
        }
    }

    ::SetFocus( hWnd );
    ::SetForegroundWindow( hWnd );

    m_mouseTracker.Unadvise();
    DestroyWindow();

    return 0;
}

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

Share

About the Author

Ralph Hare
Web Developer
United Kingdom United Kingdom
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150327.1 | Last Updated 21 Sep 2005
Article Copyright 2003 by Ralph Hare
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid