2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/listview.c
5 * PURPOSE: service listview manipulation functions
6 * COPYRIGHT: Copyright 2006-2007 Ged Murphy <gedmurphy@reactos.org>
13 SetListViewStyle(HWND hListView
,
16 DWORD Style
= GetWindowLongPtr(hListView
, GWL_STYLE
);
18 if ((Style
& LVS_TYPEMASK
) != View
)
20 SetWindowLongPtr(hListView
,
22 (Style
& ~LVS_TYPEMASK
) | View
);
27 ListViewSelectionChanged(PMAIN_WND_INFO Info
,
32 /* get handle to menu */
33 hMainMenu
= GetMenu(Info
->hMainWnd
);
35 /* activate properties menu item, if not already */
36 if (GetMenuState(hMainMenu
,
38 MF_BYCOMMAND
) != MF_ENABLED
)
40 EnableMenuItem(hMainMenu
,
43 EnableMenuItem(GetSubMenu(Info
->hShortcutMenu
, 0),
46 SetMenuDefaultItem(GetSubMenu(Info
->hShortcutMenu
, 0),
51 /* activate delete menu item, if not already */
52 if (GetMenuState(hMainMenu
,
54 MF_BYCOMMAND
) != MF_ENABLED
)
56 EnableMenuItem(hMainMenu
,
59 EnableMenuItem(GetSubMenu(Info
->hShortcutMenu
, 0),
64 /* set selected service */
65 Info
->SelectedItem
= pnmv
->iItem
;
67 /* get pointer to selected service */
68 Info
->pCurrentService
= GetSelectedService(Info
);
70 /* set current selected service in the status bar */
71 SendMessage(Info
->hStatus
,
74 (LPARAM
)Info
->pCurrentService
->lpDisplayName
);
76 /* show the properties button */
77 SendMessage(Info
->hTool
,
80 (LPARAM
)MAKELONG(TBSTATE_ENABLED
, 0));
84 ChangeListViewText(PMAIN_WND_INFO Info
,
85 ENUM_SERVICE_STATUS_PROCESS
* pService
,
92 lvfi
.flags
= LVFI_PARAM
;
93 lvfi
.lParam
= (LPARAM
)pService
;
94 index
= ListView_FindItem(Info
->hListView
,
100 lvItem
.iSubItem
= Column
;
106 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
108 lpServiceConfig
= GetServiceConfig(pService
->lpServiceName
);
111 lvItem
.pszText
= lpServiceConfig
->lpDisplayName
;
112 SendMessage(Info
->hListView
,
117 HeapFree(ProcessHeap
,
126 LPTSTR lpDescription
;
128 lpDescription
= GetServiceDescription(pService
->lpServiceName
);
130 lvItem
.pszText
= lpDescription
;
131 SendMessage(Info
->hListView
,
136 HeapFree(ProcessHeap
,
146 if (pService
->ServiceStatusProcess
.dwCurrentState
== SERVICE_RUNNING
)
148 LoadString(hInstance
,
149 IDS_SERVICES_STARTED
,
151 sizeof(szStatus
) / sizeof(TCHAR
));
158 lvItem
.pszText
= szStatus
;
159 SendMessage(Info
->hListView
,
168 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
169 LPTSTR lpStartup
= NULL
;
172 lpServiceConfig
= GetServiceConfig(pService
->lpServiceName
);
176 switch (lpServiceConfig
->dwStartType
)
178 case 2: StringId
= IDS_SERVICES_AUTO
; break;
179 case 3: StringId
= IDS_SERVICES_MAN
; break;
180 case 4: StringId
= IDS_SERVICES_DIS
; break;
185 AllocAndLoadString(&lpStartup
,
189 lvItem
.pszText
= lpStartup
;
190 SendMessage(Info
->hListView
,
195 HeapFree(ProcessHeap
,
198 HeapFree(ProcessHeap
,
206 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
208 lpServiceConfig
= GetServiceConfig(pService
->lpServiceName
);
211 lvItem
.pszText
= lpServiceConfig
->lpServiceStartName
;
212 SendMessage(Info
->hListView
,
217 HeapFree(ProcessHeap
,
228 RefreshServiceList(PMAIN_WND_INFO Info
)
230 ENUM_SERVICE_STATUS_PROCESS
*pService
;
235 SendMessage (Info
->hListView
,
240 (void)ListView_DeleteAllItems(Info
->hListView
);
242 if (GetServiceList(Info
, &NumServices
))
244 for (Index
= 0; Index
< NumServices
; Index
++)
248 pService
= &Info
->pAllServices
[Index
];
250 /* set the display name */
251 ZeroMemory(&lvItem
, sizeof(LVITEM
));
252 lvItem
.mask
= LVIF_TEXT
| LVIF_PARAM
;
253 lvItem
.pszText
= pService
->lpDisplayName
;
255 /* Add the service pointer */
256 lvItem
.lParam
= (LPARAM
)pService
;
258 /* add it to the listview */
259 lvItem
.iItem
= ListView_InsertItem(Info
->hListView
, &lvItem
);
261 /* fill out all the column data */
262 for (i
= LVDESC
; i
<= LVLOGONAS
; i
++)
264 ChangeListViewText(Info
, pService
, i
);
268 UpdateServiceCount(Info
);
271 /* turn redraw flag on. */
272 SendMessage (Info
->hListView
,
281 InitListViewImage(PMAIN_WND_INFO Info
)
283 HICON hSmIconItem
, hLgIconItem
;
284 HIMAGELIST hSmall
, hLarge
;
286 hSmall
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
),
287 GetSystemMetrics(SM_CYSMICON
),
288 ILC_MASK
| ILC_COLOR32
,
293 hSmIconItem
= LoadImage(hInstance
,
294 MAKEINTRESOURCE(IDI_SM_ICON
),
301 ImageList_AddIcon(hSmall
,
303 (void)ListView_SetImageList(Info
->hListView
,
307 DestroyIcon(hSmIconItem
);
311 hLarge
= ImageList_Create(GetSystemMetrics(SM_CXICON
),
312 GetSystemMetrics(SM_CYICON
),
313 ILC_MASK
| ILC_COLOR32
,
318 hLgIconItem
= LoadImage(hInstance
,
319 MAKEINTRESOURCE(IDI_SM_ICON
),
326 ImageList_AddIcon(hLarge
,
328 (void)ListView_SetImageList(Info
->hListView
,
331 DestroyIcon(hLgIconItem
);
337 CreateListView(PMAIN_WND_INFO Info
)
339 LVCOLUMN lvc
= { 0 };
342 Info
->hListView
= CreateWindowEx(WS_EX_CLIENTEDGE
,
345 WS_CHILD
| WS_VISIBLE
| LVS_REPORT
| WS_BORDER
|
346 LBS_NOTIFY
| LVS_SORTASCENDING
| LBS_NOREDRAW
,
349 (HMENU
) IDC_SERVLIST
,
352 if (Info
->hListView
== NULL
)
354 MessageBox(Info
->hMainWnd
,
355 _T("Could not create List View."),
357 MB_OK
| MB_ICONERROR
);
361 (void)ListView_SetExtendedListViewStyle(Info
->hListView
,
362 LVS_EX_FULLROWSELECT
| LVS_EX_HEADERDRAGDROP
);/*LVS_EX_GRIDLINES |*/
364 lvc
.mask
= LVCF_TEXT
| LVCF_SUBITEM
| LVCF_WIDTH
| LVCF_FMT
;
365 lvc
.fmt
= LVCFMT_LEFT
;
367 /* Add columns to the list-view */
369 lvc
.iSubItem
= LVNAME
;
371 LoadString(hInstance
,
374 sizeof(szTemp
) / sizeof(TCHAR
));
375 lvc
.pszText
= szTemp
;
376 (void)ListView_InsertColumn(Info
->hListView
,
381 lvc
.iSubItem
= LVDESC
;
383 LoadString(hInstance
,
386 sizeof(szTemp
) / sizeof(TCHAR
));
387 lvc
.pszText
= szTemp
;
388 (void)ListView_InsertColumn(Info
->hListView
,
393 lvc
.iSubItem
= LVSTATUS
;
395 LoadString(hInstance
,
398 sizeof(szTemp
) / sizeof(TCHAR
));
399 lvc
.pszText
= szTemp
;
400 (void)ListView_InsertColumn(Info
->hListView
,
405 lvc
.iSubItem
= LVSTARTUP
;
407 LoadString(hInstance
,
410 sizeof(szTemp
) / sizeof(TCHAR
));
411 lvc
.pszText
= szTemp
;
412 (void)ListView_InsertColumn(Info
->hListView
,
417 lvc
.iSubItem
= LVLOGONAS
;
419 LoadString(hInstance
,
422 sizeof(szTemp
) / sizeof(TCHAR
));
423 lvc
.pszText
= szTemp
;
424 (void)ListView_InsertColumn(Info
->hListView
,
428 InitListViewImage(Info
);
430 /* check the details view menu item */
431 CheckMenuRadioItem(GetMenu(Info
->hMainWnd
),