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>
14 SetListViewStyle(HWND hListView
,
17 DWORD Style
= GetWindowLong(hListView
, GWL_STYLE
);
19 if ((Style
& LVS_TYPEMASK
) != View
)
21 SetWindowLong(hListView
,
23 (Style
& ~LVS_TYPEMASK
) | View
);
29 ListViewSelectionChanged(PMAIN_WND_INFO Info
,
34 /* get handle to menu */
35 hMainMenu
= GetMenu(Info
->hMainWnd
);
37 /* activate properties menu item, if not already */
38 if (GetMenuState(hMainMenu
,
40 MF_BYCOMMAND
) != MF_ENABLED
)
42 EnableMenuItem(hMainMenu
,
45 EnableMenuItem(GetSubMenu(Info
->hShortcutMenu
, 0),
48 SetMenuDefaultItem(GetSubMenu(Info
->hShortcutMenu
, 0),
53 /* activate delete menu item, if not already */
54 if (GetMenuState(hMainMenu
,
56 MF_BYCOMMAND
) != MF_ENABLED
)
58 EnableMenuItem(hMainMenu
,
61 EnableMenuItem(GetSubMenu(Info
->hShortcutMenu
, 0),
66 /* set selected service */
67 Info
->SelectedItem
= pnmv
->iItem
;
69 /* get pointer to selected service */
70 Info
->pCurrentService
= GetSelectedService(Info
);
72 /* set current selected service in the status bar */
73 SendMessage(Info
->hStatus
,
76 (LPARAM
)Info
->pCurrentService
->lpDisplayName
);
78 /* show the properties button */
79 SendMessage(Info
->hTool
,
82 (LPARAM
)MAKELONG(TBSTATE_ENABLED
, 0));
87 ChangeListViewText(PMAIN_WND_INFO Info
,
88 ENUM_SERVICE_STATUS_PROCESS
* pService
,
95 lvfi
.flags
= LVFI_PARAM
;
96 lvfi
.lParam
= (LPARAM
)pService
;
97 index
= ListView_FindItem(Info
->hListView
,
102 lvItem
.iItem
= index
;
103 lvItem
.iSubItem
= Column
;
109 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
111 lpServiceConfig
= GetServiceConfig(pService
->lpServiceName
);
114 lvItem
.pszText
= lpServiceConfig
->lpDisplayName
;
115 SendMessage(Info
->hListView
,
120 HeapFree(ProcessHeap
,
129 LPTSTR lpDescription
;
131 lpDescription
= GetServiceDescription(pService
->lpServiceName
);
133 lvItem
.pszText
= lpDescription
;
134 SendMessage(Info
->hListView
,
139 HeapFree(ProcessHeap
,
149 if (pService
->ServiceStatusProcess
.dwCurrentState
== SERVICE_RUNNING
)
151 LoadString(hInstance
,
152 IDS_SERVICES_STARTED
,
154 sizeof(szStatus
) / sizeof(TCHAR
));
161 lvItem
.pszText
= szStatus
;
162 SendMessage(Info
->hListView
,
171 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
172 LPTSTR lpStartup
= NULL
;
175 lpServiceConfig
= GetServiceConfig(pService
->lpServiceName
);
177 switch (lpServiceConfig
->dwStartType
)
179 case 2: StringId
= IDS_SERVICES_AUTO
; break;
180 case 3: StringId
= IDS_SERVICES_MAN
; break;
181 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
,
229 RefreshServiceList(PMAIN_WND_INFO Info
)
231 ENUM_SERVICE_STATUS_PROCESS
*pService
;
236 SendMessage (Info
->hListView
,
241 (void)ListView_DeleteAllItems(Info
->hListView
);
243 if (GetServiceList(Info
, &NumServices
))
245 for (Index
= 0; Index
< NumServices
; Index
++)
249 pService
= &Info
->pAllServices
[Index
];
251 /* set the display name */
252 ZeroMemory(&lvItem
, sizeof(LVITEM
));
253 lvItem
.mask
= LVIF_TEXT
| LVIF_PARAM
;
254 lvItem
.pszText
= pService
->lpDisplayName
;
256 /* Add the service pointer */
257 lvItem
.lParam
= (LPARAM
)pService
;
259 /* add it to the listview */
260 lvItem
.iItem
= ListView_InsertItem(Info
->hListView
, &lvItem
);
262 /* fill out all the column data */
263 for (i
= LVDESC
; i
<= LVLOGONAS
; i
++)
265 ChangeListViewText(Info
, pService
, i
);
269 UpdateServiceCount(Info
);
272 /* turn redraw flag on. */
273 SendMessage (Info
->hListView
,
283 InitListViewImage(PMAIN_WND_INFO Info
)
285 HICON hSmIconItem
, hLgIconItem
;
286 HIMAGELIST hSmall
, hLarge
;
288 hSmall
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
),
289 GetSystemMetrics(SM_CYSMICON
),
290 ILC_MASK
| ILC_COLOR32
,
295 hSmIconItem
= LoadImage(hInstance
,
296 MAKEINTRESOURCE(IDI_SM_ICON
),
303 ImageList_AddIcon(hSmall
,
305 (void)ListView_SetImageList(Info
->hListView
,
309 DestroyIcon(hSmIconItem
);
313 hLarge
= ImageList_Create(GetSystemMetrics(SM_CXICON
),
314 GetSystemMetrics(SM_CYICON
),
315 ILC_MASK
| ILC_COLOR32
,
320 hLgIconItem
= LoadImage(hInstance
,
321 MAKEINTRESOURCE(IDI_SM_ICON
),
328 ImageList_AddIcon(hLarge
,
330 (void)ListView_SetImageList(Info
->hListView
,
333 DestroyIcon(hLgIconItem
);
340 CreateListView(PMAIN_WND_INFO Info
)
342 LVCOLUMN lvc
= { 0 };
345 Info
->hListView
= CreateWindowEx(WS_EX_CLIENTEDGE
,
348 WS_CHILD
| WS_VISIBLE
| LVS_REPORT
| WS_BORDER
|
349 LBS_NOTIFY
| LVS_SORTASCENDING
| LBS_NOREDRAW
,
352 (HMENU
) IDC_SERVLIST
,
355 if (Info
->hListView
== NULL
)
357 MessageBox(Info
->hMainWnd
,
358 _T("Could not create List View."),
360 MB_OK
| MB_ICONERROR
);
364 (void)ListView_SetExtendedListViewStyle(Info
->hListView
,
365 LVS_EX_FULLROWSELECT
| LVS_EX_HEADERDRAGDROP
);/*LVS_EX_GRIDLINES |*/
367 lvc
.mask
= LVCF_TEXT
| LVCF_SUBITEM
| LVCF_WIDTH
| LVCF_FMT
;
368 lvc
.fmt
= LVCFMT_LEFT
;
370 /* Add columns to the list-view */
372 lvc
.iSubItem
= LVNAME
;
374 LoadString(hInstance
,
377 sizeof(szTemp
) / sizeof(TCHAR
));
378 lvc
.pszText
= szTemp
;
379 (void)ListView_InsertColumn(Info
->hListView
,
384 lvc
.iSubItem
= LVDESC
;
386 LoadString(hInstance
,
389 sizeof(szTemp
) / sizeof(TCHAR
));
390 lvc
.pszText
= szTemp
;
391 (void)ListView_InsertColumn(Info
->hListView
,
396 lvc
.iSubItem
= LVSTATUS
;
398 LoadString(hInstance
,
401 sizeof(szTemp
) / sizeof(TCHAR
));
402 lvc
.pszText
= szTemp
;
403 (void)ListView_InsertColumn(Info
->hListView
,
408 lvc
.iSubItem
= LVSTARTUP
;
410 LoadString(hInstance
,
413 sizeof(szTemp
) / sizeof(TCHAR
));
414 lvc
.pszText
= szTemp
;
415 (void)ListView_InsertColumn(Info
->hListView
,
420 lvc
.iSubItem
= LVLOGONAS
;
422 LoadString(hInstance
,
425 sizeof(szTemp
) / sizeof(TCHAR
));
426 lvc
.pszText
= szTemp
;
427 (void)ListView_InsertColumn(Info
->hListView
,
431 InitListViewImage(Info
);
433 /* check the details view menu item */
434 CheckMenuRadioItem(GetMenu(Info
->hMainWnd
),