55aa961d6c8e2eb9734864e1b41090dbeec93a79
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");
23 INT
GetSelectedItem(VOID
)
29 LRESULT CALLBACK
WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
37 INT statwidths
[] = {110, -1}; /* widths of status bar */
42 TBBUTTON tbb
[NUM_BUTTONS
] =
43 { /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
44 {TBICON_PROP
, ID_PROP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0}, /* properties */
45 {TBICON_REFRESH
, ID_REFRESH
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0}, /* refresh */
46 {TBICON_EXPORT
, ID_EXPORT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0}, /* export */
48 /* Note: First item for a seperator is its width in pixels */
49 {15, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0}, 0, 0}, /* separator */
51 {TBICON_NEW
, ID_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* create */
53 {15, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0}, 0, 0}, /* separator */
55 {TBICON_START
, ID_START
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* start */
56 {TBICON_STOP
, ID_STOP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* stop */
57 {TBICON_PAUSE
, ID_PAUSE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* pause */
58 {TBICON_RESTART
, ID_RESTART
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* restart */
60 {15, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0}, 0, 0}, /* separator */
62 {TBICON_HELP
, ID_HELP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* help */
63 {TBICON_EXIT
, ID_EXIT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* exit */
67 /* ======================== Create Toolbar ============================== */
70 hTool
= CreateWindowEx(0,
73 WS_CHILD
| WS_VISIBLE
| TBSTYLE_FLAT
| TBSTYLE_TOOLTIPS
,
80 MessageBox(hwnd
, _T("Could not create tool bar."), _T("Error"), MB_OK
| MB_ICONERROR
);
82 /* Send the TB_BUTTONSTRUCTSIZE message, which is required for backward compatibility */
83 SendMessage(hTool
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
85 /* Add custom images */
86 tbab
.hInst
= hInstance
;
87 tbab
.nID
= IDB_BUTTONS
;
88 iImageOffset
= (INT
)SendMessage(hTool
, TB_ADDBITMAP
, NUM_BUTTONS
, (LPARAM
)&tbab
);
89 tbb
[0].iBitmap
+= iImageOffset
; /* properties */
90 tbb
[1].iBitmap
+= iImageOffset
; /* refresh */
91 tbb
[2].iBitmap
+= iImageOffset
; /* export */
92 tbb
[4].iBitmap
+= iImageOffset
; /* new */
93 tbb
[6].iBitmap
+= iImageOffset
; /* start */
94 tbb
[7].iBitmap
+= iImageOffset
; /* stop */
95 tbb
[8].iBitmap
+= iImageOffset
; /* pause */
96 tbb
[9].iBitmap
+= iImageOffset
; /* restart */
97 tbb
[11].iBitmap
+= iImageOffset
; /* help */
98 tbb
[12].iBitmap
+= iImageOffset
; /* exit */
100 /* Add buttons to toolbar */
101 SendMessage(hTool
, TB_ADDBUTTONS
, NUM_BUTTONS
, (LPARAM
) &tbb
);
104 ShowWindow(hTool
, SW_SHOWNORMAL
);
108 /* ======================== Create List View ============================== */
110 hListView
= CreateWindowEx(0,
113 WS_CHILD
| WS_VISIBLE
| LVS_REPORT
| WS_BORDER
|
114 LBS_NOTIFY
| LVS_SORTASCENDING
| LBS_NOREDRAW
,
115 0, 0, 0, 0, /* sized via WM_SIZE */
117 (HMENU
) IDC_SERVLIST
,
120 if (hListView
== NULL
)
121 MessageBox(hwnd
, _T("Could not create List View."), _T("Error"), MB_OK
| MB_ICONERROR
);
123 ListView_SetExtendedListViewStyle(hListView
, LVS_EX_FULLROWSELECT
|
124 LVS_EX_GRIDLINES
| LVS_EX_HEADERDRAGDROP
);
126 lvc
.mask
= LVCF_TEXT
| LVCF_SUBITEM
| LVCF_WIDTH
| LVCF_FMT
;
127 lvc
.fmt
= LVCFMT_LEFT
;
129 /* Add columns to the list-view */
134 LoadString(hInstance
, IDS_FIRSTCOLUMN
, szTemp
, 256);
135 lvc
.pszText
= szTemp
;
136 ListView_InsertColumn(hListView
, 0, &lvc
);
141 LoadString(hInstance
, IDS_SECONDCOLUMN
, szTemp
, 256);
142 lvc
.pszText
= szTemp
;
143 ListView_InsertColumn(hListView
, 1, &lvc
);
148 LoadString(hInstance
, IDS_THIRDCOLUMN
, szTemp
, 256);
149 lvc
.pszText
= szTemp
;
150 ListView_InsertColumn(hListView
, 2, &lvc
);
155 LoadString(hInstance
, IDS_FOURTHCOLUMN
, szTemp
, 256);
156 lvc
.pszText
= szTemp
;
157 ListView_InsertColumn(hListView
, 3, &lvc
);
162 LoadString(hInstance
, IDS_FITHCOLUMN
, szTemp
, 256);
163 lvc
.pszText
= szTemp
;
164 ListView_InsertColumn(hListView
, 4, &lvc
);
168 /* ======================== Create Status Bar ============================== */
170 hStatus
= CreateWindowEx(0,
173 WS_CHILD
| WS_VISIBLE
| SBARS_SIZEGRIP
,
176 (HMENU
)IDC_STATUSBAR
,
180 MessageBox(hwnd
, _T("Could not create status bar."),
181 _T("Error!"), MB_OK
| MB_ICONERROR
);
183 SendMessage(hStatus
, SB_SETPARTS
, sizeof(statwidths
)/sizeof(int), (LPARAM
)statwidths
);
186 /* ======================== Create Popup Menu ============================== */
188 hShortcutMenu
= LoadMenu(hInstance
, MAKEINTRESOURCE (IDR_POPUP
));
189 hShortcutMenu
= GetSubMenu(hShortcutMenu
, 0);
194 /* ================= populate the list view with all services =================== */
196 RefreshServiceList();
212 /* Size toolbar and get height */
213 hTool
= GetDlgItem(hwnd
, IDC_TOOLBAR
);
214 SendMessage(hTool
, TB_AUTOSIZE
, 0, 0);
216 GetWindowRect(hTool
, &rcTool
);
217 iToolHeight
= rcTool
.bottom
- rcTool
.top
;
219 /* Size status bar and get height */
220 hStatus
= GetDlgItem(hwnd
, IDC_STATUSBAR
);
221 SendMessage(hStatus
, WM_SIZE
, 0, 0);
223 GetWindowRect(hStatus
, &rcStatus
);
224 iStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
226 /* Calculate remaining height and size list view */
227 GetClientRect(hwnd
, &rcClient
);
229 lvHeight
= rcClient
.bottom
- iToolHeight
- iStatusHeight
;
231 hListView
= GetDlgItem(hwnd
, IDC_SERVLIST
);
232 SetWindowPos(hListView
, NULL
, 0, iToolHeight
, rcClient
.right
, lvHeight
, SWP_NOZORDER
);
238 NMHDR
* nm
= (NMHDR
*) lParam
;
246 case LVN_ITEMCHANGED
:
248 LPNMLISTVIEW pnmv
= (LPNMLISTVIEW
) lParam
;
250 SelectedItem
= pnmv
->iItem
;
255 case TTN_GETDISPINFO
:
260 lpttt
= (LPTOOLTIPTEXT
) lParam
;
262 /* Specify the resource identifier of the descriptive
263 * text for the given button. */
264 idButton
= (UINT
)lpttt
->hdr
.idFrom
;
268 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_PROP
);
272 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH
);
276 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_EXPORT
);
280 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_START
);
284 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_STOP
);
288 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_PAUSE
);
292 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_RESTART
);
296 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_NEW
);
300 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_HELP
);
304 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_EXIT
);
321 xPos
= GET_X_LPARAM(lParam
);
322 yPos
= GET_Y_LPARAM(lParam
);
324 TrackPopupMenuEx(hShortcutMenu
, TPM_RIGHTBUTTON
,
325 xPos
, yPos
, hwnd
, NULL
);
331 switch(LOWORD(wParam
))
338 RefreshServiceList();
346 RefreshServiceList();
350 Control(SERVICE_CONTROL_STOP
);
351 RefreshServiceList();
355 Control(SERVICE_CONTROL_PAUSE
);
356 RefreshServiceList();
360 Control(SERVICE_CONTROL_CONTINUE
);
361 RefreshServiceList();
365 Control(SERVICE_CONTROL_STOP
);
367 RefreshServiceList();
374 MessageBox(NULL
, _T("Help is not yet implemented\n"),
375 _T("Note!"), MB_OK
| MB_ICONINFORMATION
);
379 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
382 case ID_VIEW_CUSTOMIZE
:
387 MAKEINTRESOURCE(IDD_ABOUTBOX
),
396 FreeMemory(); /* free the service array */
397 DestroyMenu(hShortcutMenu
);
406 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
412 #pragma warning(disable : 4100)
414 int WINAPI
WinMain(HINSTANCE hThisInstance
, HINSTANCE hPrevInstance
,
415 LPSTR lpCmdLine
, int nCmdShow
)
421 hInstance
= hThisInstance
;
423 InitCommonControls();
425 wc
.cbSize
= sizeof(WNDCLASSEX
);
427 wc
.lpfnWndProc
= WndProc
;
430 wc
.hInstance
= hInstance
;
431 wc
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_SM_ICON
));
432 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
433 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
434 wc
.lpszMenuName
= MAKEINTRESOURCE(IDR_MAINMENU
);
435 wc
.lpszClassName
= ClassName
;
436 wc
.hIconSm
= (HICON
)LoadImage(hInstance
,
437 MAKEINTRESOURCE(IDI_SM_ICON
), IMAGE_ICON
, 16, 16, 0);
439 if(!RegisterClassEx(&wc
))
441 MessageBox(NULL
, _T("Window Registration Failed!"), _T("Error!"),
442 MB_ICONEXCLAMATION
| MB_OK
);
446 hMainWnd
= CreateWindowEx(
449 _T("ReactOS Service Manager"),
450 WS_OVERLAPPEDWINDOW
| WS_CLIPCHILDREN
,
451 CW_USEDEFAULT
, CW_USEDEFAULT
, 650, 450,
452 NULL
, NULL
, hInstance
, NULL
);
456 MessageBox(NULL
, _T("Window Creation Failed!"), _T("Error!"),
457 MB_ICONEXCLAMATION
| MB_OK
);
461 ShowWindow(hMainWnd
, nCmdShow
);
462 UpdateWindow(hMainWnd
);
464 while( (bRet
= GetMessage( &Msg
, NULL
, 0, 0 )) != 0)
468 /* handle the error and possibly exit */
472 TranslateMessage(&Msg
);
473 DispatchMessage(&Msg
);
476 return (int)Msg
.wParam
;