VC++文件拖放

时间:2023-03-09 13:25:34
VC++文件拖放

属性Accept Files 设置True,消息WM_DROPFILES 设置事件OnDropFiles

void CNWiReworkDlg::OnDropFiles(HDROP hDropInfo)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
LPTSTR pFilePathName = (LPTSTR)malloc();
DragQueryFile(hDropInfo, , pFilePathName, ); // 获取拖放文件的完整文件名,最关键! CString filePath = pFilePathName;
filePath.MakeLower();
if (filePath.Find(_T(".bin")) > -)
{
m_ctrlProgress.SetPos();
ShowMessage(_T(""), );
SetDlgItemText(IDC_STATIC_HexFileName, pFilePathName);
} DragFinish(hDropInfo); //拖放结束后,释放内存
CDialog::OnDropFiles(hDropInfo);
free(pFilePathName);
}