314284a083fd778ee1d1acdd81ae755a664cd35f
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 {STD_PROPERTIES
, ID_PROP
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0}, /* properties */
41 {STD_FILENEW
, ID_REFRESH
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0}, /* */
42 {STD_FILENEW
, ID_EXPORT
, TBSTATE_ENABLED
, BTNS_BUTTON
, {0}, 0, 0}, /* */
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 */
53 /* ======================== Create Toolbar ============================== */
56 hTool
= CreateWindowEx(0,
59 WS_CHILD
| WS_VISIBLE
| TBSTYLE_FLAT
| TBSTYLE_TOOLTIPS
,
66 MessageBox(hwnd
, _T("Could not create tool bar."), _T("Error"), MB_OK
| MB_ICONERROR
);
68 /* Send the TB_BUTTONSTRUCTSIZE message, which is required for backward compatibility */
69 SendMessage(hTool
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
71 /* Add standard image list */
72 tbab
.hInst
= HINST_COMMCTRL
;
73 tbab
.nID
= IDB_STD_SMALL_COLOR
;
74 SendMessage(hTool
, TB_ADDBITMAP
, 0, (LPARAM
) &tbab
);
76 /* Add custom images */
77 tbab
.hInst
= hInstance
;
78 tbab
.nID
= IDB_BUTTONS
;
79 iImageOffset
= (INT
)SendMessage(hTool
, TB_ADDBITMAP
, 4, (LPARAM
)&tbab
);
80 tbb
[4].iBitmap
+= iImageOffset
; /* start */
81 tbb
[5].iBitmap
+= iImageOffset
; /* stop */
82 tbb
[6].iBitmap
+= iImageOffset
; /* pause */
83 tbb
[7].iBitmap
+= iImageOffset
; /* restart */
85 /* Add buttons to toolbar */
86 SendMessage(hTool
, TB_ADDBUTTONS
, NUM_BUTTONS
, (LPARAM
) &tbb
);
88 /* Send a WM_SIZE message to layout controls */
89 GetClientRect(hwnd
, &rcClient
);
90 SendMessage(hwnd
, WM_SIZE
, SIZE_RESTORED
, MAKELONG(rcClient
.right
, rcClient
.bottom
));
93 ShowWindow(hTool
, SW_SHOWNORMAL
);
97 /* ======================== Create List View ============================== */
99 hListView
= CreateWindow(WC_LISTVIEW
,
101 WS_CHILD
| WS_VISIBLE
| LVS_REPORT
| WS_BORDER
|
102 LVS_EDITLABELS
| LVS_SORTASCENDING
,
103 0, 0, 0, 0, /* sized via WM_SIZE */
105 (HMENU
) IDC_SERVLIST
,
108 if (hListView
== NULL
)
109 MessageBox(hwnd
, _T("Could not create List View."), _T("Error"), MB_OK
| MB_ICONERROR
);
113 ListView_SetExtendedListViewStyle(hListView
, LVS_EX_FULLROWSELECT
|
114 /*LVS_EX_GRIDLINES |*/ LVS_EX_HEADERDRAGDROP
);
116 lvc
.mask
= LVCF_TEXT
| LVCF_SUBITEM
| LVCF_WIDTH
| LVCF_FMT
;
117 lvc
.fmt
= LVCFMT_LEFT
;
119 /* Add columns to the list-view (first column contains check box). */
122 LoadString(hInstance
, IDS_FIRSTCOLUMN
, szTemp
, 256);
123 lvc
.pszText
= szTemp
;
124 ListView_InsertColumn(hListView
, 0, &lvc
);
128 LoadString(hInstance
, IDS_SECONDCOLUMN
, szTemp
, 256);
129 lvc
.pszText
= szTemp
;
130 ListView_InsertColumn(hListView
, 1, &lvc
);
134 LoadString(hInstance
, IDS_THIRDCOLUMN
, szTemp
, 256);
135 lvc
.pszText
= szTemp
;
136 ListView_InsertColumn(hListView
, 2, &lvc
);
140 LoadString(hInstance
, IDS_FOURTHCOLUMN
, szTemp
, 256);
141 lvc
.pszText
= szTemp
;
142 ListView_InsertColumn(hListView
, 3, &lvc
);
146 LoadString(hInstance
, IDS_FITHCOLUMN
, szTemp
, 256);
147 lvc
.pszText
= szTemp
;
148 ListView_InsertColumn(hListView
, 4, &lvc
);
152 /* ======================== Create Status Bar ============================== */
154 hStatus
= CreateWindowEx(0,
157 WS_CHILD
| WS_VISIBLE
| SBARS_SIZEGRIP
,
160 (HMENU
)IDC_STATUSBAR
,
164 MessageBox(hwnd
, _T("Could not create status bar."),
165 _T("Error!"), MB_OK
| MB_ICONERROR
);
167 SendMessage(hStatus
, SB_SETPARTS
, sizeof(statwidths
)/sizeof(int), (LPARAM
)statwidths
);
169 /* populate the list view with all services */
170 if (! RefreshServiceList() )
186 /* Size toolbar and get height */
187 SendMessage(hTool
, TB_AUTOSIZE
, 0, 0);
189 GetWindowRect(hTool
, &rcTool
);
190 iToolHeight
= rcTool
.bottom
- rcTool
.top
;
192 /* Size status bar and get height */
193 hStatus
= GetDlgItem(hwnd
, IDC_STATUSBAR
);
194 SendMessage(hStatus
, WM_SIZE
, 0, 0);
196 GetWindowRect(hStatus
, &rcStatus
);
197 iStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
199 /* Calculate remaining height and size list view */
200 GetClientRect(hwnd
, &rcClient
);
202 lvHeight
= rcClient
.bottom
- iToolHeight
- iStatusHeight
;
204 hListView
= GetDlgItem(hwnd
, IDC_SERVLIST
);
205 SetWindowPos(hListView
, NULL
, 0, iToolHeight
, rcClient
.right
, lvHeight
, SWP_NOZORDER
);
211 LPNMITEMACTIVATE item
;
213 switch (((LPNMHDR
) lParam
)->code
)
217 item
= (LPNMITEMACTIVATE
) lParam
;
222 case TTN_GETDISPINFO
:
227 lpttt
= (LPTOOLTIPTEXT
) lParam
;
228 lpttt
->hinst
= hInstance
;
230 // Specify the resource identifier of the descriptive
231 // text for the given button.
232 idButton
= lpttt
->hdr
.idFrom
;
236 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_PROP
);
240 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH
);
244 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_EXPORT
);
248 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_START
);
252 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_STOP
);
256 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_PAUSE
);
260 lpttt
->lpszText
= MAKEINTRESOURCE(IDS_TOOLTIP_RESTART
);
274 /* free the service array */
284 switch(LOWORD(wParam
))
287 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
312 case ID_VIEW_CUSTOMIZE
:
317 MAKEINTRESOURCE(IDD_ABOUTBOX
),
329 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
335 //#pragma warning(disable : 4100)
336 int WINAPI
WinMain(HINSTANCE hThisInstance
, HINSTANCE hPrevInstance
,
337 LPSTR lpCmdLine
, int nCmdShow
)
343 hInstance
= hThisInstance
;
345 InitCommonControls();
347 wc
.cbSize
= sizeof(WNDCLASSEX
);
349 wc
.lpfnWndProc
= WndProc
;
352 wc
.hInstance
= hInstance
;
353 wc
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_SM_ICON
));
354 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
355 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
356 wc
.lpszMenuName
= MAKEINTRESOURCE(IDR_MAINMENU
);
357 wc
.lpszClassName
= ClassName
;
358 wc
.hIconSm
= (HICON
)LoadImage(hInstance
,
359 MAKEINTRESOURCE(IDI_SM_ICON
), IMAGE_ICON
, 16, 16, 0);
361 if(!RegisterClassEx(&wc
))
363 MessageBox(NULL
, _T("Window Registration Failed!"), _T("Error!"),
364 MB_ICONEXCLAMATION
| MB_OK
);
368 hMainWnd
= CreateWindowEx(
371 _T("ReactOS Service Manager"),
372 WS_OVERLAPPEDWINDOW
| WS_CLIPCHILDREN
,
373 CW_USEDEFAULT
, CW_USEDEFAULT
, 700, 500,
374 NULL
, NULL
, hInstance
, NULL
);
378 MessageBox(NULL
, _T("Window Creation Failed!"), _T("Error!"),
379 MB_ICONEXCLAMATION
| MB_OK
);
383 ShowWindow(hMainWnd
, nCmdShow
);
384 UpdateWindow(hMainWnd
);
386 while( (bRet
= GetMessage( &Msg
, NULL
, 0, 0 )) != 0)
390 /* handle the error and possibly exit */
394 TranslateMessage(&Msg
);
395 DispatchMessage(&Msg
);