// GetClipboardDlg.h : 头文件//#pragma once#include "afxwin.h"// CGetClipboardDlg 对话框class CGetClipboardDlg : public CDialog{// 构造public: CGetClipboardDlg(CWnd* pParent = NULL); // 标准构造函数// 对话框数据 enum { IDD = IDD_GETCLIPBOARD_DIALOG }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持// 实现protected: HICON m_hIcon; // 生成的消息映射函数 virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); DECLARE_MESSAGE_MAP()public: afx_msg void OnBnClickedButton1(); FILE *fp; BOOL bStart; afx_msg void OnBnClickedButton2(); CListBox m_list; CButton m_start; CEdit m_file; CButton m_choice; int WriteFile(char * szBuf); void StartListenClipBoard(void); afx_msg void OnDrawClipboard();private: CString strPreMsg;public: afx_msg void OnChangeCbChain(HWND hWndRemove, HWND hWndAfter); HWND hNextWnd; afx_msg void OnDestroy(); afx_msg void OnBnClickedButton4(); CButton m_clear;};直接代码吧,不想写点文字的,懒。
// GetClipboardDlg.cpp : 实现文件//#include "stdafx.h"#include "GetClipboard.h"#include "GetClipboardDlg.h"#ifdef _DEBUG#define new DEBUG_NEW#endif// 用于应用程序“关于”菜单项的 CAboutDlg 对话框class CAboutDlg : public CDialog{public: CAboutDlg();// 对话框数据 enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持// 实现protected: DECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD){}void CAboutDlg::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX);}BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)END_MESSAGE_MAP()// CGetClipboardDlg 对话框CGetClipboardDlg::CGetClipboardDlg(CWnd* pParent /*=NULL*/) : CDialog(CGetClipboardDlg::IDD, pParent){ m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);}void CGetClipboardDlg::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_LIST2, m_list); DDX_Control(pDX, IDC_BUTTON2, m_start); DDX_Control(pDX, IDC_EDIT1, m_file); DDX_Control(pDX, IDC_BUTTON1, m_choice); DDX_Control(pDX, IDC_BUTTON4, m_clear);}BEGIN_MESSAGE_MAP(CGetClipboardDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON1, &CGetClipboardDlg::OnBnClickedButton1) ON_BN_CLICKED(IDC_BUTTON2, &CGetClipboardDlg::OnBnClickedButton2) ON_WM_DRAWCLIPBOARD() ON_WM_CHANGECBCHAIN() ON_WM_DESTROY() ON_BN_CLICKED(IDC_BUTTON4, &CGetClipboardDlg::OnBnClickedButton4)END_MESSAGE_MAP()// CGetClipboardDlg 消息处理程序BOOL CGetClipboardDlg::OnInitDialog(){ CDialog::OnInitDialog(); // 将“关于...”菜单项添加到系统菜单中。 // IDM_ABOUTBOX 必须在系统命令范围内。 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 // TODO: 在此添加额外的初始化代码 bStart = FALSE; fp = NULL; m_start.EnableWindow(FALSE); m_clear.EnableWindow(FALSE); hNextWnd = NULL; return TRUE; // 除非将焦点设置到控件,否则返回 TRUE}void CGetClipboardDlg::OnSysCommand(UINT nID, LPARAM lParam){ if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); }}// 如果向对话框添加最小化按钮,则需要下面的代码// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,// 这将由框架自动完成。void CGetClipboardDlg::OnPaint(){ if (IsIconic()) { CPaintDC dc(this); // 用于绘制的设备上下文 SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // 使图标在工作区矩形中居中 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; // 绘制图标 dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); }}//当用户拖动最小化窗口时系统调用此函数取得光标//显示。HCURSOR CGetClipboardDlg::OnQueryDragIcon(){ return static_cast (m_hIcon);}void CGetClipboardDlg::OnBnClickedButton1(){ // TODO: 在此添加控件通知处理程序代码 CFileDialog dlg(TRUE); if( dlg.DoModal() ) { CEdit *pFile = (CEdit*)GetDlgItem(IDC_EDIT1); pFile->SetWindowText( dlg.GetPathName() ); m_list.ResetContent(); m_start.EnableWindow(TRUE); }}void CGetClipboardDlg::OnBnClickedButton2(){ // TODO: 在此添加控件通知处理程序代码 if( FALSE==bStart ) { CString str; char szFileName[256]; GetDlgItem(IDC_EDIT1)->GetWindowText(szFileName,256); if( NULL==(fp=fopen(szFileName,"a+")) ) { MessageBox( "打开文件失败","", MB_ICONWARNING ); return; } m_list.ResetContent(); char c, szBuf[1024]; int i = 0; while( (c=fgetc(fp))!=EOF ) { if( c=='\n' ) { szBuf[i] = '\0'; m_list.AddString(szBuf); i = 0; } else szBuf[i++] = c; } fseek(fp, 0, SEEK_END ); SYSTEMTIME t; GetLocalTime(&t); sprintf( szBuf, "----------------------------------------------------------------------\n%d-%d-%d %d:%d:%d", t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond ); WriteFile( szBuf ); m_start.SetWindowText("停止"); m_file.SetReadOnly(TRUE); m_choice.EnableWindow(FALSE); bStart = TRUE; m_clear.EnableWindow(TRUE); StartListenClipBoard(); } else { char szBuf[1024]; SYSTEMTIME t; GetLocalTime(&t); sprintf( szBuf, "\n\n%d-%d-%d %d:%d:%d\n----------------------------------------------------------------------", t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond ); WriteFile( szBuf ); fclose(fp); fp = NULL; m_start.SetWindowText("开始"); m_file.SetReadOnly(FALSE); m_choice.EnableWindow(TRUE); m_start.EnableWindow(FALSE); m_clear.EnableWindow(FALSE); bStart = FALSE; }}int CGetClipboardDlg::WriteFile(char * szBuf){ if( bStart==TRUE ) { fprintf( fp, "%s\r\n",szBuf ); return 1; } return 0;}void CGetClipboardDlg::StartListenClipBoard(void){ hNextWnd = this->SetClipboardViewer();//设置本窗口到剪贴板监视链}void CGetClipboardDlg::OnDrawClipboard()//响应剪贴板内容变化事件{ CDialog::OnDrawClipboard(); unsigned int anFormats[] = {CF_TEXT}; unsigned int nFormat = GetPriorityClipboardFormat(anFormats,sizeof(anFormats)); if(nFormat == CF_TEXT) { HGLOBAL hMem; OpenClipboard(); if(hMem = ::GetClipboardData(CF_TEXT)) { LPTSTR lpszText = (LPTSTR) GlobalLock(hMem); GlobalUnlock(hMem); CString str1=lpszText; str1.Trim(); this->strPreMsg.Trim(); if( this->strPreMsg!=str1 ) { this->WriteFile( lpszText); this->strPreMsg = lpszText; m_list.AddString( lpszText ); } } } CloseClipboard();}void CGetClipboardDlg::OnChangeCbChain(HWND hWndRemove, HWND hWndAfter){ CDialog::OnChangeCbChain(hWndRemove, hWndAfter); // TODO: 在此处添加消息处理程序代码 //if( hWndRemove==hNextWnd ) }void CGetClipboardDlg::OnDestroy(){ CDialog::OnDestroy(); // TODO: 在此处添加消息处理程序代码 if( hNextWnd!=NULL )this->ChangeClipboardChain(hNextWnd);}void CGetClipboardDlg::OnBnClickedButton4(){ // TODO: 在此添加控件通知处理程序代码 if( bStart!=TRUE ) return; fclose(fp); char szFileName[MAX_PATH]; m_file.GetWindowText( szFileName, MAX_PATH ); if( (fp=fopen( szFileName, "w+" ))==NULL ) { MessageBox( "清空文件失败" ); return; } else { char szBuf[1024]; m_list.ResetContent(); SYSTEMTIME t; GetLocalTime(&t); sprintf( szBuf, "----------------------------------------------------------------------\n%d-%d-%d %d:%d:%d", t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond ); WriteFile( szBuf ); m_list.AddString( "----------------------------------------------------------------------" ); sprintf( szBuf, "%d-%d-%d %d:%d:%d", t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond ); m_list.AddString( szBuf ); }}
效果图:
主要问题是剪贴板的,之前没接触过。具体操作是:
现需要执行this->SetClipboardViewer();//设置本窗口到剪贴板监视链
然后响应WM_OnDrawClipboard消息,之后还有些善后处理的等等..
有些迅雷连续剧资源不是做成一起的,需要一集一集的复制地址,之后会弹出一个迅雷下载框,下载40集,弹个40个。
蛋都碎了,这个可以直接把资源地址保存到文件,之后直接把所有地址复制,然后新建一个迅雷任务就可以下载所有资源了,也算比较方便吧。