fix msvc warnings
[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 HWND hTool;
19
20
21 LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
22 {
23 switch(msg)
24 {
25 case WM_CREATE:
26 {
27 //HFONT hfDefault;
28
29 TBADDBITMAP tbab;
30 INT iImageOffset;
31 INT statwidths[] = {110, -1}; /* widths of status bar */
32 TCHAR szTemp[256];
33 LVCOLUMN lvc = { 0 };
34
35 /* Toolbar buttons */
36 TBBUTTON tbb [NUM_BUTTONS] =
37 { /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
38 {TBICON_PROP, ID_PROP, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}, /* properties */
39 {TBICON_REFRESH, ID_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}, /* refresh */
40 {TBICON_EXPORT, ID_EXPORT, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}, /* export */
41
42 /* Note: First item for a seperator is its width in pixels */
43 {25, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0}, /* separator */
44
45 {TBICON_START, ID_START, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* start */
46 {TBICON_STOP, ID_STOP, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* stop */
47 {TBICON_PAUSE, ID_PAUSE, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* pause */
48 {TBICON_RESTART, ID_RESTART, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* restart */
49
50 {25, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0}, /* separator */
51
52 {TBICON_NEW, ID_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* start */
53 {TBICON_HELP, ID_HELP, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* stop */
54 {TBICON_EXIT, ID_EXIT, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }, /* pause */
55
56 };
57
58 /* ======================== Create Toolbar ============================== */
59
60 /* Create Toolbar */
61 hTool = CreateWindowEx(0,
62 TOOLBARCLASSNAME,
63 NULL,
64 WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS,
65 0, 0, 0, 0,
66 hwnd,
67 (HMENU)IDC_TOOLBAR,
68 hInstance,
69 NULL);
70 if(hTool == NULL)
71 MessageBox(hwnd, _T("Could not create tool bar."), _T("Error"), MB_OK | MB_ICONERROR);
72
73 /* Send the TB_BUTTONSTRUCTSIZE message, which is required for backward compatibility */
74 SendMessage(hTool, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
75
76 /* Add standard image list */
77 tbab.hInst = HINST_COMMCTRL;
78 tbab.nID = IDB_STD_SMALL_COLOR;
79 SendMessage(hTool, TB_ADDBITMAP, 0, (LPARAM) &tbab);
80
81 /* Add custom images */
82 tbab.hInst = hInstance;
83 tbab.nID = IDB_BUTTONS;
84 iImageOffset = (INT)SendMessage(hTool, TB_ADDBITMAP, 11, (LPARAM)&tbab);
85 tbb[0].iBitmap += iImageOffset; /* properties */
86 tbb[1].iBitmap += iImageOffset; /* refresh */
87 tbb[2].iBitmap += iImageOffset; /* export */
88 tbb[4].iBitmap += iImageOffset; /* start */
89 tbb[5].iBitmap += iImageOffset; /* stop */
90 tbb[6].iBitmap += iImageOffset; /* pause */
91 tbb[7].iBitmap += iImageOffset; /* restart */
92 tbb[9].iBitmap += iImageOffset; /* new */
93 tbb[10].iBitmap += iImageOffset; /* help */
94 tbb[11].iBitmap += iImageOffset; /* exit */
95
96 /* Add buttons to toolbar */
97 SendMessage(hTool, TB_ADDBUTTONS, NUM_BUTTONS, (LPARAM) &tbb);
98
99 /* Show toolbar */
100 ShowWindow(hTool, SW_SHOWNORMAL);
101
102
103
104 /* ======================== Create List View ============================== */
105
106 hListView = CreateWindow(WC_LISTVIEW,
107 NULL,
108 WS_CHILD | WS_VISIBLE | LVS_REPORT | WS_BORDER |
109 LVS_EDITLABELS | LVS_SORTASCENDING,
110 0, 0, 0, 0, /* sized via WM_SIZE */
111 hwnd,
112 (HMENU) IDC_SERVLIST,
113 hInstance,
114 NULL);
115 if (hListView == NULL)
116 MessageBox(hwnd, _T("Could not create List View."), _T("Error"), MB_OK | MB_ICONERROR);
117
118 ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT |
119 LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP);
120
121 lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_FMT;
122 lvc.fmt = LVCFMT_LEFT;
123
124 /* Add columns to the list-view */
125
126 /* name */
127 lvc.iSubItem = 0;
128 lvc.cx = 160;
129 LoadString(hInstance, IDS_FIRSTCOLUMN, szTemp, 256);
130 lvc.pszText = szTemp;
131 ListView_InsertColumn(hListView, 0, &lvc);
132
133 /* description */
134 lvc.iSubItem = 1;
135 lvc.cx = 260;
136 LoadString(hInstance, IDS_SECONDCOLUMN, szTemp, 256);
137 lvc.pszText = szTemp;
138 ListView_InsertColumn(hListView, 1, &lvc);
139
140 /* status */
141 lvc.iSubItem = 2;
142 lvc.cx = 75;
143 LoadString(hInstance, IDS_THIRDCOLUMN, szTemp, 256);
144 lvc.pszText = szTemp;
145 ListView_InsertColumn(hListView, 2, &lvc);
146
147 /* startup type */
148 lvc.iSubItem = 3;
149 lvc.cx = 80;
150 LoadString(hInstance, IDS_FOURTHCOLUMN, szTemp, 256);
151 lvc.pszText = szTemp;
152 ListView_InsertColumn(hListView, 3, &lvc);
153
154 /* logon as */
155 lvc.iSubItem = 4;
156 lvc.cx = 100;
157 LoadString(hInstance, IDS_FITHCOLUMN, szTemp, 256);
158 lvc.pszText = szTemp;
159 ListView_InsertColumn(hListView, 4, &lvc);
160
161
162
163 /* ======================== Create Status Bar ============================== */
164
165 hStatus = CreateWindowEx(0,
166 STATUSCLASSNAME,
167 NULL,
168 WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
169 0, 0, 0, 0,
170 hwnd,
171 (HMENU)IDC_STATUSBAR,
172 hInstance,
173 NULL);
174 if(hStatus == NULL)
175 MessageBox(hwnd, _T("Could not create status bar."),
176 _T("Error!"), MB_OK | MB_ICONERROR);
177
178 SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
179
180
181 /* ================= populate the list view with all services =================== */
182
183 if (! RefreshServiceList() )
184 GetError();
185
186 }
187 break;
188
189 case WM_SIZE:
190 {
191 RECT rcTool;
192 int iToolHeight;
193
194 RECT rcStatus;
195 int iStatusHeight;
196
197 int lvHeight;
198 RECT rcClient;
199
200 /* Size toolbar and get height */
201 hTool = GetDlgItem(hwnd, IDC_TOOLBAR);
202 SendMessage(hTool, TB_AUTOSIZE, 0, 0);
203
204 GetWindowRect(hTool, &rcTool);
205 iToolHeight = rcTool.bottom - rcTool.top;
206
207 /* Size status bar and get height */
208 hStatus = GetDlgItem(hwnd, IDC_STATUSBAR);
209 SendMessage(hStatus, WM_SIZE, 0, 0);
210
211 GetWindowRect(hStatus, &rcStatus);
212 iStatusHeight = rcStatus.bottom - rcStatus.top;
213
214 /* Calculate remaining height and size list view */
215 GetClientRect(hwnd, &rcClient);
216
217 lvHeight = rcClient.bottom - iToolHeight - iStatusHeight;
218
219 hListView = GetDlgItem(hwnd, IDC_SERVLIST);
220 SetWindowPos(hListView, NULL, 0, iToolHeight, rcClient.right, lvHeight, SWP_NOZORDER);
221 }
222 break;
223
224 case WM_NOTIFY:
225 {
226 LPNMITEMACTIVATE item;
227
228 switch (((LPNMHDR) lParam)->code)
229 {
230
231 case NM_DBLCLK:
232 item = (LPNMITEMACTIVATE) lParam;
233 PropSheets(hwnd);
234
235 break;
236
237 case TTN_GETDISPINFO:
238 {
239 LPTOOLTIPTEXT lpttt;
240 UINT idButton;
241
242 lpttt = (LPTOOLTIPTEXT) lParam;
243 lpttt->hinst = hInstance;
244
245 // Specify the resource identifier of the descriptive
246 // text for the given button.
247 idButton = (UINT)lpttt->hdr.idFrom;
248 switch (idButton)
249 {
250 case ID_PROP:
251 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PROP);
252 break;
253
254 case ID_REFRESH:
255 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH);
256 break;
257
258 case ID_EXPORT:
259 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXPORT);
260 break;
261
262 case ID_START:
263 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_START);
264 break;
265
266 case ID_STOP:
267 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_STOP);
268 break;
269
270 case ID_PAUSE:
271 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PAUSE);
272 break;
273
274 case ID_RESTART:
275 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_RESTART);
276 break;
277
278 case ID_NEW:
279 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_NEW);
280 break;
281
282 case ID_HELP:
283 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_HELP);
284 break;
285
286 case ID_EXIT:
287 lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXIT);
288 break;
289
290 }
291 }
292 break;
293
294 default:
295 break;
296 }
297 }
298 break;
299
300 case WM_CLOSE:
301 /* free the service array */
302 FreeMemory();
303 DestroyWindow(hwnd);
304 break;
305
306 case WM_DESTROY:
307 PostQuitMessage(0);
308 break;
309
310 case WM_COMMAND:
311 switch(LOWORD(wParam))
312 {
313 case ID_PROP:
314 PropSheets(hwnd);
315 break;
316
317 case ID_REFRESH:
318 if (! RefreshServiceList() )
319 GetError();
320
321 case ID_EXPORT:
322 break;
323
324 case ID_START:
325 break;
326
327 case ID_STOP:
328 break;
329
330 case ID_PAUSE:
331 break;
332
333 case ID_RESUME:
334 break;
335
336 case ID_RESTART:
337 break;
338
339 case ID_NEW:
340 break;
341
342 case ID_HELP:
343 MessageBox(NULL, _T("Help is not yet implemented\n"),
344 _T("Note!"), MB_OK | MB_ICONINFORMATION);
345 break;
346
347 case ID_EXIT:
348 PostMessage(hwnd, WM_CLOSE, 0, 0);
349 break;
350
351 case ID_VIEW_CUSTOMIZE:
352 break;
353
354 case ID_HELP_ABOUT:
355 DialogBox(hInstance,
356 MAKEINTRESOURCE(IDD_ABOUTBOX),
357 hwnd,
358 AboutDialogProc);
359 break;
360
361 }
362 break;
363
364 default:
365 return DefWindowProc(hwnd, msg, wParam, lParam);
366 }
367 return 0;
368 }
369
370 #ifdef _MSC_VER
371 #pragma warning(disable : 4100)
372 #endif
373 int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance,
374 LPSTR lpCmdLine, int nCmdShow)
375 {
376 WNDCLASSEX wc;
377 MSG Msg;
378 BOOL bRet;
379
380 hInstance = hThisInstance;
381
382 InitCommonControls();
383
384 wc.cbSize = sizeof(WNDCLASSEX);
385 wc.style = 0;
386 wc.lpfnWndProc = WndProc;
387 wc.cbClsExtra = 0;
388 wc.cbWndExtra = 0;
389 wc.hInstance = hInstance;
390 wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SM_ICON));
391 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
392 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
393 wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
394 wc.lpszClassName = ClassName;
395 wc.hIconSm = (HICON)LoadImage(hInstance,
396 MAKEINTRESOURCE(IDI_SM_ICON), IMAGE_ICON, 16, 16, 0);
397
398 if(!RegisterClassEx(&wc))
399 {
400 MessageBox(NULL, _T("Window Registration Failed!"), _T("Error!"),
401 MB_ICONEXCLAMATION | MB_OK);
402 return 0;
403 }
404
405 hMainWnd = CreateWindowEx(
406 0,
407 ClassName,
408 _T("ReactOS Service Manager"),
409 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
410 CW_USEDEFAULT, CW_USEDEFAULT, 700, 500,
411 NULL, NULL, hInstance, NULL);
412
413 if(hMainWnd == NULL)
414 {
415 MessageBox(NULL, _T("Window Creation Failed!"), _T("Error!"),
416 MB_ICONEXCLAMATION | MB_OK);
417 return 0;
418 }
419
420 ShowWindow(hMainWnd, nCmdShow);
421 UpdateWindow(hMainWnd);
422
423 while( (bRet = GetMessage( &Msg, NULL, 0, 0 )) != 0)
424 {
425 if (bRet == -1)
426 {
427 /* handle the error and possibly exit */
428 }
429 else
430 {
431 TranslateMessage(&Msg);
432 DispatchMessage(&Msg);
433 }
434 }
435 return (int)Msg.wParam;
436 }
437
438