-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyEdit.cpp
82 lines (64 loc) · 1.41 KB
/
MyEdit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// MyEdit.cpp : 实现文件
//
//拷贝到工程目录下使用
#include "stdafx.h"
#include "MyEdit.h"
// CMyEdit
IMPLEMENT_DYNAMIC(CMyEdit, CEdit)
CMyEdit::CMyEdit():m_nFlag(EDIT_NONE_JUDGE)
{
}
CMyEdit::~CMyEdit()
{
}
BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
ON_WM_DROPFILES()
END_MESSAGE_MAP()
// CMyEdit 消息处理程序
void CMyEdit::OnDropFiles(HDROP hDropInfo)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if(hDropInfo)
{
//拖拽文件的数量
UINT nDrag = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0);
//只拖拽一个文件
if (nDrag > 1 && (m_nFlag & EDIT_SIG_JUDGE))
{
nDrag = 1;
}
// 被拖拽的文件的文件名
TCHAR* szItemPath = new TCHAR[MAX_PATH + 1]();
CString strAllPath;
for (UINT i = 0; i < nDrag; ++i)
{
memset(szItemPath, 0, sizeof(TCHAR) * (MAX_PATH + 1));
DragQueryFile(hDropInfo, i, szItemPath, MAX_PATH);
if (PathFileExists(szItemPath) == TRUE)
{
//根据类型判断
if ((m_nFlag & EDIT_DIR_JUDGE) && PathIsDirectory(szItemPath))
{
strAllPath += szItemPath;
}
else if ((m_nFlag & EDIT_FILE_JUDGE) && !PathIsDirectory(szItemPath))
{
strAllPath += szItemPath;
}
else if (m_nFlag == EDIT_NONE_JUDGE)
{
strAllPath += szItemPath;
}
//超一个项目的时添加间隔符
if (nDrag > 1)
{
strAllPath += ";";
}
}
SetWindowText(strAllPath);
}
delete[] szItemPath;
szItemPath = nullptr;
}
CEdit::OnDropFiles(hDropInfo);
}