如何在对话框中实现文件拖放功能
2012-10-18 12:27
344 查看
以下文章转载自:http://blog.sina.com.cn/s/blog_6a6d5ba80100lcay.html ,致谢!!
如何在对话框中实现文件拖放功能
在对话框上添加一个Picture
Control,然后把Accept Files属性修改成True。如果是想托图片的话需要把Type改成Bitmap。
在头文件里加入:afx_msg void OnDropFiles(HDROP
hDropInfo);
在cpp文件里加入:ON_WM_DROPFILES()
在OnInitDialog()的最后加入:DragAcceptFiles(TRUE);
在cpp文件里添加:
到此为止已经结束。为了证明拖拽文件ok可以做一个小测试。
在对话框中加入一个edit
box,
然后在头文件中加入:CString
m_StrPath;
在cpp文件的DoDataExchange(CDataExchange*
pDX)函数中加入
DDX_Text(pDX, IDC_EDIT0, m_StrPath);
在DragQueryFile后添加:
m_StrPath.Format("%s",strFilePath);
UpdateData(FALSE);
然后测试就会发现只要拖拽一个文件就会在edit
box里出现此文件的全路径。
如何在对话框中实现文件拖放功能
在对话框上添加一个Picture
Control,然后把Accept Files属性修改成True。如果是想托图片的话需要把Type改成Bitmap。
在头文件里加入:afx_msg void OnDropFiles(HDROP
hDropInfo);
在cpp文件里加入:ON_WM_DROPFILES()
在OnInitDialog()的最后加入:DragAcceptFiles(TRUE);
在cpp文件里添加:
void CTestDragDlg::OnDropFiles(HDROP hDropInfo){ int nFileCount = DragQueryFile(hDropInfo, -1, NULL, 0); TCHAR *strFilePath; int dwSize; if (nFileCount==1) { dwSize = DragQueryFile(hDropInfo, 0, NULL, 0); strFilePath = new TCHAR[dwSize+1]; if (strFilePath) { DragQueryFile(hDropInfo, 0, strFilePath, dwSize+1); //Retrieves the names of dropped files that result from a successful drag-and-drop operation. //Do sth to prove succeed delete []strFilePath; } } CDialog::OnDropFiles(hDropInfo); DragFinish(hDropInfo); Invalidate(); }
到此为止已经结束。为了证明拖拽文件ok可以做一个小测试。
在对话框中加入一个edit
box,
然后在头文件中加入:CString
m_StrPath;
在cpp文件的DoDataExchange(CDataExchange*
pDX)函数中加入
DDX_Text(pDX, IDC_EDIT0, m_StrPath);
在DragQueryFile后添加:
m_StrPath.Format("%s",strFilePath);
UpdateData(FALSE);
然后测试就会发现只要拖拽一个文件就会在edit
box里出现此文件的全路径。
相关文章推荐
- 如何在对话框中实现文件拖放功能
- 如何在vc6.0的单文档和对话框中实现文件拖放功能
- 如何在对话框中实现文件拖放功能
- 如何在vc6.0的单文档和对话框中实现文件拖放功能
- jsp如何实现下载文件的功能
- REDHAT5中如何配置SAMBA实现window与linux之间的文件互访功能!
- 图形的绘制,如何使用自定义画笔(颜色,线宽,线形)。如何为程序中添加选项菜单和选项设置对话框,如何使用标准颜色对话框,如何使用字体对话框,在选项对话框中实现预览功能。实现选项对话框和窗口类中的数据交换。如何改变对话框和控件的背景色,如何改变控件的文本颜色,
- 如何实现web应用下载文件时不弹出文件保存对话框,而是直接保存到指定的文件中
- [置顶] 如何用FFmpeg API采集摄像头视频和麦克风音频,并实现录制文件的功能
- VC下在对话框上实现接受文件拖放 (Drop files)
- android如何实现文件打开方式可供选择功能。
- 实现窗口的文件拖放功能
- 如何用VC60实现类似windows搜索文件的功能,针对文件夹中包含的文件名进行模糊查
- 请问:如何实现文件日志功能?要求每天换一个文件。文件名以日期区分
- C#中 如何通过路径实现文件上传功能
- 如何实现虚拟机跟主机间文件共享和复制粘贴功能及互ping通功能
- 如何在web端实现本地文件的访问功能
- Linux如何实现断点续传文件功能?
- java 利用文件对话框实现文件的转存功能
- IIS7中 ASP.NET授权功能如何实现对静态文件的控制