* Sync with recent trunk (r52637).
[reactos.git] / base / applications / msconfig / msconfig.c
1 /*
2 * PROJECT: ReactOS Applications
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/msconfig.c
5 * PURPOSE: msconfig main dialog
6 * COPYRIGHT: Copyright 2005-2006 Christoph von Wittich <Christoph@ApiViewer.de>
7 *
8 */
9 #include <precomp.h>
10
11 HINSTANCE hInst = 0;
12
13 HWND hMainWnd; /* Main Window */
14 HWND hTabWnd; /* Tab Control Window */
15 UINT uXIcon = 0, uYIcon = 0; /* Icon sizes */
16 HICON hDialogIcon = NULL;
17
18 void MsConfig_OnTabWndSelChange(void);
19
20 BOOL OnCreate(HWND hWnd)
21 {
22 TCHAR szTemp[256];
23 TCITEM item;
24
25 hTabWnd = GetDlgItem(hWnd, IDC_TAB);
26 hGeneralPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_GENERAL_PAGE), hWnd, GeneralPageWndProc);
27 hSystemPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SYSTEM_PAGE), hWnd, SystemPageWndProc);
28 hFreeLdrPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_FREELDR_PAGE), hWnd, FreeLdrPageWndProc);
29 hServicesPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SERVICES_PAGE), hWnd, ServicesPageWndProc);
30 hStartupPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_STARTUP_PAGE), hWnd, StartupPageWndProc);
31 hToolsPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_TOOLS_PAGE), hWnd, ToolsPageWndProc);
32
33 LoadString(hInst, IDS_MSCONFIG, szTemp, 256);
34 SetWindowText(hWnd, szTemp);
35
36 // Insert Tab Pages
37 LoadString(hInst, IDS_TAB_GENERAL, szTemp, 256);
38 memset(&item, 0, sizeof(TCITEM));
39 item.mask = TCIF_TEXT;
40 item.pszText = szTemp;
41 (void)TabCtrl_InsertItem(hTabWnd, 0, &item);
42
43 LoadString(hInst, IDS_TAB_SYSTEM, szTemp, 256);
44 memset(&item, 0, sizeof(TCITEM));
45 item.mask = TCIF_TEXT;
46 item.pszText = szTemp;
47 (void)TabCtrl_InsertItem(hTabWnd, 1, &item);
48
49 LoadString(hInst, IDS_TAB_FREELDR, szTemp, 256);
50 memset(&item, 0, sizeof(TCITEM));
51 item.mask = TCIF_TEXT;
52 item.pszText = szTemp;
53 (void)TabCtrl_InsertItem(hTabWnd, 2, &item);
54
55 LoadString(hInst, IDS_TAB_SERVICES, szTemp, 256);
56 memset(&item, 0, sizeof(TCITEM));
57 item.mask = TCIF_TEXT;
58 item.pszText = szTemp;
59 (void)TabCtrl_InsertItem(hTabWnd, 3, &item);
60
61 LoadString(hInst, IDS_TAB_STARTUP, szTemp, 256);
62 memset(&item, 0, sizeof(TCITEM));
63 item.mask = TCIF_TEXT;
64 item.pszText = szTemp;
65 (void)TabCtrl_InsertItem(hTabWnd, 4, &item);
66
67 LoadString(hInst, IDS_TAB_TOOLS, szTemp, 256);
68 memset(&item, 0, sizeof(TCITEM));
69 item.mask = TCIF_TEXT;
70 item.pszText = szTemp;
71 (void)TabCtrl_InsertItem(hTabWnd, 5, &item);
72
73 MsConfig_OnTabWndSelChange();
74
75 return TRUE;
76 }
77
78
79 void MsConfig_OnTabWndSelChange(void)
80 {
81 switch (TabCtrl_GetCurSel(hTabWnd)) {
82 case 0: //General
83 ShowWindow(hGeneralPage, SW_SHOW);
84 ShowWindow(hSystemPage, SW_HIDE);
85 ShowWindow(hFreeLdrPage, SW_HIDE);
86 ShowWindow(hServicesPage, SW_HIDE);
87 ShowWindow(hStartupPage, SW_HIDE);
88 ShowWindow(hToolsPage, SW_HIDE);
89 BringWindowToTop(hGeneralPage);
90 break;
91 case 1: //SYSTEM.INI
92 ShowWindow(hGeneralPage, SW_HIDE);
93 ShowWindow(hSystemPage, SW_SHOW);
94 ShowWindow(hToolsPage, SW_HIDE);
95 ShowWindow(hStartupPage, SW_HIDE);
96 ShowWindow(hFreeLdrPage, SW_HIDE);
97 ShowWindow(hServicesPage, SW_HIDE);
98 BringWindowToTop(hSystemPage);
99 break;
100 case 2: //Freeldr
101 ShowWindow(hGeneralPage, SW_HIDE);
102 ShowWindow(hSystemPage, SW_HIDE);
103 ShowWindow(hFreeLdrPage, SW_SHOW);
104 ShowWindow(hServicesPage, SW_HIDE);
105 ShowWindow(hStartupPage, SW_HIDE);
106 ShowWindow(hToolsPage, SW_HIDE);
107 BringWindowToTop(hFreeLdrPage);
108 break;
109 case 3: //Services
110 ShowWindow(hGeneralPage, SW_HIDE);
111 ShowWindow(hSystemPage, SW_HIDE);
112 ShowWindow(hFreeLdrPage, SW_HIDE);
113 ShowWindow(hServicesPage, SW_SHOW);
114 ShowWindow(hStartupPage, SW_HIDE);
115 ShowWindow(hToolsPage, SW_HIDE);
116 BringWindowToTop(hServicesPage);
117 break;
118 case 4: //startup
119 ShowWindow(hGeneralPage, SW_HIDE);
120 ShowWindow(hSystemPage, SW_HIDE);
121 ShowWindow(hFreeLdrPage, SW_HIDE);
122 ShowWindow(hServicesPage, SW_HIDE);
123 ShowWindow(hStartupPage, SW_SHOW);
124 ShowWindow(hToolsPage, SW_HIDE);
125 BringWindowToTop(hStartupPage);
126 break;
127 case 5: //Tools
128 ShowWindow(hGeneralPage, SW_HIDE);
129 ShowWindow(hSystemPage, SW_HIDE);
130 ShowWindow(hFreeLdrPage, SW_HIDE);
131 ShowWindow(hServicesPage, SW_HIDE);
132 ShowWindow(hStartupPage, SW_HIDE);
133 ShowWindow(hToolsPage, SW_SHOW);
134 BringWindowToTop(hToolsPage);
135 break;
136 }
137 }
138
139
140 static
141 VOID
142 SetDialogIcon(HWND hDlg)
143 {
144 if (hDialogIcon) DestroyIcon(hDialogIcon);
145
146 hDialogIcon = LoadImage(GetModuleHandle(NULL),
147 MAKEINTRESOURCE(IDI_APPICON),
148 IMAGE_ICON,
149 uXIcon,
150 uYIcon,
151 0);
152 SendMessage(hDlg,
153 WM_SETICON,
154 ICON_SMALL,
155 (LPARAM)hDialogIcon);
156 }
157
158
159 /* Message handler for dialog box. */
160 INT_PTR CALLBACK
161 MsConfigWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
162 {
163 int idctrl;
164 LPNMHDR pnmh;
165 UINT uXIconNew, uYIconNew;
166
167 switch (message)
168 {
169 case WM_INITDIALOG:
170 hMainWnd = hDlg;
171
172 uXIcon = GetSystemMetrics(SM_CXSMICON);
173 uYIcon = GetSystemMetrics(SM_CYSMICON);
174
175 SetDialogIcon(hDlg);
176
177 return OnCreate(hDlg);
178
179 case WM_SETTINGCHANGE:
180 uXIconNew = GetSystemMetrics(SM_CXSMICON);
181 uYIconNew = GetSystemMetrics(SM_CYSMICON);
182
183 if ((uXIcon != uXIconNew) || (uYIcon != uYIconNew))
184 {
185 uXIcon = uXIconNew;
186 uYIcon = uYIconNew;
187 SetDialogIcon(hDlg);
188 }
189 break;
190
191 case WM_COMMAND:
192
193 if (LOWORD(wParam) == IDOK)
194 {
195 //MsConfig_OnSaveChanges();
196 }
197
198 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
199 EndDialog(hDlg, LOWORD(wParam));
200 return TRUE;
201 }
202 break;
203
204 case WM_NOTIFY:
205 idctrl = wParam;
206 pnmh = (LPNMHDR)lParam;
207 if ((pnmh->hwndFrom == hTabWnd) &&
208 (pnmh->idFrom == IDC_TAB) &&
209 (pnmh->code == TCN_SELCHANGE))
210 {
211 MsConfig_OnTabWndSelChange();
212 }
213 break;
214
215 case WM_SYSCOLORCHANGE:
216 /* Forward WM_SYSCOLORCHANGE to common controls */
217 SendMessage(hServicesListCtrl, WM_SYSCOLORCHANGE, 0, 0);
218 SendMessage(hStartupListCtrl, WM_SYSCOLORCHANGE, 0, 0);
219 SendMessage(hToolsListCtrl, WM_SYSCOLORCHANGE, 0, 0);
220 break;
221
222 case WM_DESTROY:
223 if (hToolsPage)
224 DestroyWindow(hToolsPage);
225 if (hGeneralPage)
226 DestroyWindow(hGeneralPage);
227 if (hServicesPage)
228 DestroyWindow(hServicesPage);
229 if (hStartupPage)
230 DestroyWindow(hStartupPage);
231 if (hFreeLdrPage)
232 DestroyWindow(hFreeLdrPage);
233 if (hSystemPage)
234 DestroyWindow(hSystemPage);
235 if (hDialogIcon)
236 DestroyIcon(hDialogIcon);
237 return DefWindowProc(hDlg, message, wParam, lParam);
238 }
239
240 return 0;
241 }
242
243 int APIENTRY _tWinMain(HINSTANCE hInstance,
244 HINSTANCE hPrevInstance,
245 LPTSTR lpCmdLine,
246 int nCmdShow)
247 {
248
249 INITCOMMONCONTROLSEX InitControls;
250
251 UNREFERENCED_PARAMETER(hPrevInstance);
252 UNREFERENCED_PARAMETER(lpCmdLine);
253 UNREFERENCED_PARAMETER(nCmdShow);
254
255 InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
256 InitControls.dwICC = ICC_TAB_CLASSES | ICC_LISTVIEW_CLASSES;
257 InitCommonControlsEx(&InitControls);
258
259 hInst = hInstance;
260
261 DialogBox(hInst, (LPCTSTR)IDD_MSCONFIG_DIALOG, NULL, MsConfigWndProc);
262
263 return 0;
264 }
265
266 /* EOF */