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

ClipSpy

Rate me:
Please Sign up or sign in to vote.
4.88/5 (55 votes)
27 Oct 2001 464.2K   7.9K   138  
A tool for viewing clipboard and drag-and-drop data
//////////////////////////////////////////////////////////////////////////
//
// ClipSpy, Copyright 1999-2001  by Michael Dunn <mdunn at inreach dot com>
//
// This is a utility to view the raw contents of the clipboard, or the 
// data in a drag-and-drop operation.  There are still some quirks and
// bugs.  Comments/suggestions are always welcome!
//
// Revision history:
//  Dec 20, 1999: Version 1.0, first release.
//
//  Sep 27, 2001: Version 1.2, added ability to save any block of data;
//      added IDropTargetHelper support to CLeftView.
//
// You can get the latest updates for ClipSpy at:
//  http://www.codeproject.com/clipboard/clipspy.asp
//
//////////////////////////////////////////////////////////////////////////

// ClipSpy.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "ClipSpy.h"

#include "MainFrm.h"
#include "ClipSpyDoc.h"
#include "LeftView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CClipSpyApp

BEGIN_MESSAGE_MAP(CClipSpyApp, CWinApp)
	//{{AFX_MSG_MAP(CClipSpyApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CClipSpyApp construction

CClipSpyApp::CClipSpyApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CClipSpyApp object

CClipSpyApp theApp;

// This array holds descriptive strings for the built-in clipboard types.
CClipFormatData g_aClipData[] = {
    { CF_TEXT,            _T("CF_TEXT") },
    { CF_BITMAP,          _T("CF_BITMAP") },
    { CF_METAFILEPICT,    _T("CF_METAFILEPICT") },
    { CF_SYLK,            _T("CF_SYLK") },
    { CF_DIF,             _T("CF_DIF") },
    { CF_TIFF,            _T("CF_TIFF") },
    { CF_OEMTEXT,         _T("CF_OEMTEXT") },
    { CF_DIB,             _T("CF_DIB") },
    { CF_PALETTE,         _T("CF_PALETTE") },
    { CF_PENDATA,         _T("CF_PENDATA") },
    { CF_RIFF,            _T("CF_RIFF") },
    { CF_WAVE,            _T("CF_WAVE") },
    { CF_UNICODETEXT,     _T("CF_UNICODETEXT") },
    { CF_ENHMETAFILE,     _T("CF_ENHMETAFILE") },
    { CF_HDROP,           _T("CF_HDROP") },
    { CF_LOCALE,          _T("CF_LOCALE") },
    { CF_DIBV5,           _T("CF_DIBV5") },
    { CF_OWNERDISPLAY,    _T("CF_OWNERDISPLAY") },
    { CF_DSPTEXT,         _T("CF_DSPTEXT") },
    { CF_DSPBITMAP,       _T("CF_DSPBITMAP") },
    { CF_DSPMETAFILEPICT, _T("CF_DSPMETAFILEPICT") },
    { CF_DSPENHMETAFILE,  _T("CF_DSPENHMETAFILE") },
    { 0, _T("") } 
    };


/////////////////////////////////////////////////////////////////////////////
// CClipSpyApp initialization

BOOL CClipSpyApp::InitInstance()
{
	// Initialize OLE libraries
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_OLE_INIT_FAILED);
		return FALSE;
	}

	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

	// Change the registry key under which our settings are stored.
	SetRegistryKey(_T("Mike's Classy Software"));

	LoadStdProfileSettings(0);  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CClipSpyDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CLeftView));
	pDocTemplate->SetContainerInfo(IDR_CNTR_INPLACE);
	AddDocTemplate(pDocTemplate);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The one and only window has been initialized, so show and update it.
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();

	return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
		// No message handlers
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CClipSpyApp message handlers

// App command to run the dialog
void CClipSpyApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

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.


Written By
Software Developer (Senior) VMware
United States United States
Michael lives in sunny Mountain View, California. He started programming with an Apple //e in 4th grade, graduated from UCLA with a math degree in 1994, and immediately landed a job as a QA engineer at Symantec, working on the Norton AntiVirus team. He pretty much taught himself Windows and MFC programming, and in 1999 he designed and coded a new interface for Norton AntiVirus 2000.
Mike has been a a developer at Napster and at his own lil' startup, Zabersoft, a development company he co-founded with offices in Los Angeles and Odense, Denmark. Mike is now a senior engineer at VMware.

He also enjoys his hobbies of playing pinball, bike riding, photography, and Domion on Friday nights (current favorite combo: Village + double Pirate Ship). He would get his own snooker table too if they weren't so darn big! He is also sad that he's forgotten the languages he's studied: French, Mandarin Chinese, and Japanese.

Mike was a VC MVP from 2005 to 2009.

Comments and Discussions