MFC对话框响应拖文件WM_DROPFILES
2022-10-20
34
0
首先初始化启用DragAcceptFiles
DragAcceptFiles(TRUE);
然后在添加类向导中增加消息:WM_DROPFILES
void CVCMAppDlg::OnDropFiles(HDROP hDropInfo)
{
CDialogEx::OnDropFiles(hDropInfo);
UINT count;
TCHAR filePath[MAX_PATH] = { 0 };
count = DragQueryFile(hDropInfo, -1, NULL, 0);
if (1 == count)
{
DragQueryFile(hDropInfo, 0, filePath, sizeof(filePath));
this->SetWindowTextW(filePath);
UpdateData(FALSE);
DragFinish(hDropInfo); //拖放成功后,释放内存
}
else
{
CString szFilePath;
for (UINT i = 0; i < count; i++)
{
int pahtLen = DragQueryFile(hDropInfo, i, filePath, sizeof(filePath));
szFilePath = szFilePath + filePath + _T("\r\n");
}
this->SetWindowTextW(szFilePath);
UpdateData(FALSE);
DragFinish(hDropInfo);
}
DragFinish(hDropInfo);
}