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);
本文介绍了一种在Windows应用程序中实现文件拖放功能的方法。主要包括重载wm_dropfiles消息处理函数,设置form属性acceptfiles为true,并在ondropfiles事件中获取并显示拖放的文件名。
560

被折叠的 条评论
为什么被折叠?



