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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
//*********************************************************************
//* Microsoft Windows **
//* Copyright(c) Microsoft Corp., 1993 **
//*********************************************************************
#include "admincfg.h"
BOOL OnSelection(HWND hwndParent,HWND hwndList,NM_LISTVIEW *pnlv);
BOOL OnDoubleClick(HWND hwndParent,HWND hwndList);
extern HIMAGELIST hImageListSmall,hImageListLarge;
BOOL OnListNotify(HWND hwndParent,HWND hwndList,NM_LISTVIEW *pnlv)
{
switch (pnlv->hdr.code) {
case LVN_ITEMCHANGED:
return OnSelection(hwndParent,hwndList,pnlv);
return FALSE;
break;
case LVN_KEYDOWN:
switch (((LV_KEYDOWN *) pnlv)->wVKey) {
case VK_RETURN:
OnProperties(hwndParent,hwndList);
return FALSE;
break;
case VK_DELETE:
if ((dwAppState & AS_CANREMOVE) &&
(dwAppState & AS_POLICYFILE))
OnRemove(hwndParent,hwndList);
return FALSE;
break;
}
break;
case NM_DBLCLK:
OnDoubleClick(hwndParent,hwndList);
return FALSE;
break;
}
return FALSE;
}
BOOL OnDoubleClick(HWND hwndParent,HWND hwndList)
{
HGLOBAL hUser;
LV_HITTESTINFO ht;
GetCursorPos(&ht.pt);
ScreenToClient(hwndList,&ht.pt);
if (ListView_HitTest(hwndList,&ht)<0) return FALSE;
if (!(hUser = (HGLOBAL) ListView_GetItemParm(hwndList,ht.iItem)))
return FALSE;
DoPolicyDlg(hwndParent,hUser);
return FALSE;
}
BOOL OnProperties(HWND hwndParent,HWND hwndList)
{
HGLOBAL hUser;
int iItem;
iItem = ListView_GetNextItem(hwndList,-1,LVNI_SELECTED);
if (iItem<0)
return FALSE;
if (!(hUser = (HGLOBAL) ListView_GetItemParm(hwndList,iItem)))
return FALSE;
DoPolicyDlg(hwndParent,hUser);
return TRUE;
}
/*******************************************************************
NAME: CreateListControl
SYNOPSIS: Creates list control for main window
********************************************************************/
HWND CreateListControl(HWND hWnd)
{
HWND hwndList;
LV_COLUMN lvc;
int iRet;
if (!(hwndList = CreateWindowEx(WS_EX_CLIENTEDGE,
szLISTVIEW,szNull,WS_CHILD | WS_VISIBLE | LVS_REPORT |
LVS_SORTASCENDING | LVS_SHAREIMAGELISTS,
0,0,0,0,hWnd,NULL,ghInst,NULL)))
return NULL;
lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
lvc.fmt = LVCFMT_LEFT;
lvc.cx = 150;
lvc.pszText = LoadSz(IDS_COLUMNTITLE,szSmallBuf,ARRAYSIZE(szSmallBuf));
lvc.cchTextMax = lstrlen(lvc.pszText) + 1;
lvc.iSubItem = 0;
iRet=ListView_InsertColumn(hwndList,0,&lvc);
ListView_SetImageList(hwndList,hImageListSmall,LVSIL_SMALL);
ListView_SetImageList(hwndList,hImageListLarge,LVSIL_NORMAL);
return hwndList;
}
/*******************************************************************
NAME: DestroyListControl
SYNOPSIS: Destroys main window list control
********************************************************************/
VOID DestroyListControl(HWND hwndList)
{
if (hwndList) {
DestroyWindow(hwndList);
}
}
/*******************************************************************
NAME: UpdateListControlPlacement
SYNOPSIS: Fits list control to fill client area in app window,
making room for toolbar/status bar as appropriate
NOTES: Called in response to WM_SIZE
********************************************************************/
VOID UpdateListControlPlacement(HWND hwndApp,HWND hwndList)
{
RECT rcClient;
UINT yHeight,yStart=0;
// LV_COLUMN lvc;
if (!hwndList) return;
GetClientRect(hwndApp,&rcClient);
yHeight = rcClient.bottom-rcClient.top;
if (ViewInfo.fToolbar) {
yStart = ViewInfo.dyToolbar + 1;
yHeight -= (ViewInfo.dyToolbar + 1);
}
if (ViewInfo.fStatusBar) {
yHeight -= (ViewInfo.dyStatusBar + 1);
}
SetWindowPos(hwndList,NULL,0,yStart,rcClient.right,
yHeight,SWP_NOZORDER);
}
/*******************************************************************
NAME: OnSelection
SYNOPSIS: Selection notification handler for list control in
app window
********************************************************************/
BOOL OnSelection(HWND hwndParent,HWND hwndList,NM_LISTVIEW *pnlv)
{
// if item is selected, make sure "remove" menu item is enabled
if ((pnlv->uNewState & TVIS_SELECTED))
dwAppState |= AS_CANREMOVE;
else dwAppState &= ~AS_CANREMOVE;
// reenable menu items on every selection change, because copy/paste
// menu items depend on how many & which items are selected
EnableMenuItems(hwndParent,dwAppState);
return FALSE;
}
|