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