1/重载wm_dropfiles
2/在form属性选择accept files=true
3/在ondropfiles添加如下:
char *lpszFileName=new char[512];
int nFileCount;
nFileCount=::DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 512);
if(nFileCount == 1)
{
UINT nChars=::DragQueryFile(hDropInfo, 0, &lpszFileName[0], 512);
CString str(&lpszFileName[0], nChars);
//
SetDlgItemText(IDC_FILENAME,str);
}
else
{
::AfxMessageBox("请勿拖放多个文件!");
}
::DragFinish(hDropInfo); //释放内存
delete []lpszFileName;
//
CDialog::OnDropFiles(hDropInfo);