您现在的位置: 主页 > 上位机技术 > delphi > 监视剪贴板中数据格式
本文所属标签:
为本文创立个标签吧:

监视剪贴板中数据格式

来源: 网络用户发布,如有版权联系网管删除 2020-04-04 

监视剪贴板中数据格式 监视剪贴板中数据格式,只要剪贴板中数据变化,就在标题栏上显示出所有可识别的数据格式
// ClipSpyDlg.h : header file
//

#if !defined(AFX_CLIPSPYDLG_H_INCLUDED_)
#define AFX_CLIPSPYDLG_H_INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

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

class CClipSpyDlg : public CDialog
{
// Construction
public:
CClipSpyDlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data
//{{AFX_DATA(CClipSpyDlg)
enum { IDD = IDD_CLIPSPY_DIALOG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA

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

// Implementation
protected:
HICON m_hIcon;

// Generated message map functions
//{{AFX_MSG(CClipSpyDlg)
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnDrawClipboard();
afx_msg void OnDestroy();
afx_msg void OnChangeCbChain(HWND hWndRemove, HWND hWndAfter);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
HWND m_hWndNextCBViewer;
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CLIPSPYDLG_H_INCLUDED_)

//////////////////////////////////////////////////////////////////////////////////
// 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();

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 {
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);
}



              查看评论 回复



嵌入式交流网主页 > 上位机技术 > delphi > 监视剪贴板中数据格式
 

"监视剪贴板中数据格式"的相关文章

网站地图

围观()