小工具界面如图。
功能实现很简单,这里给出核心代码。
软件支持直接拖拽驱动器或者文件夹到主界面,需要注意的是,获取驱动器的路径可能需要特殊处理。
// DllTestorDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "DllTestor.h"
#include "DllTestorDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// 对话框数据
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// CDllTestorDlg 对话框
/************************************************************
//函数名称:GetDriverInfomation
//函数功能:得到驱动器的信息
//参数1:bAlpha - BYTE型,驱动器的代号A-Z(a-z)
//参数2:iGTI_TYPE - int,将要获取的驱动器信息类型
// GDI_VOLUMENAME 得到驱动器名字
// GDI_VOLUMESERIALNUMBER 得到驱动器序列号
// GDI_VOLUMEFILESYSTEM 得到驱动器文件系统
// GDI_VOLUMETYPE 得到驱动器类型
// GDI_VOLUMESIZE 得到驱动器总大小
// GDI_VOLUMEFREESIZE 得到驱动器剩余大小
//返回值:CString型,所要得到的驱动器信息的字符串表达
//例子:得到C盘的名字GetDriverInfomation('C',GDI_VOLUMENAME)
************************************************************/
#define GDI_VOLUMENAME 0
#define GDI_VOLUMESERIALNUMBER 1
#define GDI_VOLUMEFILESYSTEM 2
#define GDI_VOLUMETYPE 3
#define GDI_VOLUMESIZE 4
#define GDI_VOLUMEFREESIZE 5
CString GetDriverInfomation(BYTE bAlpha,int iGTI_TYPE)
{
CString strResult = _T("");
if(!::IsCharAlpha((TCHAR)bAlpha))
{
strResult = _T("驱动器参数无效!");
return strResult;
}
else
{
/**********获取驱动器名字、序列号和文件系统部分**********/
CString strRootPathName;
strRootPathName.Format(_T("%c:\\"),bAlpha);
LPCTSTR lpRootPathName = strRootPathName;
LPTSTR lpVolumeNameBuffer = new TCHAR[_MAX_FNAME];
DWORD nVolumeNameSize = _MAX_FNAME;
DWORD nVolumeSerialNumber = 0;//便于驱动器无效时做判断
DWORD nMaximumComponentLength;
DWORD nFileSystemFlags;
LPTSTR lpFileSystemNameBuffer = new TCHAR[20];//文件系统(NTFS,FAT)多大有定义好的宏吗
DWORD nFileSystemNameSize = 20;
GetVolumeInformation(
lpRootPathName,
lpVolumeNameBuffer,
nVolumeNameSize,
&nVolumeSerialNumber,
&nMaximumComponentLength,
&nFileSystemFlags,
lpFileSystemNameBuffer,
nFileSystemNameSize);
/**********获取驱动器类型部分**********/
CString strDriveType;
/**********获取驱动器总大小和剩余大小部分**********/
LPCTSTR lpDirectoryName = new TCHAR[2];
lpDirectoryName = (LPCTSTR)strRootPathName.Mid(0,2);
_ULARGE_INTEGER FreeBytesAvailable,TotalNumberOfBytes,TotalNumberOfFreeBytes ;
__int64 iVolumeSize = 0,iVolumeFreeSize = 0;
GetDiskFreeSpaceEx(strRootPathName.Mid(0,2),&FreeBytesAvailable,&TotalNumberOfBytes,&TotalNumberOfFreeBytes );
iVolumeSize = TotalNumberOfBytes.QuadPart / 1024 / 1024;
iVolumeFreeSize = FreeBytesAvailable.QuadPart / 1024 / 1024;
/**********根据参数得出响应的驱动器信息**********/
switch(iGTI_TYPE)
{
case GDI_VOLUMENAME:
if (lpVolumeNameBuffer != NULL)
//strResult.Format(_T("驱动器 %c 的名字为:%s."),bAlpha,lpVolumeNameBuffer);
strResult.Format(_T("%s"),lpVolumeNameBuffer);
else
strResult.Format(_T("获取驱动器名字失败!"));
break;
case GDI_VOLUMESERIALNUMBER:
if (nVolumeSerialNumber != 0)
strResult.Format(_T("驱动器 %c 的序列号为:%X."),bAlpha,nVolumeSerialNumber);
else
strResult.Format(_T("获取驱动器序列号失败!"));
break;
case GDI_VOLUMEFILESYSTEM:
if (lpFileSystemNameBuffer != NULL)
strResult.Format(_T("驱动器 %c 的文件系统为:%s."),bAlpha,lpFileSystemNameBuffer);
else
strResult.Format(_T("获取驱动器文件系统失败!"));
break;
case GDI_VOLUMESIZE:
if (iVolumeSize != 0)
strResult.Format(_T("驱动器 %c 的总大小为:%.2fGB."),bAlpha,(float)iVolumeSize/1024);
else
strResult.Format(_T("获取驱动器总大小失败!"));
break;
case GDI_VOLUMEFREESIZE:
if (iVolumeFreeSize != 0)
strResult.Format(_T("驱动器 %c 的剩余大小为:%.2fGB."),bAlpha,(float)iVolumeFreeSize/1024);
else
strResult.Format(_T("获取驱动器剩余大小失败!"));
break;
case GDI_VOLUMETYPE:
switch(GetDriveType(lpRootPathName))
{
case DRIVE_UNKNOWN:
strDriveType = _T("未知类型!");
break;
case DRIVE_NO_ROOT_DIR:
strResult = _T("没有根目录的驱动器!");
return strResult;
case DRIVE_REMOVABLE:
strDriveType = _T("可移动磁盘");
break;
case DRIVE_FIXED:
strDriveType = _T("硬盘");
break;
case DRIVE_REMOTE:
strDriveType = _T("网络驱动器");
break;
case DRIVE_CDROM:
strDriveType = _T("光驱(CD-ROM)");
break;
case DRIVE_RAMDISK:
strDriveType = _T("RAM磁盘(RAM Disk)");
break;
default:
strResult = _T("未知错误!");
return strResult;
}
strResult.Format(_T("驱动器 %c 的类型为:%s."),bAlpha,strDriveType);
break;
default:
strResult = _T("获取驱动器信息时参数设置错误!");
break;
}
}
/**********返回所要求的驱动器的信息**********/
return strResult;
}
CDllTestorDlg::CDllTestorDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CDllTestorDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDllTestorDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CDllTestorDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//ON_BN_CLICKED(IDC_BUTTON_OPEN, &CDllTestorDlg::OnBnClickedButtonOpen)
ON_BN_CLICKED(IDC_BUTTON_BROWSE, &CDllTestorDlg::OnBnClickedButtonBrowse)
ON_BN_CLICKED(IDOK, &CDllTestorDlg::OnBnClickedOk)
ON_WM_DROPFILES()
ON_WM_ERASEBKGND()
ON_WM_HELPINFO()
END_MESSAGE_MAP()
// CDllTestorDlg 消息处理程序
BOOL CDllTestorDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// 将“关于...”菜单项添加到系统菜单中。
// IDM_ABOUTBOX 必须在系统命令范围内。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
#ifndef NEED_FILE
((CEdit*)GetDlgItem(IDC_EDIT_FILE))->EnableWindow(FALSE);
(CButton*)GetDlgItem(IDC_BUTTON_OPEN)->EnableWindow(FALSE);
#endif
#ifndef NEED_DIR
((CEdit*)GetDlgItem(IDC_EDIT_DIR))->EnableWindow(FALSE);
(CButton*)GetDlgItem(IDC_BUTTON_BROWSE)->EnableWindow(FALSE);
#endif
//读取配置信息
_tstring strIniPath = GetIniPath();
if (CStdFile::IfAccessFile(strIniPath))
{
ReadIniFile(strIniPath, _conf);
}
else
{
WriteIniFile(strIniPath, _conf);
}
if (_conf.bRemPath)
{
#ifdef NEED_DIR
if (_conf.vDirPaths.size() > 0)
{
SetDlgItemText(IDC_EDIT_DIR, VectorToString(_conf.vDirPaths).c_str());
}
#endif // NEED_DIR
#ifdef NEED_FILE
if (_conf.vFilePaths.size() > 0)
{
SetDlgItemText(IDC_EDIT_FILE, VectorToString(_conf.vFilePaths).c_str());
}
#endif // NEED_FILE
}
if (_conf.bSubDir)
{
((CButton*)GetDlgItem(IDC_CHECK_SUBDIR))->SetCheck(TRUE);
}
if (_conf.bFullPath)
{
((CButton*)GetDlgItem(IDC_CHECK_FULLPATH))->SetCheck(TRUE);
}
if (_conf.nSepIndex == 1)
{
((CButton*)GetDlgItem(IDC_RADIO_SEMICOLON))->SetCheck(TRUE);
}
else
{
((CButton*)GetDlgItem(IDC_RADIO_NEWLINE))->SetCheck(TRUE);
}
CComboBox* pCombox = (CComboBox*)GetDlgItem(IDC_COMBO_SUFFIX);
if (pCombox != nullptr)
{
_tstring sCurSuffix = VectorToString(_conf.vSuffixs);
int nJpgQualityIndex = pCombox->FindString(0, CString(sCurSuffix.c_str()));
if (nJpgQualityIndex != -1)
{
pCombox->SetCurSel(nJpgQualityIndex);
}
else
{
pCombox->AddString(CString(sCurSuffix.c_str()));
nJpgQualityIndex = pCombox->FindString(0, CString(sCurSuffix.c_str()));
pCombox->SetCurSel(nJpgQualityIndex);
}
}
//如果是将文件夹拖拽到应用程序图标或者快捷方式
#ifndef _CMD_INPUT
int argc = 0;
#ifdef _UNICODE
LPWSTR *argv=::CommandLineToArgvW(::GetCommandLine(),&argc);
#else
LPWSTR *argv=::CommandLineToArgvW(CStdStr::s2ws(::GetCommandLine()).c_str(),&argc);
#endif
CStringArray arrCmds;
//去掉第一个程序自身的参数
for (int i = 1; i < argc; ++i)
{
#ifdef _UNICODE
arrCmds.Add(argv[i]);
#else
std::string sArc = CStdStr::ws2s(argv[i]);
arrCmds.Add(sArc.c_str());
#endif
}
LocalFree(argv);
if (arrCmds.GetCount() >= 1)
{
int nItems = (int)arrCmds.GetCount();
CString strFiles, strDirs;;
int nFileNum = 0, nDirNum = 0;
for (int i = 0; i < nItems; ++i)
{
CString strCurItem = arrCmds[i];
_tstring sItem = CMfcStrFile::CString2string(strCurItem);
if(PathFileExists(sItem.c_str()))
{
if (CStdFile::IfAccessFile(sItem))
{
#ifdef NEED_FILE
strFiles += strCurItem + CString('|');
++nFileNum;
#endif // NEED_FILE
}
else
{
#ifdef NEED_DIR
strDirs += strCurItem + CString('|');
++nDirNum;
#endif // NEED_DIR
}
}
}
CString strTmp[2];
strTmp[0].LoadString(IDS_PROCESS_NOW);
strTmp[1].LoadString(IDS_TIPS);
//文件和文件夹同时成立时才会执行,可根据需要修改
if (nFileNum + nDirNum > 0 && MessageBox(strTmp[0], strTmp[1], MB_YESNO) == IDYES)
{
strFiles.Trim('|');
SetDlgItemText(IDC_EDIT_FILE, strFiles);
strDirs.Trim('|');
SetDlgItemText(IDC_EDIT_DIR, strDirs);
OnBnClickedOk();
}
}
#endif // _CMD_INPUT
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
void CDllTestorDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void CDllTestorDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(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
{
CDialogEx::OnPaint();
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CDllTestorDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
// void CDllTestorDlg::OnBnClickedButtonOpen()
// {
// // TODO: 在此添加控件通知处理程序代码
// CString strFilePath = CMfcStrFile::OpenFile();
//
// if (strFilePath.GetLength() > 0)
// {
// SetDlgItemText(IDC_EDIT_FILE, strFilePath);
// CString strTmp[2];
// strTmp[0].LoadString(IDS_PROCESS_NOW);
// strTmp[1].LoadString(IDS_TIPS);
// if (MessageBox(strTmp[0], strTmp[1], MB_YESNO) == IDYES)
// {
// OnBnClickedOk();
// }
// }
// }
void CDllTestorDlg::OnBnClickedButtonBrowse()
{
// TODO: 在此添加控件通知处理程序代码
CString strDirPath = CMfcStrFile::BrowseDir();
if (strDirPath.GetLength() > 0)
{
SetDlgItemText(IDC_EDIT_DIR, strDirPath);
SetDlgItemText(IDC_EDIT_FILE, strDirPath + _T(".txt"));
CString strTmp[2];
strTmp[0].LoadString(IDS_PROCESS_NOW);
strTmp[1].LoadString(IDS_TIPS);
if (MessageBox(strTmp[0], strTmp[1], MB_YESNO) == IDYES)
{
OnBnClickedOk();
}
}
}
void CDllTestorDlg::OnBnClickedOk()
{
// TODO: 在此添加命令处理程序代码
#ifdef NEED_DIR
CString strDir;
GetDlgItemText(IDC_EDIT_DIR, strDir);
if (!strDir.GetLength())
{
strDir = CMfcStrFile::BrowseDir();
if (strDir.GetLength() > 0)
{
SetDlgItemText(IDC_EDIT_DIR, strDir);
}
else
{
return;
}
}
_tstring sDir = CMfcStrFile::CString2string(strDir);
_conf.vDirPaths.clear();
_conf.vDirPaths.push_back(sDir);
#endif // NEED_DIR
#ifdef NEED_FILE
CString strFile;
GetDlgItemText(IDC_EDIT_FILE, strFile);
if (!strFile.GetLength())
{
strFile = CMfcStrFile::OpenFile();
if (strFile.GetLength() > 0)
{
SetDlgItemText(IDC_EDIT_FILE, strFile);
}
else
{
return;
}
}
_tstring sFile = CMfcStrFile::CString2string(strFile);
_conf.vFilePaths.clear();
_conf.vFilePaths.push_back(sFile);
#endif // NEED_FILE
//获取全路径
_conf.bSubDir = ((CButton*)GetDlgItem(IDC_CHECK_SUBDIR))->GetCheck() == TRUE;
_conf.bFullPath = ((CButton*)GetDlgItem(IDC_CHECK_FULLPATH))->GetCheck() == TRUE;
if (((CButton*)GetDlgItem(IDC_RADIO_SEMICOLON))->GetCheck() == TRUE)
{
_conf.nSepIndex = 1;
}
else
{
_conf.nSepIndex = 0;
}
char cSepStr = _conf.nSepIndex == 1 ? ';' : '\n';
//获取后缀
CComboBox* pCombox = (CComboBox*)GetDlgItem(IDC_COMBO_SUFFIX);
if (pCombox != nullptr)
{
CString strSuffix;
pCombox->GetWindowText(strSuffix);
_conf.vSuffixs.clear();
_conf.vSuffixs.push_back(CMfcStrFile::CString2string(strSuffix));
}
_tstring sSuffix = VectorToString(_conf.vSuffixs);
//测试时间
clock_t start, finish;
double duration;
start = clock();
//开始显示进度
//开始显示进度
CTaskBarProgress tbp(m_hWnd);
CProgressInterface* ppi = &tbp;
ppi->Start();
/*********************************这里增加主程序 开始***************************************/
ppi->OutputInfo("Reading the files!");
std::vector<_tstring> vFiles;
std::string suffix = CStdStr::ws2s(sSuffix);
getFiles(sDir, vFiles, suffix.c_str(), _conf.bSubDir);
//将文件转换
for (auto it = vFiles.begin(); it != vFiles.end(); ++it)
{
if (!_conf.bFullPath)
{
*it = CStdStr::GetNameOfFile(*it);
}
*it += cSepStr;
}
CStdFile::SaveTXTFile(sFile, vFiles);
/*********************************这里增加主程序 结束***************************************/
ppi->End();
FlashWindow(TRUE);
finish = clock();
duration = double(finish - start) / CLOCKS_PER_SEC;
int nMinutes = int(duration / 60);
int nSeconds = (int)duration % 60;
CString strTips;
strTips.Format(_T("%d分%d秒%d毫秒"), nMinutes, nSeconds, (finish - start) % CLOCKS_PER_SEC);
//保存log,当前时间以及耗时
CString strTime, strDate; //获取系统时间
CTime tm = CTime::GetCurrentTime();
strTime = tm.Format("%Y年%m月%d日 %X");
strDate = tm.Format("%Y年%m月%d日");
_tstring sLogLine;
#ifdef NEED_FILE
sLogLine = sFile;
#endif // NEED_FILE
#ifdef NEED_DIR
sLogLine = sDir;
#endif // NEED_DIR
//同时需要文件和文件夹时,记录文件夹
CString strSaveLine = _T("本次耗时:") + strTips + "\t" + CString(sDir.c_str()) + '\n';
//保存日志和配置文件
_tstring strIniPath = GetIniPath();
_tstring strExeDir = CStdStr::GetDirOfFile(strIniPath);
CString strLogPath = CStdStr::AddSlashIfNeeded(strExeDir).c_str() + strDate + ".log";
CStdioFile sStdFile(strLogPath, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite);
sStdFile.SeekToEnd();
setlocale(LC_CTYPE, "chs");//设定f
sStdFile.WriteString(strSaveLine);
setlocale(LC_ALL, "C"); //还原区域设定
sStdFile.Close();
WriteIniFile(strIniPath, _conf);
AfxMessageBox(strTips);
CDialogEx::OnOK();
}
_tstring CDllTestorDlg::GetIniPath(const TCHAR* szFileExt /*= _T(".ini")*/)
{
TCHAR chpath[MAX_PATH];
GetModuleFileName(NULL, chpath, sizeof(chpath));
_tstring strModulePath = CMfcStrFile::CString2string(chpath);
_tstring strIniPath = CStdStr::ReplaceSuffix(strModulePath, szFileExt);
return strIniPath;
}
void CDllTestorDlg::OnDropFiles(HDROP hDropInfo)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
// 定义一个缓冲区来存放读取的文件名信息
TCHAR* szItemPath = nullptr;
const int nMaxPathLength = 2048;
CStdTpl::NewSafely(szItemPath, nMaxPathLength, true);
// 通过设置iFiles参数为0xFFFFFFFF,可以取得当前拖动的文件数量,
// 当设置为0xFFFFFFFF,函数间忽略后面两个参数。
UINT nNum = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0);
// 通过循环依次取得拖动文件的File Name信息,并把它添加到ListBox中
CString strFiles, strDirs;
DragQueryFile(hDropInfo, 0, szItemPath, nMaxPathLength);
if (PathFileExists(szItemPath) == TRUE)
{
if (CStdFile::IfAccessFile(CMfcStrFile::CString2string(szItemPath)))
{
#ifdef NEED_FILE
strFiles += szItemPath + CString('|');
#endif // NEED_FILE
}
else if(PathIsDirectory(szItemPath))
{
#ifdef NEED_DIR
strDirs += szItemPath + CString('|');
#endif // NEED_DIR
}
}
strDirs.Trim('|');
SetDlgItemText(IDC_EDIT_DIR, strDirs);
if (strDirs.GetLength() == 3)
{
//此时为驱动器
strDirs += GetDriverInfomation(strDirs[0],GDI_VOLUMENAME);
}
SetDlgItemText(IDC_EDIT_FILE, strDirs + _T(".txt"));
// 结束此次拖拽操作,并释放分配的资源
CStdTpl::DelPointerSafely(szItemPath, true);
DragFinish(hDropInfo);
CDialogEx::OnDropFiles(hDropInfo);
}
BOOL CDllTestorDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CDialogEx::OnEraseBkgnd(pDC);
HBITMAP hBitmap = ::LoadBitmap(::GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BITMAP1));
//获取位图尺寸
BITMAP bitmap;
GetObject(hBitmap, sizeof (BITMAP), &bitmap);
//获取对话框尺寸
CRect rect;
GetClientRect(&rect);
//创建DC
HDC m_hBkDC= ::CreateCompatibleDC(pDC->m_hDC);
//绘图并清理
if(hBitmap && m_hBkDC)
{
::SelectObject(m_hBkDC,hBitmap);
::StretchBlt(pDC->m_hDC, 0, 0, rect.Width(), rect.Height(),m_hBkDC,0,0,bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
::DeleteObject(hBitmap);
::DeleteDC(m_hBkDC);
}
//这个很重要
return TRUE;
}
BOOL CDllTestorDlg::OnHelpInfo(HELPINFO* pHelpInfo)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (MessageBox(_T("如果遇到任何问题需要帮助,\n请通过邮箱autumoon@vip.qq.com联系我!\n\n立即复制“autumoon@vip.qq.com”到剪贴板吗?"),
_T("需要帮助"), MB_YESNO) == IDYES)
{
//已经复制到剪贴板
if(OpenClipboard())
{
_tstring source(_T("autumoon@vip.qq.com"));
HGLOBAL clipbuffer;
char* buffer;
EmptyClipboard();
clipbuffer = GlobalAlloc(GMEM_DDESHARE, source.size() + 1);
buffer = (char*)GlobalLock(clipbuffer);
#ifdef _UNICODE
std::string sSrc = CStdStr::ws2s(source);
#else
std::string sSrc(source);
#endif // _UNICODE
strcpy(buffer, sSrc.c_str());
GlobalUnlock(clipbuffer);
SetClipboardData(CF_TEXT,clipbuffer);
CloseClipboard();
MessageBox(_T("已经成功复制到剪贴板!"), _T("地址复制完成!"), MB_ICONINFORMATION);
}
}
return TRUE;
}
更多交流,欢迎留言。