Repository navigation
Expand file tree
/
Copy pathScanDetailsDialog.cpp
More file actions
73 lines (62 loc) · 1.75 KB
/
Copy pathScanDetailsDialog.cpp
File metadata and controls
73 lines (62 loc) · 1.75 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
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
#include "stdafx.h"
#include "resource.h"
#include "ScanDetailsDialog.h"
#include "PathUtil.h"
#include "Lang.h"
CScanDetailsDialog::CScanDetailsDialog(ui64 totalSkipped,
const std::vector<std::wstring>& paths, CWnd *parent)
: CDialog(IDD_SCAN_DETAILS, parent)
, m_totalSkipped(totalSkipped)
, m_paths(paths)
{
}
BEGIN_MESSAGE_MAP(CScanDetailsDialog, CDialog)
ON_BN_CLICKED(IDC_SCAN_DETAILS_COPY, OnCopyPaths)
END_MESSAGE_MAP()
BOOL CScanDetailsDialog::OnInitDialog()
{
CDialog::OnInitDialog();
SetWindowText(CurLang->scan_details_title);
CString summary;
summary.Format(CurLang->scan_details_summary_format,
m_totalSkipped, (ui64)m_paths.size());
SetDlgItemText(IDC_SCAN_DETAILS_SUMMARY, summary);
SetDlgItemText(IDC_SCAN_DETAILS_COPY, CurLang->scan_details_copy);
SetDlgItemText(IDOK, CurLang->ok);
CListBox *list = (CListBox *)GetDlgItem(IDC_SCAN_DETAILS_LIST);
if (list != NULL) {
for (const auto& path : m_paths) {
list->AddString(path.c_str());
}
}
return TRUE;
}
void CScanDetailsDialog::OnCopyPaths()
{
if (m_paths.empty()) return;
SIZE_T chars = 1;
for (const auto& path : m_paths) chars += path.length() + 2;
HGLOBAL memory = GlobalAlloc(GMEM_MOVEABLE, chars * sizeof(wchar_t));
if (memory == NULL) return;
wchar_t *buffer = (wchar_t *)GlobalLock(memory);
if (buffer == NULL) {
GlobalFree(memory);
return;
}
wchar_t *cursor = buffer;
for (const auto& path : m_paths) {
memcpy(cursor, path.c_str(), path.length() * sizeof(wchar_t));
cursor += path.length();
*cursor++ = L'\r';
*cursor++ = L'\n';
}
*cursor = L'\0';
GlobalUnlock(memory);
if (!::OpenClipboard(m_hWnd)) {
GlobalFree(memory);
return;
}
EmptyClipboard();
if (SetClipboardData(CF_UNICODETEXT, memory) == NULL) GlobalFree(memory);
CloseClipboard();
}