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
= GetWindowLongPtr(hListView
, GWL_STYLE
);
19 if ((Style
& LVS_TYPEMASK
) != View
)
21 SetWindowLongPtr(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
);
179 switch (lpServiceConfig
->dwStartType
)
181 case 2: StringId
= IDS_SERVICES_AUTO
; break;
182 case 3: StringId
= IDS_SERVICES_MAN
; break;
183 case 4: StringId
= IDS_SERVICES_DIS
; break;
188 AllocAndLoadString(&lpStartup
,
192 lvItem
.pszText
= lpStartup
;
193 SendMessage(Info
->hListView
,
198 HeapFree(ProcessHeap
,
201 HeapFree(ProcessHeap
,
209 LPQUERY_SERVICE_CONFIG lpServiceConfig
;
211 lpServiceConfig
= GetServiceConfig(pService
->lpServiceName
);
214 lvItem
.pszText
= lpServiceConfig
->lpServiceStartName
;
215 SendMessage(Info
->hListView
,
220 HeapFree(ProcessHeap
,
232 RefreshServiceList(PMAIN_WND_INFO Info
)
234 ENUM_SERVICE_STATUS_PROCESS
*pService
;
239 SendMessage (Info
->hListView
,
244 (void)ListView_DeleteAllItems(Info
->hListView
);
246 if (GetServiceList(Info
, &NumServices
))
248 for (Index
= 0; Index
< NumServices
; Index
++)
252 pService
= &Info
->pAllServices
[Index
];
254 /* set the display name */
255 ZeroMemory(&lvItem
, sizeof(LVITEM
));
256 lvItem
.mask
= LVIF_TEXT
| LVIF_PARAM
;
257 lvItem
.pszText
= pService
->lpDisplayName
;
259 /* Add the service pointer */
260 lvItem
.lParam
= (LPARAM
)pService
;
262 /* add it to the listview */
263 lvItem
.iItem
= ListView_InsertItem(Info
->hListView
, &lvItem
);
265 /* fill out all the column data */
266 for (i
= LVDESC
; i
<= LVLOGONAS
; i
++)
268 ChangeListViewText(Info
, pService
, i
);
272 UpdateServiceCount(Info
);
275 /* turn redraw flag on. */
276 SendMessage (Info
->hListView
,
286 InitListViewImage(PMAIN_WND_INFO Info
)
288 HICON hSmIconItem
, hLgIconItem
;
289 HIMAGELIST hSmall
, hLarge
;
291 hSmall
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
),
292 GetSystemMetrics(SM_CYSMICON
),
293 ILC_MASK
| ILC_COLOR32
,
298 hSmIconItem
= LoadImage(hInstance
,
299 MAKEINTRESOURCE(IDI_SM_ICON
),
306 ImageList_AddIcon(hSmall
,
308 (void)ListView_SetImageList(Info
->hListView
,
312 DestroyIcon(hSmIconItem
);
316 hLarge
= ImageList_Create(GetSystemMetrics(SM_CXICON
),
317 GetSystemMetrics(SM_CYICON
),
318 ILC_MASK
| ILC_COLOR32
,
323 hLgIconItem
= LoadImage(hInstance
,
324 MAKEINTRESOURCE(IDI_SM_ICON
),
331 ImageList_AddIcon(hLarge
,
333 (void)ListView_SetImageList(Info
->hListView
,
336 DestroyIcon(hLgIconItem
);
343 CreateListView(PMAIN_WND_INFO Info
)
345 LVCOLUMN lvc
= { 0 };
348 Info
->hListView
= CreateWindowEx(WS_EX_CLIENTEDGE
,
351 WS_CHILD
| WS_VISIBLE
| LVS_REPORT
| WS_BORDER
|
352 LBS_NOTIFY
| LVS_SORTASCENDING
| LBS_NOREDRAW
,
355 (HMENU
) IDC_SERVLIST
,
358 if (Info
->hListView
== NULL
)
360 MessageBox(Info
->hMainWnd
,
361 _T("Could not create List View."),
363 MB_OK
| MB_ICONERROR
);
367 (void)ListView_SetExtendedListViewStyle(Info
->hListView
,
368 LVS_EX_FULLROWSELECT
| LVS_EX_HEADERDRAGDROP
);/*LVS_EX_GRIDLINES |*/
370 lvc
.mask
= LVCF_TEXT
| LVCF_SUBITEM
| LVCF_WIDTH
| LVCF_FMT
;
371 lvc
.fmt
= LVCFMT_LEFT
;
373 /* Add columns to the list-view */
375 lvc
.iSubItem
= LVNAME
;
377 LoadString(hInstance
,
380 sizeof(szTemp
) / sizeof(TCHAR
));
381 lvc
.pszText
= szTemp
;
382 (void)ListView_InsertColumn(Info
->hListView
,
387 lvc
.iSubItem
= LVDESC
;
389 LoadString(hInstance
,
392 sizeof(szTemp
) / sizeof(TCHAR
));
393 lvc
.pszText
= szTemp
;
394 (void)ListView_InsertColumn(Info
->hListView
,
399 lvc
.iSubItem
= LVSTATUS
;
401 LoadString(hInstance
,
404 sizeof(szTemp
) / sizeof(TCHAR
));
405 lvc
.pszText
= szTemp
;
406 (void)ListView_InsertColumn(Info
->hListView
,
411 lvc
.iSubItem
= LVSTARTUP
;
413 LoadString(hInstance
,
416 sizeof(szTemp
) / sizeof(TCHAR
));
417 lvc
.pszText
= szTemp
;
418 (void)ListView_InsertColumn(Info
->hListView
,
423 lvc
.iSubItem
= LVLOGONAS
;
425 LoadString(hInstance
,
428 sizeof(szTemp
) / sizeof(TCHAR
));
429 lvc
.pszText
= szTemp
;
430 (void)ListView_InsertColumn(Info
->hListView
,
434 InitListViewImage(Info
);
436 /* check the details view menu item */
437 CheckMenuRadioItem(GetMenu(Info
->hMainWnd
),