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 LocalFree(lpStartup
);
196 HeapFree(ProcessHeap
,
204 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
206 lpServiceConfig
= GetServiceConfig(pService
->lpServiceName
);
209 lvItem
.pszText
= lpServiceConfig
->lpServiceStartName
;
210 SendMessage(Info
->hListView
,
215 HeapFree(ProcessHeap
,
226 RefreshServiceList(PMAIN_WND_INFO Info
)
228 ENUM_SERVICE_STATUS_PROCESS
*pService
;
233 SendMessage (Info
->hListView
,
238 (void)ListView_DeleteAllItems(Info
->hListView
);
240 if (GetServiceList(Info
, &NumServices
))
242 for (Index
= 0; Index
< NumServices
; Index
++)
246 pService
= &Info
->pAllServices
[Index
];
248 /* set the display name */
249 ZeroMemory(&lvItem
, sizeof(LVITEM
));
250 lvItem
.mask
= LVIF_TEXT
| LVIF_PARAM
;
251 lvItem
.pszText
= pService
->lpDisplayName
;
253 /* Add the service pointer */
254 lvItem
.lParam
= (LPARAM
)pService
;
256 /* add it to the listview */
257 lvItem
.iItem
= ListView_InsertItem(Info
->hListView
, &lvItem
);
259 /* fill out all the column data */
260 for (i
= LVDESC
; i
<= LVLOGONAS
; i
++)
262 ChangeListViewText(Info
, pService
, i
);
266 UpdateServiceCount(Info
);
269 /* turn redraw flag on. */
270 SendMessage (Info
->hListView
,
279 InitListViewImage(PMAIN_WND_INFO Info
)
281 HICON hSmIconItem
, hLgIconItem
;
282 HIMAGELIST hSmall
, hLarge
;
284 hSmall
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
),
285 GetSystemMetrics(SM_CYSMICON
),
286 ILC_MASK
| ILC_COLOR32
,
291 hSmIconItem
= LoadImage(hInstance
,
292 MAKEINTRESOURCE(IDI_SM_ICON
),
299 ImageList_AddIcon(hSmall
,
301 (void)ListView_SetImageList(Info
->hListView
,
305 DestroyIcon(hSmIconItem
);
309 hLarge
= ImageList_Create(GetSystemMetrics(SM_CXICON
),
310 GetSystemMetrics(SM_CYICON
),
311 ILC_MASK
| ILC_COLOR32
,
316 hLgIconItem
= LoadImage(hInstance
,
317 MAKEINTRESOURCE(IDI_SM_ICON
),
324 ImageList_AddIcon(hLarge
,
326 (void)ListView_SetImageList(Info
->hListView
,
329 DestroyIcon(hLgIconItem
);
335 CreateListView(PMAIN_WND_INFO Info
)
337 LVCOLUMN lvc
= { 0 };
340 Info
->hListView
= CreateWindowEx(WS_EX_CLIENTEDGE
,
343 WS_CHILD
| WS_VISIBLE
| LVS_REPORT
| WS_BORDER
|
344 LBS_NOTIFY
| LVS_SORTASCENDING
| LBS_NOREDRAW
,
347 (HMENU
) IDC_SERVLIST
,
350 if (Info
->hListView
== NULL
)
352 MessageBox(Info
->hMainWnd
,
353 _T("Could not create List View."),
355 MB_OK
| MB_ICONERROR
);
359 (void)ListView_SetExtendedListViewStyle(Info
->hListView
,
360 LVS_EX_FULLROWSELECT
| LVS_EX_HEADERDRAGDROP
);/*LVS_EX_GRIDLINES |*/
362 lvc
.mask
= LVCF_TEXT
| LVCF_SUBITEM
| LVCF_WIDTH
| LVCF_FMT
;
363 lvc
.fmt
= LVCFMT_LEFT
;
365 /* Add columns to the list-view */
367 lvc
.iSubItem
= LVNAME
;
369 LoadString(hInstance
,
372 sizeof(szTemp
) / sizeof(TCHAR
));
373 lvc
.pszText
= szTemp
;
374 (void)ListView_InsertColumn(Info
->hListView
,
379 lvc
.iSubItem
= LVDESC
;
381 LoadString(hInstance
,
384 sizeof(szTemp
) / sizeof(TCHAR
));
385 lvc
.pszText
= szTemp
;
386 (void)ListView_InsertColumn(Info
->hListView
,
391 lvc
.iSubItem
= LVSTATUS
;
393 LoadString(hInstance
,
396 sizeof(szTemp
) / sizeof(TCHAR
));
397 lvc
.pszText
= szTemp
;
398 (void)ListView_InsertColumn(Info
->hListView
,
403 lvc
.iSubItem
= LVSTARTUP
;
405 LoadString(hInstance
,
408 sizeof(szTemp
) / sizeof(TCHAR
));
409 lvc
.pszText
= szTemp
;
410 (void)ListView_InsertColumn(Info
->hListView
,
415 lvc
.iSubItem
= LVLOGONAS
;
417 LoadString(hInstance
,
420 sizeof(szTemp
) / sizeof(TCHAR
));
421 lvc
.pszText
= szTemp
;
422 (void)ListView_InsertColumn(Info
->hListView
,
426 InitListViewImage(Info
);
428 /* check the details view menu item */
429 CheckMenuRadioItem(GetMenu(Info
->hMainWnd
),