-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMyListCtrl.cpp
More file actions
46 lines (44 loc) · 1.29 KB
/
CMyListCtrl.cpp
File metadata and controls
46 lines (44 loc) · 1.29 KB
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
#include "pch.h"
#include "CMyListCtrl.h"
#include "vbdcoderDlg.h"
BEGIN_MESSAGE_MAP(CMyListCtrl, CListCtrl)
ON_WM_DROPFILES()
END_MESSAGE_MAP()
/*
OnDropFiles -> void
消息处理函数
重写了列表的拖放操作, 支持多文件同时拖放. 如果拖入的是文件, 则加入列表.
注: 检测了后缀名, 如果不合法则弹出窗口提示.
*/
void CMyListCtrl::OnDropFiles(HDROP hDropInfo)
{
auto dlg = (CvbdcoderDlg*)CvbdcoderDlg::FromHandle(AfxGetMainWnd()->GetSafeHwnd());
wchar_t path[_MAX_PATH];
auto size = GetItemCount();
UINT nNumOfFiles = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0);
int addedCount = 0;
for (int i = 0; i != nNumOfFiles; i++)
{
DragQueryFile(hDropInfo, i, path, _MAX_PATH);
DWORD attrib = GetFileAttributes(path);
if (!CvbdcoderDlg::checkPath(path))
{
CString tmp;
tmp.Format(L"不支持的后缀名, 跳过文件: %s", path);
AfxMessageBox(tmp);
continue;
}
if ( attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY) == 0)
{
dlg->addToListItems(path, -1);
addedCount++;
}
}
dlg->updateList();
for (int i = 0; i != addedCount; i++)
{
SetCheck(size + i, true);
}
CListCtrl::OnDropFiles(hDropInfo);
DragFinish(hDropInfo);
}