dc10abe8e1175cbee07e8c5a7b3e4c817ac7bb1a
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>
12 const TCHAR ClassName
[] = _T("ServiceManager");
22 LRESULT CALLBACK
WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
32 INT statwidths
[] = {110, -1}; /* widths of status bar */
37 TBBUTTON tbb
[NUM_BUTTONS
] =
38 { /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
39 {TBICON_PROP
, ID_PROP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0}, /* properties */
40 {TBICON_REFRESH
, ID_REFRESH
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0}, /* refresh */
41 {TBICON_EXPORT
, ID_EXPORT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0}, /* export */
43 /* Note: First item for a seperator is its width in pixels */
44 {25, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0}, 0, 0}, /* separator */
46 {TBICON_START
, ID_START
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* start */
47 {TBICON_STOP
, ID_STOP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* stop */
48 {TBICON_PAUSE
, ID_PAUSE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* pause */
49 {TBICON_RESTART
, ID_RESTART
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* restart */
51 {25, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0}, 0, 0}, /* separator */
53 {TBICON_NEW
, ID_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* start */
54 {TBICON_HELP
, ID_HELP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* stop */
55 {TBICON_EXIT
, ID_EXIT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* pause */
59 /* ======================== Create Toolbar ============================== */
62 hTool
= CreateWindowEx(0,
65 WS_CHILD
| WS_VISIBLE
| TBSTYLE_FLAT
| TBSTYLE_TOOLTIPS
,
72 MessageBox(hwnd
, _T("Could not create tool bar."), _T("Error"), MB_OK
| MB_ICONERROR
);
74 /* Send the TB_BUTTONSTRUCTSIZE message, which is required for backward compatibility */
75 SendMessage(hTool
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
77 /* Add standard image list */
78 tbab
.hInst
= HINST_COMMCTRL
;
79 tbab
.nID
= IDB_STD_SMALL_COLOR
;
80 SendMessage(hTool
, TB_ADDBITMAP
, 0, (LPARAM
) &tbab
);
82 /* Add custom images */
83 tbab
.hInst
= hInstance
;
84 tbab
.nID
= IDB_BUTTONS
;
85 iImageOffset
= (INT
)SendMessage(hTool
, TB_ADDBITMAP
, 11, (LPARAM
)&tbab
);
86 tbb
[0].iBitmap
+= iImageOffset
; /* properties */
87 tbb
[1].iBitmap
+= iImageOffset
; /* refresh */
88 tbb
[2].iBitmap
+= iImageOffset
; /* export */
89 tbb
[4].iBitmap
+= iImageOffset
; /* start */
90 tbb
[5].iBitmap
+= iImageOffset
; /* stop */
91 tbb
[6].iBitmap
+= iImageOffset
; /* pause */
92 tbb
[7].iBitmap
+= iImageOffset
; /* restart */
93 tbb
[9].iBitmap
+= iImageOffset
; /* new */
94 tbb
[10].iBitmap
+= iImageOffset
; /* help */
95 tbb
[11].iBitmap
+= iImageOffset
; /* exit */
97 /* Add buttons to toolbar */
98 SendMessage(hTool
, TB_ADDBUTTONS
, NUM_BUTTONS
, (LPARAM
) &tbb
);
101 ShowWindow(hTool
, SW_SHOWNORMAL
);
105 /* ======================== Create List View ============================== */
107 hListView
= CreateWindow(WC_LISTVIEW
,
109 WS_CHILD
| WS_VISIBLE
| LVS_REPORT
| WS_BORDER
|
110 LVS_EDITLABELS
| LVS_SORTASCENDING
,
111 0, 0, 0, 0, /* sized via WM_SIZE */
113 (HMENU
) IDC_SERVLIST
,
116 if (hListView
== NULL
)
117 MessageBox(hwnd
, _T("Could not create List View."), _T("Error"), MB_OK
| MB_ICONERROR
);
119 ListView_SetExtendedListViewStyle(hListView
, LVS_EX_FULLROWSELECT
|
120 LVS_EX_GRIDLINES
| LVS_EX_HEADERDRAGDROP
);
122 lvc
.mask
= LVCF_TEXT
| LVCF_SUBITEM
| LVCF_WIDTH
| LVCF_FMT
;
123 lvc
.fmt
= LVCFMT_LEFT
;
125 /* Add columns to the list-view */
130 LoadString(hInstance
, IDS_FIRSTCOLUMN
, szTemp
, 256);
131 lvc
.pszText
= szTemp
;
132 ListView_InsertColumn(hListView
, 0, &lvc
);
137 LoadString(hInstance
, IDS_SECONDCOLUMN
, szTemp
, 256);
138 lvc
.pszText
= szTemp
;
139 ListView_InsertColumn(hListView
, 1, &lvc
);
144 LoadString(hInstance
, IDS_THIRDCOLUMN
, szTemp
, 256);
145 lvc
.pszText
= szTemp
;
146 ListView_InsertColumn(hListView
, 2, &lvc
);
151 LoadString(hInstance
, IDS_FOURTHCOLUMN
, szTemp
, 256);
152 lvc
.pszText
= szTemp
;
153 ListView_InsertColumn(hListView
, 3, &lvc
);
158 LoadString(hInstance
, IDS_FITHCOLUMN
, szTemp
, 256);
159 lvc
.pszText
= szTemp
;
160 ListView_InsertColumn(hListView
, 4, &lvc
);
164 /* ======================== Create Status Bar ============================== */
166 hStatus
= CreateWindowEx(0,
169 WS_CHILD
| WS_VISIBLE
| SBARS_SIZEGRIP
,
172 (HMENU
)IDC_STATUSBAR
,
176 MessageBox(hwnd
, _T("Could not create status bar."),
177 _T("Error!"), MB_OK
| MB_ICONERROR
);
179 SendMessage(hStatus
, SB_SETPARTS
, sizeof(statwidths
)/sizeof(int), (LPARAM
)statwidths
);
182 /* ======================== Create Popup Menu ============================== */
184 hShortcutMenu
= LoadMenu(hInstance
, MAKEINTRESOURCE (IDR_POPUP
));
185 hShortcutMenu
= GetSubMenu(hShortcutMenu
, 0);
190 /* ================= populate the list view with all services =================== */
192 RefreshServiceList();
208 /* Size toolbar and get height */
209 hTool
= GetDlgItem(hwnd
, IDC_TOOLBAR
);
210 SendMessage(hTool
, TB_AUTOSIZE
, 0, 0);
212 GetWindowRect(hTool
, &rcTool
);
213 iToolHeight
= rcTool
.bottom
- rcTool
.top
;
215 /* Size status bar and get height */
216 hStatus
= GetDlgItem(hwnd
, IDC_STATUSBAR
);
217 SendMessage(hStatus
, WM_SIZE
, 0, 0);
219 GetWindowRect(hStatus
, &rcStatus
);
220 iStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
222 /* Calculate remaining height and size list view */
223 GetClientRect(hwnd
, &rcClient
);
225 lvHeight
= rcClient
.bottom
- iToolHeight
- iStatusHeight
;
227 hListView
= GetDlgItem(hwnd
, IDC_SERVLIST
);
228 SetWindowPos(hListView
, NULL
, 0, iToolHeight
, rcClient
.right
, lvHeight
, SWP_NOZORDER
);
234 LPNMITEMACTIVATE item
;
237 switch (((LPNMHDR
) lParam
)->code
)
240 item
= (LPNMITEMACTIVATE
) lParam
;
244 case TTN_GETDISPINFO
:
249 lpttt
= (LPTOOLTIPTEXT
) lParam
;
250 lpttt
->hinst
= hInstance
;
252 // Specify the resource identifier of the descriptive
253 // text for the given button.
254 idButton
= (UINT
)lpttt
->hdr
.idFrom
;
258 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_PROP
);
262 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH
);
266 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_EXPORT
);
270 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_START
);
274 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_STOP
);
278 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_PAUSE
);
282 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_RESTART
);
286 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_NEW
);
290 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_HELP
);
294 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_EXIT
);
308 FreeMemory(); /* free the service array */
309 DestroyMenu(hShortcutMenu
);
321 xPos
= LOWORD(lParam
);
322 yPos
= HIWORD(lParam
);
324 TrackPopupMenuEx(hShortcutMenu
, TPM_RIGHTBUTTON
, xPos
, yPos
, hwnd
, NULL
);
329 switch(LOWORD(wParam
))
336 if (! RefreshServiceList() )
361 MessageBox(NULL
, _T("Help is not yet implemented\n"),
362 _T("Note!"), MB_OK
| MB_ICONINFORMATION
);
366 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
369 case ID_VIEW_CUSTOMIZE
:
374 MAKEINTRESOURCE(IDD_ABOUTBOX
),
383 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
389 #pragma warning(disable : 4100)
391 int WINAPI
WinMain(HINSTANCE hThisInstance
, HINSTANCE hPrevInstance
,
392 LPSTR lpCmdLine
, int nCmdShow
)
398 hInstance
= hThisInstance
;
400 InitCommonControls();
402 wc
.cbSize
= sizeof(WNDCLASSEX
);
404 wc
.lpfnWndProc
= WndProc
;
407 wc
.hInstance
= hInstance
;
408 wc
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_SM_ICON
));
409 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
410 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
411 wc
.lpszMenuName
= MAKEINTRESOURCE(IDR_MAINMENU
);
412 wc
.lpszClassName
= ClassName
;
413 wc
.hIconSm
= (HICON
)LoadImage(hInstance
,
414 MAKEINTRESOURCE(IDI_SM_ICON
), IMAGE_ICON
, 16, 16, 0);
416 if(!RegisterClassEx(&wc
))
418 MessageBox(NULL
, _T("Window Registration Failed!"), _T("Error!"),
419 MB_ICONEXCLAMATION
| MB_OK
);
423 hMainWnd
= CreateWindowEx(
426 _T("ReactOS Service Manager"),
427 WS_OVERLAPPEDWINDOW
| WS_CLIPCHILDREN
,
428 CW_USEDEFAULT
, CW_USEDEFAULT
, 700, 500,
429 NULL
, NULL
, hInstance
, NULL
);
433 MessageBox(NULL
, _T("Window Creation Failed!"), _T("Error!"),
434 MB_ICONEXCLAMATION
| MB_OK
);
438 ShowWindow(hMainWnd
, nCmdShow
);
439 UpdateWindow(hMainWnd
);
441 while( (bRet
= GetMessage( &Msg
, NULL
, 0, 0 )) != 0)
445 /* handle the error and possibly exit */
449 TranslateMessage(&Msg
);
450 DispatchMessage(&Msg
);
453 return (int)Msg
.wParam
;