MFC实现拖拽文件
2013-04-17 10:39
309 查看
Dragging Files
Dragging Files can be supported relatively easily as follows * Add a OnDropFiles(HDROP hDropInfo) handler to your Dialog. You'll probably have to add this manually, as ClassWizard doesn't seen to support the WM_DROPFILES message for dialogs.
Make the following changes
1) In your .h file add the OnDropFiles to the AFX_MSG section
// Generated message map functions
//{{AFX_MSG(A2hDialog)
...
afx_msg void OnDropFiles(HDROP hDropInfo);
...
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
2) In your .cpp file add the ON_WM_DROPFILES() handler to the AFX_MSG_MAP section
BEGIN_MESSAGE_MAP(MyDialog, CDialog)
//{{AFX_MSG_MAP(MyDialog)
...
ON_WM_DROPFILES()
...
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
Strangely, after doing (1) and (2) the results become visible in the ClassWizard.
3)
Use ClassWizard to add an OnCreate() handler to your dialog. in this add the call
this->DragAcceptFiles(TRUE);
This enables Drag and drop of files on your Dialog's window. You can check this by dragging files over your Window. If the cursor is a "no entry" sign (circle with a line through it) it's not working. If the cursor changes to a file/folder icon with a "+" on it, you're in business.
4) Manually add the OnDropFiles method to look something as follows :-
void MyDialog::OnDropFiles(HDROP hDropInfo)
{
HDROP m_hDropInfo = hDropInfo;
CString Filename;
if (m_hDropInfo) {
int iFiles = DragQueryFile(m_hDropInfo, (UINT)-1, NULL, 0);
for (int i=0; i<ifiles; i++) {
char* pFilename = Filename.GetBuffer(_MAX_PATH);
DragQueryFile(m_hDropInfo, i, pFilename, _MAX_PATH);
// do whatever...
} // for each files...
} // if DropInfo
DragFinish(m_hDropInfo);
m_hDropInfo = 0;
} // End of OnDropFiles
相关文章推荐
- MFC----文件拖拽的实现OnDropFiles
- MFC中窗口实现拖拽文件功能
- MFC单个控件实现文件拖拽功能
- VC/MFC 实现文件拖拽获取文件名(WM_DROPFILES)
- mfc实现文件的拖拽操作
- VS2008中,MFC对话框类实现类似QQ拖拽上传文件的功能,CWnd::OnDropFiles
- MFC----文件拖拽的实现OnDropFiles
- 在MFC中实现拖拽文件到对话框中的编辑控件中
- windows sdk 实现文件拖拽 不是使用mfc
- MFC实现拖拽文件
- MFC单文档实现文件拖拽功能
- MFC----文件拖拽的实现OnDropFiles
- MFC文档应用程序实现文件拖拽到应用程序中显示
- MFC中实现单个控件接收拖拽文件的功能
- MFC实现文件拖拽功能
- MFC中实现单个控件接收拖拽文件的功能
- MFC对话框实现txt文件读写,及时间差判断
- 通过继承实现edit控件的拖拽文件功能扩展的一般步骤
- 实现将文件拖拽到richtextbox进行显示
- JavaScript实现拖拽预览,AJAX小文件上传