Click here to Skip to main content
15,894,460 members
Articles / Programming Languages / C++

Middle Mouse Button (or Wheel) to Doubleclick (VC6)

Rate me:
Please Sign up or sign in to vote.
4.67/5 (17 votes)
26 Jul 2010CPOL2 min read 84.1K   2K   34  
This is a small but handy tool I'm using every day. It converts a middle mouse button click in to a left mouse button double click.
/////////////////////////////////////////////////////
// CSimpleTray - Simple tray icon implementation
//
// Copyright (c) 2003 - 3827 T1TAN 
// Copyright (c) 2003 - 3827 SprdSoft Inc.
//
// This source code is FREE.
//

#include "stdafx.h"
#include "SimpleTray.h"


// constructor
CSimpleTray::CSimpleTray() {
	// initialize 
	m_hIcon = NULL;
	m_strTooltip = "";
	m_bEnabled = FALSE;
}

// destructor
CSimpleTray::~CSimpleTray() {
	Hide(); // a good thing to do :-)
}

// shows the tray icon
void CSimpleTray::Show() {
	// check to see if we have a valid icon
	if ( m_hIcon == NULL )
		return;

	// make sure we are not already visible
	if ( m_bEnabled == TRUE )
		return;

	// initialize the TRAYNOTIFYDATA struct
	m_nid.cbSize	= sizeof(m_nid);

	m_nid.hWnd		= AfxGetMainWnd()->m_hWnd;	// the 'owner' window
												// this is the window that
												// receives notifications
	m_nid.uID		= 1;	// ID of our icon, as you can have
							// more than one icon in a single app

	m_nid.uCallbackMessage = WM_TRAYNOTIFY;	// our callback message
	strcpy(m_nid.szTip, m_strTooltip);	// set the tooltip
	m_nid.hIcon = m_hIcon;	// icon to show

	m_nid.uFlags =	NIF_MESSAGE |	// flags are set to indicate what
					NIF_ICON |		// needs to be updated, in this case
					NIF_TIP;		// callback message, icon, and tooltip
	
	int nRet = Shell_NotifyIcon( NIM_ADD, &m_nid );	// finally add the icon

	m_bEnabled = TRUE;	// set our indicator so that we
						// know the current status
}


// hides the tray icon
void CSimpleTray::Hide() {
	// make sure we are enabled
	if ( m_bEnabled == TRUE ) {
		// we are, so remove
		m_nid.uFlags = 0;
		Shell_NotifyIcon( NIM_DELETE, &m_nid );
		// and again, we need to know what's going on
		m_bEnabled = FALSE;
	}
}

// updates tray with a new icon
void CSimpleTray::SetIcon(HICON hIcon) {
	// first make sure we got a valid icon
	if ( hIcon == NULL )
		return;

	// set it as our private
	m_hIcon = hIcon;

	// now check if we are already enabled
	if ( m_bEnabled == TRUE ) {	// we are, so update
		m_nid.hIcon = m_hIcon;
		m_nid.uFlags = NIF_ICON;	// only icon
		Shell_NotifyIcon( NIM_MODIFY, &m_nid );
	}
}

// updates tray with a new tooltip
void CSimpleTray::SetTooltip(LPCTSTR lpTooltip) {
	// tooltip can be empty, we don't care
	m_strTooltip = lpTooltip;

	// if we are enabled
	if ( m_bEnabled == TRUE ) {	// do an update
		strcpy(m_nid.szTip, m_strTooltip);
		m_nid.uFlags = NIF_TIP;	// tooltip only
		Shell_NotifyIcon( NIM_MODIFY, &m_nid );
	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Switzerland Switzerland
programmer and software junkie since 1991 zurich switzerland

Comments and Discussions