MFC + MDI文件拖拽功能

来源:互联网 发布:ansys仿真软件价格 编辑:程序博客网 时间:2024/05/18 00:29

第一步:

首先在int CXXXView::OnCreate(LPCREATESTRUCT lpCreateStruct)中添加this->DragAcceptFiles();

第二步:

打开类向导


添加WM_DROPFILES消息

第三步:

OnDropFiles函数中接收文件路径

void CxxxView::OnDropFiles(HDROP hDropInfo)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
//Add 
int DropCount = DragQueryFile(hDropInfo, -1, NULL, 0); // 取得文件数量 When the function copies a file name to the buffer, the return value is a count of the characters copied, not including the terminating null character.
for(int i = 0; i < DropCount; i++)  // 遍历
{  
TCHAR strFileName[MAX_PATH];  
DragQueryFile(hDropInfo, i, strFileName, MAX_PATH); // 获得文件名(包含路径) Retrieves the names of dropped files that result from a successful drag-and-drop operation.
theApp.OpenDocumentFile(strFileName); // 打开文件
}   
DragFinish(hDropInfo);  // 释放内存  Releases memory that the system allocated for use in transferring file names to the application.

CScrollView::OnDropFiles(hDropInfo);
}

 

0 0