49ffa6044cbc8baf520e55dd61934b7b89a2b229
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");
21 LRESULT CALLBACK
WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
32 INT statwidths
[] = {110, -1};
38 TBBUTTON tbb
[NUM_BUTTONS
] =
39 { // iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString
40 {TBICON_PROP
, ID_PROP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0}, /* properties */
41 {TBICON_REFRESH
, ID_REFRESH
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0}, /* refresh */
42 {TBICON_EXPORT
, ID_EXPORT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0}, /* export */
44 /* Note: First item for a seperator is its width in pixels */
45 {5, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0}, 0, 0}, /* separator */
47 {TBICON_START
, ID_START
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* start */
48 {TBICON_STOP
, ID_STOP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* stop */
49 {TBICON_PAUSE
, ID_PAUSE
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* pause */
50 {TBICON_RESTART
, ID_RESTART
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* restart */
52 {5, 0, TBSTATE_ENABLED
, BTNS_SEP
, {0}, 0, 0}, /* separator */
54 {TBICON_NEW
, ID_NEW
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* start */
55 {TBICON_HELP
, ID_HELP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* stop */
56 {TBICON_EXIT
, ID_EXIT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0 }, /* pause */
60 /* ======================== Create Toolbar ============================== */
63 hTool
= CreateWindowEx(0,
66 WS_CHILD
| WS_VISIBLE
| TBSTYLE_FLAT
| TBSTYLE_TOOLTIPS
,
73 MessageBox(hwnd
, _T("Could not create tool bar."), _T("Error"), MB_OK
| MB_ICONERROR
);
75 /* Send the TB_BUTTONSTRUCTSIZE message, which is required for backward compatibility */
76 SendMessage(hTool
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
78 /* Add standard image list */
79 tbab
.hInst
= HINST_COMMCTRL
;
80 tbab
.nID
= IDB_STD_SMALL_COLOR
;
81 SendMessage(hTool
, TB_ADDBITMAP
, 0, (LPARAM
) &tbab
);
83 /* Add custom images */
84 tbab
.hInst
= hInstance
;
85 tbab
.nID
= IDB_BUTTONS
;
86 iImageOffset
= (INT
)SendMessage(hTool
, TB_ADDBITMAP
, 11, (LPARAM
)&tbab
);
87 tbb
[0].iBitmap
+= iImageOffset
; /* properties */
88 tbb
[1].iBitmap
+= iImageOffset
; /* refresh */
89 tbb
[2].iBitmap
+= iImageOffset
; /* export */
90 tbb
[4].iBitmap
+= iImageOffset
; /* start */
91 tbb
[5].iBitmap
+= iImageOffset
; /* stop */
92 tbb
[6].iBitmap
+= iImageOffset
; /* pause */
93 tbb
[7].iBitmap
+= iImageOffset
; /* restart */
94 tbb
[9].iBitmap
+= iImageOffset
; /* new */
95 tbb
[10].iBitmap
+= iImageOffset
; /* help */
96 tbb
[11].iBitmap
+= iImageOffset
; /* exit */
98 /* Add buttons to toolbar */
99 SendMessage(hTool
, TB_ADDBUTTONS
, NUM_BUTTONS
, (LPARAM
) &tbb
);
101 /* Send a WM_SIZE message to layout controls */
102 GetClientRect(hwnd
, &rcClient
);
103 SendMessage(hwnd
, WM_SIZE
, SIZE_RESTORED
, MAKELONG(rcClient
.right
, rcClient
.bottom
));
106 ShowWindow(hTool
, SW_SHOWNORMAL
);
110 /* ======================== Create List View ============================== */
112 hListView
= CreateWindow(WC_LISTVIEW
,
114 WS_CHILD
| WS_VISIBLE
| LVS_REPORT
| WS_BORDER
|
115 LVS_EDITLABELS
| LVS_SORTASCENDING
,
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
);
126 ListView_SetExtendedListViewStyle(hListView
, LVS_EX_FULLROWSELECT
|
127 /*LVS_EX_GRIDLINES |*/ LVS_EX_HEADERDRAGDROP
);
129 lvc
.mask
= LVCF_TEXT
| LVCF_SUBITEM
| LVCF_WIDTH
| LVCF_FMT
;
130 lvc
.fmt
= LVCFMT_LEFT
;
132 /* Add columns to the list-view (first column contains check box). */
135 LoadString(hInstance
, IDS_FIRSTCOLUMN
, szTemp
, 256);
136 lvc
.pszText
= szTemp
;
137 ListView_InsertColumn(hListView
, 0, &lvc
);
141 LoadString(hInstance
, IDS_SECONDCOLUMN
, szTemp
, 256);
142 lvc
.pszText
= szTemp
;
143 ListView_InsertColumn(hListView
, 1, &lvc
);
147 LoadString(hInstance
, IDS_THIRDCOLUMN
, szTemp
, 256);
148 lvc
.pszText
= szTemp
;
149 ListView_InsertColumn(hListView
, 2, &lvc
);
153 LoadString(hInstance
, IDS_FOURTHCOLUMN
, szTemp
, 256);
154 lvc
.pszText
= szTemp
;
155 ListView_InsertColumn(hListView
, 3, &lvc
);
159 LoadString(hInstance
, IDS_FITHCOLUMN
, szTemp
, 256);
160 lvc
.pszText
= szTemp
;
161 ListView_InsertColumn(hListView
, 4, &lvc
);
165 /* ======================== Create Status Bar ============================== */
167 hStatus
= CreateWindowEx(0,
170 WS_CHILD
| WS_VISIBLE
| SBARS_SIZEGRIP
,
173 (HMENU
)IDC_STATUSBAR
,
177 MessageBox(hwnd
, _T("Could not create status bar."),
178 _T("Error!"), MB_OK
| MB_ICONERROR
);
180 SendMessage(hStatus
, SB_SETPARTS
, sizeof(statwidths
)/sizeof(int), (LPARAM
)statwidths
);
182 /* populate the list view with all services */
183 if (! RefreshServiceList() )
199 /* Size toolbar and get height */
200 hTool
= GetDlgItem(hwnd
, IDC_TOOLBAR
);
201 SendMessage(hTool
, TB_AUTOSIZE
, 0, 0);
203 GetWindowRect(hTool
, &rcTool
);
204 iToolHeight
= rcTool
.bottom
- rcTool
.top
;
206 /* Size status bar and get height */
207 hStatus
= GetDlgItem(hwnd
, IDC_STATUSBAR
);
208 SendMessage(hStatus
, WM_SIZE
, 0, 0);
210 GetWindowRect(hStatus
, &rcStatus
);
211 iStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
213 /* Calculate remaining height and size list view */
214 GetClientRect(hwnd
, &rcClient
);
216 lvHeight
= rcClient
.bottom
- iToolHeight
- iStatusHeight
;
218 hListView
= GetDlgItem(hwnd
, IDC_SERVLIST
);
219 SetWindowPos(hListView
, NULL
, 0, iToolHeight
, rcClient
.right
, lvHeight
, SWP_NOZORDER
);
225 LPNMITEMACTIVATE item
;
227 switch (((LPNMHDR
) lParam
)->code
)
231 item
= (LPNMITEMACTIVATE
) lParam
;
236 case TTN_GETDISPINFO
:
241 lpttt
= (LPTOOLTIPTEXT
) lParam
;
242 lpttt
->hinst
= hInstance
;
244 // Specify the resource identifier of the descriptive
245 // text for the given button.
246 idButton
= lpttt
->hdr
.idFrom
;
250 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_PROP
);
254 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH
);
258 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_EXPORT
);
262 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_START
);
266 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_STOP
);
270 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_PAUSE
);
274 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_RESTART
);
278 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_NEW
);
282 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_HELP
);
286 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_EXIT
);
300 /* free the service array */
310 switch(LOWORD(wParam
))
313 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
338 case ID_VIEW_CUSTOMIZE
:
343 MAKEINTRESOURCE(IDD_ABOUTBOX
),
355 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
361 //#pragma warning(disable : 4100)
362 int WINAPI
WinMain(HINSTANCE hThisInstance
, HINSTANCE hPrevInstance
,
363 LPSTR lpCmdLine
, int nCmdShow
)
369 hInstance
= hThisInstance
;
371 InitCommonControls();
373 wc
.cbSize
= sizeof(WNDCLASSEX
);
375 wc
.lpfnWndProc
= WndProc
;
378 wc
.hInstance
= hInstance
;
379 wc
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_SM_ICON
));
380 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
381 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
382 wc
.lpszMenuName
= MAKEINTRESOURCE(IDR_MAINMENU
);
383 wc
.lpszClassName
= ClassName
;
384 wc
.hIconSm
= (HICON
)LoadImage(hInstance
,
385 MAKEINTRESOURCE(IDI_SM_ICON
), IMAGE_ICON
, 16, 16, 0);
387 if(!RegisterClassEx(&wc
))
389 MessageBox(NULL
, _T("Window Registration Failed!"), _T("Error!"),
390 MB_ICONEXCLAMATION
| MB_OK
);
394 hMainWnd
= CreateWindowEx(
397 _T("ReactOS Service Manager"),
398 WS_OVERLAPPEDWINDOW
| WS_CLIPCHILDREN
,
399 CW_USEDEFAULT
, CW_USEDEFAULT
, 700, 500,
400 NULL
, NULL
, hInstance
, NULL
);
404 MessageBox(NULL
, _T("Window Creation Failed!"), _T("Error!"),
405 MB_ICONEXCLAMATION
| MB_OK
);
409 ShowWindow(hMainWnd
, nCmdShow
);
410 UpdateWindow(hMainWnd
);
412 while( (bRet
= GetMessage( &Msg
, NULL
, 0, 0 )) != 0)
416 /* handle the error and possibly exit */
420 TranslateMessage(&Msg
);
421 DispatchMessage(&Msg
);