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 - 2006 Ged Murphy <gedmurphy@gmail.com>
12 const TCHAR ClassName
[] = _T("ServiceManager");
24 INT
GetSelectedItem(VOID
)
30 LRESULT CALLBACK
WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
38 INT statwidths
[] = {110, -1}; /* widths of status bar */
43 TBBUTTON tbb
[NUM_BUTTONS
] =
44 { /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
45 {TBICON_PROP
, ID_PROP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0}, /* properties */
46 {TBICON_REFRESH
, ID_REFRESH
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0}, /* refresh */
47 {TBICON_EXPORT
, ID_EXPORT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0}, /* export */
49 /* Note: First item for a seperator is its width in pixels */
50 {15, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0}, 0, 0}, /* separator */
52 {TBICON_NEW
, ID_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* create */
54 {15, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0}, 0, 0}, /* separator */
56 {TBICON_START
, ID_START
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* start */
57 {TBICON_STOP
, ID_STOP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* stop */
58 {TBICON_PAUSE
, ID_PAUSE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* pause */
59 {TBICON_RESTART
, ID_RESTART
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* restart */
61 {15, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0}, 0, 0}, /* separator */
63 {TBICON_HELP
, ID_HELP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* help */
64 {TBICON_EXIT
, ID_EXIT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* exit */
68 /* ======================== Create Toolbar ============================== */
71 hTool
= CreateWindowEx(0,
74 WS_CHILD
| WS_VISIBLE
| TBSTYLE_FLAT
| TBSTYLE_TOOLTIPS
,
81 MessageBox(hwnd
, _T("Could not create tool bar."), _T("Error"), MB_OK
| MB_ICONERROR
);
83 /* Send the TB_BUTTONSTRUCTSIZE message, which is required for backward compatibility */
84 SendMessage(hTool
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
86 /* Add custom images */
87 tbab
.hInst
= hInstance
;
88 tbab
.nID
= IDB_BUTTONS
;
89 iImageOffset
= (INT
)SendMessage(hTool
, TB_ADDBITMAP
, NUM_BUTTONS
, (LPARAM
)&tbab
);
90 tbb
[0].iBitmap
+= iImageOffset
; /* properties */
91 tbb
[1].iBitmap
+= iImageOffset
; /* refresh */
92 tbb
[2].iBitmap
+= iImageOffset
; /* export */
93 tbb
[4].iBitmap
+= iImageOffset
; /* new */
94 tbb
[6].iBitmap
+= iImageOffset
; /* start */
95 tbb
[7].iBitmap
+= iImageOffset
; /* stop */
96 tbb
[8].iBitmap
+= iImageOffset
; /* pause */
97 tbb
[9].iBitmap
+= iImageOffset
; /* restart */
98 tbb
[11].iBitmap
+= iImageOffset
; /* help */
99 tbb
[12].iBitmap
+= iImageOffset
; /* exit */
101 /* Add buttons to toolbar */
102 SendMessage(hTool
, TB_ADDBUTTONS
, NUM_BUTTONS
, (LPARAM
) &tbb
);
105 ShowWindow(hTool
, SW_SHOWNORMAL
);
109 /* ======================== Create List View ============================== */
111 hListView
= CreateWindowEx(0,
114 WS_CHILD
| WS_VISIBLE
| LVS_REPORT
| WS_BORDER
|
115 LBS_NOTIFY
| LVS_SORTASCENDING
| LBS_NOREDRAW
,
116 0, 0, 0, 0, /* sized via WM_SIZE */
118 (HMENU
) IDC_SERVLIST
,
121 if (hListView
== NULL
)
122 MessageBox(hwnd
, _T("Could not create List View."), _T("Error"), MB_OK
| MB_ICONERROR
);
124 ListView_SetExtendedListViewStyle(hListView
, LVS_EX_FULLROWSELECT
|
125 LVS_EX_GRIDLINES
| LVS_EX_HEADERDRAGDROP
);
127 lvc
.mask
= LVCF_TEXT
| LVCF_SUBITEM
| LVCF_WIDTH
| LVCF_FMT
;
128 lvc
.fmt
= LVCFMT_LEFT
;
130 /* Add columns to the list-view */
135 LoadString(hInstance
, IDS_FIRSTCOLUMN
, szTemp
, 256);
136 lvc
.pszText
= szTemp
;
137 ListView_InsertColumn(hListView
, 0, &lvc
);
142 LoadString(hInstance
, IDS_SECONDCOLUMN
, szTemp
, 256);
143 lvc
.pszText
= szTemp
;
144 ListView_InsertColumn(hListView
, 1, &lvc
);
149 LoadString(hInstance
, IDS_THIRDCOLUMN
, szTemp
, 256);
150 lvc
.pszText
= szTemp
;
151 ListView_InsertColumn(hListView
, 2, &lvc
);
156 LoadString(hInstance
, IDS_FOURTHCOLUMN
, szTemp
, 256);
157 lvc
.pszText
= szTemp
;
158 ListView_InsertColumn(hListView
, 3, &lvc
);
163 LoadString(hInstance
, IDS_FITHCOLUMN
, szTemp
, 256);
164 lvc
.pszText
= szTemp
;
165 ListView_InsertColumn(hListView
, 4, &lvc
);
169 /* ======================== Create Status Bar ============================== */
171 hStatus
= CreateWindowEx(0,
174 WS_CHILD
| WS_VISIBLE
| SBARS_SIZEGRIP
,
177 (HMENU
)IDC_STATUSBAR
,
181 MessageBox(hwnd
, _T("Could not create status bar."),
182 _T("Error!"), MB_OK
| MB_ICONERROR
);
184 SendMessage(hStatus
, SB_SETPARTS
, sizeof(statwidths
)/sizeof(int), (LPARAM
)statwidths
);
187 /* ======================== Create Popup Menu ============================== */
189 hShortcutMenu
= LoadMenu(hInstance
, MAKEINTRESOURCE (IDR_POPUP
));
190 hShortcutMenu
= GetSubMenu(hShortcutMenu
, 0);
195 /* ================= populate the list view with all services =================== */
197 RefreshServiceList();
213 /* Size toolbar and get height */
214 hTool
= GetDlgItem(hwnd
, IDC_TOOLBAR
);
215 SendMessage(hTool
, TB_AUTOSIZE
, 0, 0);
217 GetWindowRect(hTool
, &rcTool
);
218 iToolHeight
= rcTool
.bottom
- rcTool
.top
;
220 /* Size status bar and get height */
221 hStatus
= GetDlgItem(hwnd
, IDC_STATUSBAR
);
222 SendMessage(hStatus
, WM_SIZE
, 0, 0);
224 GetWindowRect(hStatus
, &rcStatus
);
225 iStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
227 /* Calculate remaining height and size list view */
228 GetClientRect(hwnd
, &rcClient
);
230 lvHeight
= rcClient
.bottom
- iToolHeight
- iStatusHeight
;
232 hListView
= GetDlgItem(hwnd
, IDC_SERVLIST
);
233 SetWindowPos(hListView
, NULL
, 0, iToolHeight
, rcClient
.right
, lvHeight
, SWP_NOZORDER
);
239 NMHDR
* nm
= (NMHDR
*) lParam
;
247 case LVN_ITEMCHANGED
:
249 LPNMLISTVIEW pnmv
= (LPNMLISTVIEW
) lParam
;
251 SelectedItem
= pnmv
->iItem
;
256 case TTN_GETDISPINFO
:
261 lpttt
= (LPTOOLTIPTEXT
) lParam
;
263 /* Specify the resource identifier of the descriptive
264 * text for the given button. */
265 idButton
= (UINT
)lpttt
->hdr
.idFrom
;
269 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_PROP
);
273 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH
);
277 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_EXPORT
);
281 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_START
);
285 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_STOP
);
289 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_PAUSE
);
293 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_RESTART
);
297 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_NEW
);
301 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_HELP
);
305 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_EXIT
);
322 xPos
= GET_X_LPARAM(lParam
);
323 yPos
= GET_Y_LPARAM(lParam
);
325 TrackPopupMenuEx(hShortcutMenu
, TPM_RIGHTBUTTON
,
326 xPos
, yPos
, hwnd
, NULL
);
332 switch(LOWORD(wParam
))
340 RefreshServiceList();
348 ENUM_SERVICE_STATUS_PROCESS
*Service
= NULL
;
351 /* open the progress dialog */
352 hProgDlg
= CreateDialog(GetModuleHandle(NULL
),
353 MAKEINTRESOURCE(IDD_DLG_PROGRESS
),
355 (DLGPROC
)ProgressDialogProc
);
356 if (hProgDlg
!= NULL
)
358 ShowWindow(hProgDlg
, SW_SHOW
);
360 /* write the info to the progress dialog */
361 LoadString(hInstance
, IDS_PROGRESS_INFO
, buf1
,
362 sizeof(buf1
) / sizeof(TCHAR
));
363 _sntprintf(buf2
, 100, buf1
, _T("start"));
364 SendDlgItemMessage(hProgDlg
, IDC_SERVCON_INFO
, WM_SETTEXT
, 0, (LPARAM
)buf2
);
366 /* get pointer to selected service */
367 Service
= GetSelectedService();
369 /* write the service name to the progress dialog */
370 SendDlgItemMessage(hProgDlg
, IDC_SERVCON_NAME
, WM_SETTEXT
, 0,
371 (LPARAM
)Service
->lpServiceName
);
374 if ( DoStartService(hProgDlg
) )
379 LoadString(hInstance
, IDS_SERVICES_STARTED
, szStatus
,
380 sizeof(szStatus
) / sizeof(TCHAR
));
381 item
.pszText
= szStatus
;
382 item
.iItem
= GetSelectedItem();
384 SendMessage(hListView
, LVM_SETITEMTEXT
, item
.iItem
, (LPARAM
) &item
);
387 SendMessage(hProgDlg
, WM_DESTROY
, 0, 0);
393 ENUM_SERVICE_STATUS_PROCESS
*Service
= NULL
;
396 /* open the progress dialog */
397 hProgDlg
= CreateDialog(GetModuleHandle(NULL
),
398 MAKEINTRESOURCE(IDD_DLG_PROGRESS
),
400 (DLGPROC
)ProgressDialogProc
);
401 if (hProgDlg
!= NULL
)
403 ShowWindow(hProgDlg
, SW_SHOW
);
405 /* write the info to the progress dialog */
406 LoadString(hInstance
, IDS_PROGRESS_INFO
, buf1
,
407 sizeof(buf1
) / sizeof(TCHAR
));
408 _sntprintf(buf2
, 100, buf1
, _T("stop"));
409 SendDlgItemMessage(hProgDlg
, IDC_SERVCON_INFO
, WM_SETTEXT
, 0, (LPARAM
)buf2
);
411 /* get pointer to selected service */
412 Service
= GetSelectedService();
414 /* write the service name to the progress dialog */
415 SendDlgItemMessage(hProgDlg
, IDC_SERVCON_NAME
, WM_SETTEXT
, 0,
416 (LPARAM
)Service
->lpServiceName
);
419 if( Control(hProgDlg
, SERVICE_CONTROL_STOP
) )
424 item
.iItem
= GetSelectedItem();
426 SendMessage(hListView
, LVM_SETITEMTEXT
, item
.iItem
, (LPARAM
) &item
);
429 SendMessage(hProgDlg
, WM_DESTROY
, 0, 0);
434 Control(hProgDlg
, SERVICE_CONTROL_PAUSE
);
438 Control(hProgDlg
, SERVICE_CONTROL_CONTINUE
);
442 SendMessage(hMainWnd
, WM_COMMAND
, 0, ID_STOP
);
443 SendMessage(hMainWnd
, WM_COMMAND
, 0, ID_START
);
450 MessageBox(NULL
, _T("Help is not yet implemented\n"),
451 _T("Note!"), MB_OK
| MB_ICONINFORMATION
);
455 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
458 case ID_VIEW_CUSTOMIZE
:
463 MAKEINTRESOURCE(IDD_ABOUTBOX
),
465 (DLGPROC
)AboutDialogProc
);
472 FreeMemory(); /* free the service array */
473 DestroyMenu(hShortcutMenu
);
482 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
488 #pragma warning(disable : 4100)
490 int WINAPI
WinMain(HINSTANCE hThisInstance
, HINSTANCE hPrevInstance
,
491 LPSTR lpCmdLine
, int nCmdShow
)
496 hInstance
= hThisInstance
;
498 InitCommonControls();
500 wc
.cbSize
= sizeof(WNDCLASSEX
);
502 wc
.lpfnWndProc
= WndProc
;
505 wc
.hInstance
= hInstance
;
506 wc
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_SM_ICON
));
507 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
508 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
509 wc
.lpszMenuName
= MAKEINTRESOURCE(IDR_MAINMENU
);
510 wc
.lpszClassName
= ClassName
;
511 wc
.hIconSm
= (HICON
)LoadImage(hInstance
,
512 MAKEINTRESOURCE(IDI_SM_ICON
), IMAGE_ICON
, 16, 16, 0);
514 if(!RegisterClassEx(&wc
))
516 MessageBox(NULL
, _T("Window Registration Failed!"), _T("Error!"),
517 MB_ICONEXCLAMATION
| MB_OK
);
521 hMainWnd
= CreateWindowEx(
524 _T("ReactOS Service Manager"),
525 WS_OVERLAPPEDWINDOW
| WS_CLIPCHILDREN
,
526 CW_USEDEFAULT
, CW_USEDEFAULT
, 650, 450,
527 NULL
, NULL
, hInstance
, NULL
);
531 MessageBox(NULL
, _T("Window Creation Failed!"), _T("Error!"),
532 MB_ICONEXCLAMATION
| MB_OK
);
536 ShowWindow(hMainWnd
, nCmdShow
);
537 UpdateWindow(hMainWnd
);
539 while( GetMessage( &Msg
, NULL
, 0, 0 ) )
541 if(! IsDialogMessage(hProgDlg
, &Msg
) )
543 TranslateMessage(&Msg
);
544 DispatchMessage(&Msg
);
548 return (int)Msg
.wParam
;