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);