⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clipspydlg.cpp

📁 visual c++ 实例编程
💻 CPP
字号:
// ClipSpyDlg.cpp : implementation file
//

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

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

/////////////////////////////////////////////////////////////////////////////
// CClipSpyDlg dialog

CClipSpyDlg::CClipSpyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CClipSpyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CClipSpyDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	
	//TODO: 变量初始化
	m_hWndNextCBViewer=NULL;
}

void CClipSpyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CClipSpyDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CClipSpyDlg, CDialog)
	//{{AFX_MSG_MAP(CClipSpyDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_DRAWCLIPBOARD()
	ON_WM_DESTROY()
	ON_WM_CHANGECBCHAIN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CClipSpyDlg message handlers

BOOL CClipSpyDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	//TODO: 将对话框加入剪贴板监视窗口链中
	m_hWndNextCBViewer=SetClipboardViewer();
	SetWindowPos( &wndTopMost, 0, 0, 0, 0, SWP_NOREPOSITION | SWP_NOSIZE );
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CClipSpyDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CClipSpyDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CClipSpyDlg::OnDestroy() 
{
	//TODO: 从监视链中删除本监视窗口
	ChangeClipboardChain( m_hWndNextCBViewer );

	CDialog::OnDestroy();
}

void CClipSpyDlg::OnDrawClipboard() 
{
	//TODO: 剪贴板内容发生变化
	CString sText("ClipSpy-");
	UINT CBFormat[]={
		CF_BITMAP,
		CF_DIB,
		CF_DIF,
		CF_DSPBITMAP,
		CF_DSPENHMETAFILE,
		CF_DSPMETAFILEPICT,
		CF_DSPTEXT,
		CF_ENHMETAFILE,
		CF_HDROP,
		CF_LOCALE,
		CF_METAFILEPICT,
		CF_OEMTEXT,
		CF_OWNERDISPLAY,
		CF_PALETTE,
		CF_PENDATA,
		CF_RIFF,
		CF_SYLK,
		CF_TEXT,
		CF_WAVE,
		CF_TIFF
	};
	char *FormatName[]={
		"CF_BITMAP",
		"CF_DIB",
		"CF_DIF",
		"CF_DSPBITMAP",
		"CF_DSPENHMETAFILE",
		"CF_DSPMETAFILEPICT",
		"CF_DSPTEXT",
		"CF_ENHMETAFILE",
		"CF_HDROP",
		"CF_LOCALE",
		"CF_METAFILEPICT",
		"CF_OEMTEXT",
		"CF_OWNERDISPLAY",
		"CF_PALETTE",
		"CF_PENDATA",
		"CF_RIFF",
		"CF_SYLK",
		"CF_TEXT",
		"CF_WAVE",
		"CF_TIFF",
		"未知格式或剪贴板中无数据"
	};

	//打开剪贴板查询格式类型
	if( OpenClipboard() )
	{
		CString sCBAvailableFormat("");
		int nFormatNum=sizeof(CBFormat)/sizeof(UINT);
		
		//枚举类型
		for(int i=0;i<nFormatNum;i++)
		{
			if( ::IsClipboardFormatAvailable( CBFormat[i] ) )
			{
				if( sCBAvailableFormat.IsEmpty() )
					sCBAvailableFormat+=FormatName[i];
				else
					sCBAvailableFormat=sCBAvailableFormat+" & "+FormatName[i];
			}
		}
		
		if( !sCBAvailableFormat.IsEmpty() )
			sText+=sCBAvailableFormat;//列出有效格式
		else
			sText+=FormatName[i];//该格式未知

		::CloseClipboard();
	}
	
	//在标题栏中显示格式
	SetWindowText( sText );

	//传WM_DRAWCLIPBOARD给下一个监视窗口
	::SendMessage(m_hWndNextCBViewer,WM_DRAWCLIPBOARD,0,0);
}

void CClipSpyDlg::OnChangeCbChain(HWND hWndRemove, HWND hWndAfter) 
{
	// TODO: 监视链中窗口发生变动
	if( m_hWndNextCBViewer==hWndRemove )
		m_hWndNextCBViewer=hWndAfter;
	
	//传WM_CHANGECBCHAIN给下一个监视窗口	
	::SendMessage(m_hWndNextCBViewer,WM_CHANGECBCHAIN,
			(WPARAM)hWndRemove,(LPARAM)hWndAfter);
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -