使对话框支持拖拽文件操作需要两步,
1、给对话框设置接受文件属性,见下图
2、为对话框添加消息WM_DROPFILES 的响应函数OnDropFiles()
下面给出OnDropFiles()的实现:
void CMJSpliceVideoDlg::OnDropFiles(HDROP hDropInfo)
{
char filepath[MAX_PATH]={0};
unsigned int count=::DragQueryFile(hDropInfo,0xFFFFFFFF,NULL,NULL);//首先获取文件的个数。
if(count>0)
{
for(unsigned int i=0;i<count;i++)
{
int pathlen=::DragQueryFile(hDropInfo,i,filepath,sizeof(filepath));//获取文件路径。
AfxMessageBox(filepath);
}
}
CDialogEx::OnDropFiles(hDropInfo);
}
函数DragQueryFile和DragQueryFile的具体使用请参看msdn。