Repository navigation
Expand file tree
/
Copy pathDriveDialog.cpp
More file actions
169 lines (140 loc) · 3.5 KB
/
Copy pathDriveDialog.cpp
File metadata and controls
169 lines (140 loc) · 3.5 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include "stdafx.h"
#include "spacemonger.h"
#include "DriveDialog.h"
#include "Lang.h"
namespace {
int GetDriveIndex(CListCtrl *list, int item)
{
const DWORD_PTR driveIndex = list->GetItemData(item);
if (driveIndex > static_cast<DWORD_PTR>('Z' - 'A')) {
ASSERT(FALSE);
return -1;
}
return static_cast<int>(driveIndex);
}
}
CDriveDialog::CDriveDialog(CWnd* pParent)
: CDialog(IDD_OPEN_DIALOG, pParent)
{
}
BEGIN_MESSAGE_MAP(CDriveDialog, CDialog)
//{{AFX_MSG_MAP(CDriveDialog)
ON_NOTIFY(NM_DBLCLK, IDC_DRIVE_LIST, OnDriveDblClk)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CDriveDialog::OnDriveDblClk(NMHDR *pNotifyStruct, LRESULT *result)
{
CListCtrl *lc = (CListCtrl *)GetDlgItem(IDC_DRIVE_LIST);
if (lc == NULL) return;
if (lc->GetSelectedCount() != 1) return;
int i, max = lc->GetItemCount();
for (i = 0; i < max; i++) {
if (lc->GetItemState(i, LVIS_SELECTED)) {
EndDialog(GetDriveIndex(lc, i));
}
}
}
void CDriveDialog::OnOK()
{
CListCtrl *lc = (CListCtrl *)GetDlgItem(IDC_DRIVE_LIST);
if (lc == NULL) EndDialog(-1);
if (lc->GetSelectedCount() != 1) return;
int i, max = lc->GetItemCount();
for (i = 0; i < max; i++) {
if (lc->GetItemState(i, LVIS_SELECTED)) {
EndDialog(GetDriveIndex(lc, i));
}
}
}
void CDriveDialog::OnCancel()
{
EndDialog(-1);
}
BOOL CDriveDialog::OnInitDialog()
{
CWaitCursor wait;
CDialog::OnInitDialog();
CDriveInfo driveinfo[26];
HIMAGELIST imagelist;
int i, index;
LVITEMW item = {};
imagelist = ImageList_Create(32, 32, TRUE, 0, 26);
CListCtrl *lc = (CListCtrl *)GetDlgItem(IDC_DRIVE_LIST);
::SendMessage(lc->m_hWnd, LVM_SETIMAGELIST, (WPARAM)LVSIL_NORMAL, (LPARAM)(HIMAGELIST)imagelist);
SetWindowText(CurLang->selectdrive);
SetDlgItemText(IDOK, CurLang->ok);
SetDlgItemText(IDCANCEL, CurLang->cancel);
lc->InsertColumn(0, L"Name");
if (lc != NULL) {
lc->SetItemCount(26);
index = 0;
for (i = 'A'; i <= 'Z'; i++) {
driveinfo[i-'A'].LoadDriveInfo(i);
if (driveinfo[i-'A'].avail) {
ImageList_AddIcon(imagelist, driveinfo[i-'A'].icon);
item.mask = LVIF_STATE|LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
item.iItem = index;
item.iSubItem = 0;
item.state = 0;
item.stateMask = LVIS_SELECTED;
item.pszText = driveinfo[i-'A'].longname;
item.cchTextMax = (int)wcslen(driveinfo[i-'A'].longname);
item.iImage = index;
item.lParam = i - 'A';
::SendMessageW(lc->m_hWnd, LVM_INSERTITEMW, (WPARAM)0, (LPARAM)(&item));
index++;
}
driveinfo[i-'A'].Free();
}
}
return TRUE;
}
//////////////////////////////////////////////////////////////////////////////
CDriveInfo::CDriveInfo()
: letter(0), avail(FALSE), icon(NULL), longname(NULL)
{
}
CDriveInfo::~CDriveInfo()
{
Free();
}
void CDriveInfo::Free(void)
{
if (longname != NULL) {
delete[] longname;
longname = NULL;
}
if (icon != NULL) {
DestroyIcon(icon);
icon = NULL;
}
}
void CDriveInfo::LoadDriveInfo(char let)
{
Free();
wchar_t name[8];
UINT type;
if (let >= 'a' && let <= 'z') let -= 32;
name[0] = (wchar_t)let;
name[1] = L':';
name[2] = L'\\';
name[3] = L'\0';
type = GetDriveTypeW(name);
if (type != 0 && type != 1) {
SHFILEINFOW fileinfo;
memset(&fileinfo, 0, sizeof(SHFILEINFO));
SHGetFileInfoW(name, 0, &fileinfo, sizeof(SHFILEINFOW),
SHGFI_DISPLAYNAME|SHGFI_ICON);
avail = 1;
letter = let;
icon = fileinfo.hIcon;
longname = new wchar_t[wcslen(fileinfo.szDisplayName)+1];
wcscpy_s(longname, wcslen(fileinfo.szDisplayName)+1, fileinfo.szDisplayName);
}
else {
avail = 0;
letter = let;
icon = NULL;
longname = NULL;
}
}