- list items alphabetically
[reactos.git] / reactos / subsys / system / servman / servman.c
1 /*
2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: subsys/system/servman/servman.c
5 * PURPOSE: Main window message handler
6 * COPYRIGHT: Copyright 2005 Ged Murphy <gedmurphy@gmail.com>
7 *
8 */
9
10 #include "servman.h"
11
12 const TCHAR ClassName[] = _T("ServiceManager");
13
14 HINSTANCE hInstance;
15 HWND hMainWnd;
16 HWND hListView;
17 HWND hStatus;
18
19
20 LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
21 {
22 switch(msg)
23 {
24 case WM_CREATE:
25 {
26 //HFONT hfDefault;
27
28 HWND hTool;
29 TBBUTTON tbb[7];
30 TBADDBITMAP tbab;
31
32 int statwidths[] = {110, -1};
33
34 TCHAR szTemp[256];
35
36 /* Create List View */
37 LVCOLUMN lvc = { 0 };
38 //LVITEM lv = { 0 };
39
40 hListView = CreateWindow(WC_LISTVIEW,
41 NULL,
42 WS_CHILD | WS_VISIBLE | LVS_REPORT | WS_BORDER |
43 LVS_EDITLABELS | LVS_SORTASCENDING,
44 0, 0, 0, 0, /* sized via WM_SIZE */
45 hwnd,
46 (HMENU) IDC_SERVLIST,
47 hInstance,
48 NULL);
49
50 ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT |
51 /*LVS_EX_GRIDLINES |*/ LVS_EX_HEADERDRAGDROP);
52
53 lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_FMT;
54 lvc.fmt = LVCFMT_LEFT;
55
56 /* Add columns to the list-view (first column contains check box). */
57 lvc.iSubItem = 0;
58 lvc.cx = 160;
59 LoadString(hInstance, IDS_FIRSTCOLUMN, szTemp, 256);
60 lvc.pszText = szTemp;
61 ListView_InsertColumn(hListView, 0, &lvc);
62
63 lvc.iSubItem = 1;
64 lvc.cx = 260;
65 LoadString(hInstance, IDS_SECONDCOLUMN, szTemp, 256);
66 lvc.pszText = szTemp;
67 ListView_InsertColumn(hListView, 1, &lvc);
68
69 lvc.iSubItem = 2;
70 lvc.cx = 75;
71 LoadString(hInstance, IDS_THIRDCOLUMN, szTemp, 256);
72 lvc.pszText = szTemp;
73 ListView_InsertColumn(hListView, 2, &lvc);
74
75 lvc.iSubItem = 3;
76 lvc.cx = 80;
77 LoadString(hInstance, IDS_FOURTHCOLUMN, szTemp, 256);
78 lvc.pszText = szTemp;
79 ListView_InsertColumn(hListView, 3, &lvc);
80
81 lvc.iSubItem = 4;
82 lvc.cx = 100;
83 LoadString(hInstance, IDS_FITHCOLUMN, szTemp, 256);
84 lvc.pszText = szTemp;
85 ListView_InsertColumn(hListView, 4, &lvc);
86
87 /* Create Toolbar */
88 hTool = CreateWindowEx(0,
89 TOOLBARCLASSNAME,
90 NULL,
91 WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS,
92 0, 0, 0, 0,
93 hwnd,
94 (HMENU)IDC_TOOLBAR,
95 hInstance,
96 NULL);
97 if(hTool == NULL)
98 MessageBox(hwnd, _T("Could not create tool bar."), _T("Error"), MB_OK | MB_ICONERROR);
99
100 // Send the TB_BUTTONSTRUCTSIZE message, which is required for
101 // backward compatibility.
102 SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
103
104 tbab.hInst = HINST_COMMCTRL;
105 tbab.nID = IDB_STD_SMALL_COLOR;
106 SendMessage(hTool, TB_ADDBITMAP, 0, (LPARAM)&tbab);
107
108 ZeroMemory(tbb, sizeof(tbb));
109 tbb[0].iBitmap = STD_PROPERTIES;
110 tbb[0].fsState = TBSTATE_ENABLED;
111 tbb[0].fsStyle = TBSTYLE_BUTTON;
112 tbb[0].idCommand = ID_PROP;
113 tbb[1].iBitmap = STD_FILENEW;
114 tbb[1].fsState = TBSTATE_ENABLED;
115 tbb[1].fsStyle = TBSTYLE_BUTTON;
116 tbb[1].idCommand = ID_REFRESH;
117 tbb[2].iBitmap = STD_FILENEW;
118 tbb[2].fsState = TBSTATE_ENABLED;
119 tbb[2].fsStyle = TBSTYLE_BUTTON;
120 tbb[2].idCommand = ID_EXPORT;
121 /* seperator */
122 tbb[3].iBitmap = STD_FILENEW;
123 tbb[3].fsState = TBSTATE_ENABLED;
124 tbb[3].fsStyle = TBSTYLE_BUTTON;
125 tbb[3].idCommand = ID_START;
126 tbb[4].iBitmap = STD_FILENEW;
127 tbb[4].fsState = TBSTATE_ENABLED;
128 tbb[4].fsStyle = TBSTYLE_BUTTON;
129 tbb[4].idCommand = ID_STOP;
130 tbb[5].iBitmap = STD_FILENEW;
131 tbb[5].fsState = TBSTATE_ENABLED;
132 tbb[5].fsStyle = TBSTYLE_BUTTON;
133 tbb[5].idCommand = ID_PAUSE;
134 tbb[6].iBitmap = STD_FILENEW;
135 tbb[6].fsState = TBSTATE_ENABLED;
136 tbb[6].fsStyle = TBSTYLE_BUTTON;
137 tbb[6].idCommand = ID_RESTART;
138 SendMessage(hTool, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);
139
140 /* Create Status bar */
141 hStatus = CreateWindowEx(0,
142 STATUSCLASSNAME,
143 NULL,
144 WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
145 0, 0, 0, 0,
146 hwnd,
147 (HMENU)IDC_STATUSBAR,
148 hInstance,
149 NULL);
150 if(hStatus == NULL)
151 MessageBox(hwnd, _T("Could not create status bar."),
152 _T("Error!"), MB_OK | MB_ICONERROR);
153
154 SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
155
156 /* populate the list view with all services */
157 if (! RefreshServiceList() )
158 GetError();
159 }
160 break;
161 case WM_SIZE:
162 {
163 HWND hTool;
164 RECT rcTool;
165 int iToolHeight;
166
167 //HWND hStatus;
168 RECT rcStatus;
169 int iStatusHeight;
170
171 //HWND hListView;
172 int lvHeight;
173 RECT rcClient;
174
175 /* Size toolbar and get height */
176 hTool = GetDlgItem(hwnd, IDC_TOOLBAR);
177 SendMessage(hTool, TB_AUTOSIZE, 0, 0);
178
179 GetWindowRect(hTool, &rcTool);
180 iToolHeight = rcTool.bottom - rcTool.top;
181
182 /* Size status bar and get height */
183 hStatus = GetDlgItem(hwnd, IDC_STATUSBAR);
184 SendMessage(hStatus, WM_SIZE, 0, 0);
185
186 GetWindowRect(hStatus, &rcStatus);
187 iStatusHeight = rcStatus.bottom - rcStatus.top;
188
189 /* Calculate remaining height and size list view */
190 GetClientRect(hwnd, &rcClient);
191
192 lvHeight = rcClient.bottom - iToolHeight - iStatusHeight;
193
194 hListView = GetDlgItem(hwnd, IDC_SERVLIST);
195 SetWindowPos(hListView, NULL, 0, iToolHeight, rcClient.right, lvHeight, SWP_NOZORDER);
196 }
197 break;
198
199 case WM_NOTIFY:
200 {
201 LPNMITEMACTIVATE item;
202
203 switch (((LPNMHDR) lParam)->code)
204 {
205
206 case NM_DBLCLK:
207 item = (LPNMITEMACTIVATE) lParam;
208 PropSheets(hwnd);
209
210 break;
211
212 case TTN_GETDISPINFO:
213 {
214 LPTOOLTIPTEXT lpttt;
215 UINT idButton;
216
217 lpttt = (LPTOOLTIPTEXT) lParam;
218 lpttt->hinst = hInstance;
219
220 // Specify the resource identifier of the descriptive
221 // text for the given button.
222 idButton = lpttt->hdr.idFrom;
223 switch (idButton)
224 {
225 case ID_PROP:
226 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PROP);
227 break;
228
229 case ID_REFRESH:
230 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH);
231 break;
232
233 case ID_EXPORT:
234 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXPORT);
235 break;
236
237 case ID_START:
238 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_START);
239 break;
240
241 case ID_STOP:
242 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_STOP);
243 break;
244
245 case ID_PAUSE:
246 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PAUSE);
247 break;
248
249 case ID_RESTART:
250 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_RESTART);
251 break;
252
253 }
254 }
255 break;
256
257 default:
258 break;
259 }
260 }
261 break;
262
263 case WM_CLOSE:
264 /* free the service array */
265 FreeMemory();
266 DestroyWindow(hwnd);
267 break;
268 case WM_DESTROY:
269 PostQuitMessage(0);
270 break;
271 case WM_COMMAND:
272 switch(LOWORD(wParam))
273 {
274 case ID_FILE_EXIT:
275 PostMessage(hwnd, WM_CLOSE, 0, 0);
276 break;
277
278 case ID_START:
279 break;
280
281 case ID_STOP:
282 break;
283
284 case ID_PAUSE:
285 break;
286
287 case ID_RESUME:
288 break;
289
290 case ID_RESTART:
291 break;
292
293 case ID_REFRESH:
294 break;
295
296 case ID_PROP:
297 PropSheets(hwnd);
298 break;
299
300 case ID_VIEW_CUSTOMIZE:
301 break;
302
303 case ID_HELP_ABOUT:
304 DialogBox(GetModuleHandle(NULL),
305 MAKEINTRESOURCE(IDD_ABOUTBOX),
306 hwnd,
307 AboutDialogProc);
308 break;
309
310 case ID_EXPORT:
311 break;
312
313 }
314 break;
315 default:
316 return DefWindowProc(hwnd, msg, wParam, lParam);
317 }
318 return 0;
319 }
320
321
322
323 int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance,
324 LPSTR lpCmdLine, int nCmdShow)
325 {
326 WNDCLASSEX wc;
327 MSG Msg;
328 BOOL bRet;
329
330 hInstance = hThisInstance;
331
332 InitCommonControls();
333
334 wc.cbSize = sizeof(WNDCLASSEX);
335 wc.style = 0;
336 wc.lpfnWndProc = WndProc;
337 wc.cbClsExtra = 0;
338 wc.cbWndExtra = 0;
339 wc.hInstance = hInstance;
340 wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SM_ICON));
341 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
342 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
343 wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
344 wc.lpszClassName = ClassName;
345 wc.hIconSm = (HICON)LoadImage(hInstance,
346 MAKEINTRESOURCE(IDI_SM_ICON), IMAGE_ICON, 16, 16, 0);
347
348 if(!RegisterClassEx(&wc))
349 {
350 MessageBox(NULL, _T("Window Registration Failed!"), _T("Error!"),
351 MB_ICONEXCLAMATION | MB_OK);
352 return 0;
353 }
354
355 hMainWnd = CreateWindowEx(
356 0,
357 ClassName,
358 _T("ReactOS Service Manager"),
359 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
360 CW_USEDEFAULT, CW_USEDEFAULT, 700, 500,
361 NULL, NULL, hInstance, NULL);
362
363 if(hMainWnd == NULL)
364 {
365 MessageBox(NULL, _T("Window Creation Failed!"), _T("Error!"),
366 MB_ICONEXCLAMATION | MB_OK);
367 return 0;
368 }
369
370 ShowWindow(hMainWnd, nCmdShow);
371 UpdateWindow(hMainWnd);
372
373 while( (bRet = GetMessage( &Msg, NULL, 0, 0 )) != 0)
374 {
375 if (bRet == -1)
376 {
377 /* handle the error and possibly exit */
378 }
379 else
380 {
381 TranslateMessage(&Msg);
382 DispatchMessage(&Msg);
383 }
384 }
385 return Msg.wParam;
386 }
387
388