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