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 
10 #include "precomp.h"
11 
12 #include "toolspage.h"
13 #include "srvpage.h"
14 #include "startuppage.h"
15 #include "freeldrpage.h"
16 #include "systempage.h"
17 #include "generalpage.h"
18 
19 HINSTANCE hInst = 0;
20 
21 HWND hMainWnd;                   /* Main Window */
22 HWND hTabWnd;                    /* Tab Control Window */
23 UINT uXIcon = 0, uYIcon = 0;     /* Icon sizes */
24 HICON hDialogIcon = NULL;
25 
26 void MsConfig_OnTabWndSelChange(void);
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 // Taken from WinSpy++ 1.7
30 // http://www.catch22.net/software/winspy
31 // Copyright (c) 2002 by J Brown
32 //
33 
34 //
35 //	Copied from uxtheme.h
36 //  If you have this new header, then delete these and
37 //  #include <uxtheme.h> instead!
38 //
39 #define ETDT_DISABLE        0x00000001
40 #define ETDT_ENABLE         0x00000002
41 #define ETDT_USETABTEXTURE  0x00000004
42 #define ETDT_ENABLETAB      (ETDT_ENABLE  | ETDT_USETABTEXTURE)
43 
44 //
45 typedef HRESULT (WINAPI * ETDTProc) (HWND, DWORD);
46 
47 //
48 //	Try to call EnableThemeDialogTexture, if uxtheme.dll is present
49 //
50 BOOL EnableDialogTheme(HWND hwnd)
51 {
52     HMODULE hUXTheme;
53     ETDTProc fnEnableThemeDialogTexture;
54 
55     hUXTheme = LoadLibrary(_T("uxtheme.dll"));
56 
57     if(hUXTheme)
58     {
59         fnEnableThemeDialogTexture =
60             (ETDTProc)GetProcAddress(hUXTheme, "EnableThemeDialogTexture");
61 
62         if(fnEnableThemeDialogTexture)
63         {
64             fnEnableThemeDialogTexture(hwnd, ETDT_ENABLETAB);
65 
66             FreeLibrary(hUXTheme);
67             return TRUE;
68         }
69         else
70         {
71             // Failed to locate API!
72             FreeLibrary(hUXTheme);
73             return FALSE;
74         }
75     }
76     else
77     {
78         // Not running under XP? Just fail gracefully
79         return FALSE;
80     }
81 }
82 BOOL OnCreate(HWND hWnd)
83 {
84     TCHAR   szTemp[256];
85     TCITEM  item;
86 
87     hTabWnd = GetDlgItem(hWnd, IDC_TAB);
88     hGeneralPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_GENERAL_PAGE), hWnd,  GeneralPageWndProc); EnableDialogTheme(hGeneralPage);
89     hSystemPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SYSTEM_PAGE), hWnd,  SystemPageWndProc); EnableDialogTheme(hSystemPage);
90     hFreeLdrPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_FREELDR_PAGE), hWnd,  FreeLdrPageWndProc); EnableDialogTheme(hFreeLdrPage);
91     hServicesPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SERVICES_PAGE), hWnd,  ServicesPageWndProc); EnableDialogTheme(hServicesPage);
92     hStartupPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_STARTUP_PAGE), hWnd,  StartupPageWndProc); EnableDialogTheme(hStartupPage);
93     hToolsPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_TOOLS_PAGE), hWnd,  ToolsPageWndProc); EnableDialogTheme(hToolsPage);
94 
95     LoadString(hInst, IDS_MSCONFIG, szTemp, 256);
96     SetWindowText(hWnd, szTemp);
97 
98     // Insert Tab Pages
99     LoadString(hInst, IDS_TAB_GENERAL, szTemp, 256);
100     memset(&item, 0, sizeof(TCITEM));
101     item.mask = TCIF_TEXT;
102     item.pszText = szTemp;
103     (void)TabCtrl_InsertItem(hTabWnd, 0, &item);
104 
105     LoadString(hInst, IDS_TAB_SYSTEM, szTemp, 256);
106     memset(&item, 0, sizeof(TCITEM));
107     item.mask = TCIF_TEXT;
108     item.pszText = szTemp;
109     (void)TabCtrl_InsertItem(hTabWnd, 1, &item);
110 
111     LoadString(hInst, IDS_TAB_FREELDR, szTemp, 256);
112     memset(&item, 0, sizeof(TCITEM));
113     item.mask = TCIF_TEXT;
114     item.pszText = szTemp;
115     (void)TabCtrl_InsertItem(hTabWnd, 2, &item);
116 
117     LoadString(hInst, IDS_TAB_SERVICES, szTemp, 256);
118     memset(&item, 0, sizeof(TCITEM));
119     item.mask = TCIF_TEXT;
120     item.pszText = szTemp;
121     (void)TabCtrl_InsertItem(hTabWnd, 3, &item);
122 
123     LoadString(hInst, IDS_TAB_STARTUP, szTemp, 256);
124     memset(&item, 0, sizeof(TCITEM));
125     item.mask = TCIF_TEXT;
126     item.pszText = szTemp;
127     (void)TabCtrl_InsertItem(hTabWnd, 4, &item);
128 
129     LoadString(hInst, IDS_TAB_TOOLS, szTemp, 256);
130     memset(&item, 0, sizeof(TCITEM));
131     item.mask = TCIF_TEXT;
132     item.pszText = szTemp;
133     (void)TabCtrl_InsertItem(hTabWnd, 5, &item);
134 
135     MsConfig_OnTabWndSelChange();
136 
137     return TRUE;
138 }
139 
140 
141 void MsConfig_OnTabWndSelChange(void)
142 {
143     switch (TabCtrl_GetCurSel(hTabWnd)) {
144     case 0: //General
145         ShowWindow(hGeneralPage, SW_SHOW);
146         ShowWindow(hSystemPage, SW_HIDE);
147         ShowWindow(hFreeLdrPage, SW_HIDE);
148         ShowWindow(hServicesPage, SW_HIDE);
149         ShowWindow(hStartupPage, SW_HIDE);
150         ShowWindow(hToolsPage, SW_HIDE);
151         BringWindowToTop(hGeneralPage);
152         break;
153     case 1: //SYSTEM.INI
154         ShowWindow(hGeneralPage, SW_HIDE);
155         ShowWindow(hSystemPage, SW_SHOW);
156         ShowWindow(hToolsPage, SW_HIDE);
157         ShowWindow(hStartupPage, SW_HIDE);
158         ShowWindow(hFreeLdrPage, SW_HIDE);
159         ShowWindow(hServicesPage, SW_HIDE);
160         BringWindowToTop(hSystemPage);
161         break;
162     case 2: //Freeldr
163         ShowWindow(hGeneralPage, SW_HIDE);
164         ShowWindow(hSystemPage, SW_HIDE);
165         ShowWindow(hFreeLdrPage, SW_SHOW);
166         ShowWindow(hServicesPage, SW_HIDE);
167         ShowWindow(hStartupPage, SW_HIDE);
168         ShowWindow(hToolsPage, SW_HIDE);
169         BringWindowToTop(hFreeLdrPage);
170         break;
171     case 3: //Services
172         ShowWindow(hGeneralPage, SW_HIDE);
173         ShowWindow(hSystemPage, SW_HIDE);
174         ShowWindow(hFreeLdrPage, SW_HIDE);
175         ShowWindow(hServicesPage, SW_SHOW);
176         ShowWindow(hStartupPage, SW_HIDE);
177         ShowWindow(hToolsPage, SW_HIDE);
178         BringWindowToTop(hServicesPage);
179         break;
180     case 4: //startup
181         ShowWindow(hGeneralPage, SW_HIDE);
182         ShowWindow(hSystemPage, SW_HIDE);
183         ShowWindow(hFreeLdrPage, SW_HIDE);
184         ShowWindow(hServicesPage, SW_HIDE);
185         ShowWindow(hStartupPage, SW_SHOW);
186         ShowWindow(hToolsPage, SW_HIDE);
187         BringWindowToTop(hStartupPage);
188         break;
189     case 5: //Tools
190         ShowWindow(hGeneralPage, SW_HIDE);
191         ShowWindow(hSystemPage, SW_HIDE);
192         ShowWindow(hFreeLdrPage, SW_HIDE);
193         ShowWindow(hServicesPage, SW_HIDE);
194         ShowWindow(hStartupPage, SW_HIDE);
195         ShowWindow(hToolsPage, SW_SHOW);
196         BringWindowToTop(hToolsPage);
197         break;
198     }
199 }
200 
201 
202 static
203 VOID
204 SetDialogIcon(HWND hDlg)
205 {
206     if (hDialogIcon) DestroyIcon(hDialogIcon);
207 
208     hDialogIcon = LoadImage(GetModuleHandle(NULL),
209                             MAKEINTRESOURCE(IDI_APPICON),
210                             IMAGE_ICON,
211                             uXIcon,
212                             uYIcon,
213                             0);
214     SendMessage(hDlg,
215                 WM_SETICON,
216                 ICON_SMALL,
217                 (LPARAM)hDialogIcon);
218 }
219 
220 
221 /* Message handler for dialog box. */
222 INT_PTR CALLBACK
223 MsConfigWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
224 {
225     LPNMHDR         pnmh;
226     UINT            uXIconNew, uYIconNew;
227 
228     switch (message)
229     {
230         case WM_INITDIALOG:
231             hMainWnd = hDlg;
232 
233             uXIcon = GetSystemMetrics(SM_CXSMICON);
234             uYIcon = GetSystemMetrics(SM_CYSMICON);
235 
236             SetDialogIcon(hDlg);
237 
238             return OnCreate(hDlg);
239 
240         case WM_SETTINGCHANGE:
241             uXIconNew = GetSystemMetrics(SM_CXSMICON);
242             uYIconNew = GetSystemMetrics(SM_CYSMICON);
243 
244             if ((uXIcon != uXIconNew) || (uYIcon != uYIconNew))
245             {
246                 uXIcon = uXIconNew;
247                 uYIcon = uYIconNew;
248                 SetDialogIcon(hDlg);
249             }
250             break;
251 
252         case WM_COMMAND:
253 
254             if (LOWORD(wParam) == IDOK)
255             {
256                 //MsConfig_OnSaveChanges();
257             }
258 
259             if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
260                 EndDialog(hDlg, LOWORD(wParam));
261                 return TRUE;
262             }
263             break;
264 
265         case WM_NOTIFY:
266             pnmh = (LPNMHDR)lParam;
267             if ((pnmh->hwndFrom == hTabWnd) &&
268                 (pnmh->idFrom == IDC_TAB) &&
269                 (pnmh->code == TCN_SELCHANGE))
270             {
271                 MsConfig_OnTabWndSelChange();
272             }
273             break;
274 
275         case WM_SYSCOLORCHANGE:
276             /* Forward WM_SYSCOLORCHANGE to common controls */
277             SendMessage(hServicesListCtrl, WM_SYSCOLORCHANGE, 0, 0);
278             SendMessage(hStartupListCtrl, WM_SYSCOLORCHANGE, 0, 0);
279             SendMessage(hToolsListCtrl, WM_SYSCOLORCHANGE, 0, 0);
280             break;
281 
282         case WM_DESTROY:
283             if (hToolsPage)
284                 DestroyWindow(hToolsPage);
285             if (hGeneralPage)
286                 DestroyWindow(hGeneralPage);
287             if (hServicesPage)
288                 DestroyWindow(hServicesPage);
289             if (hStartupPage)
290                 DestroyWindow(hStartupPage);
291             if (hFreeLdrPage)
292                 DestroyWindow(hFreeLdrPage);
293             if (hSystemPage)
294                 DestroyWindow(hSystemPage);
295             if (hDialogIcon)
296                 DestroyIcon(hDialogIcon);
297             return DefWindowProc(hDlg, message, wParam, lParam);
298     }
299 
300     return 0;
301 }
302 
303 int APIENTRY _tWinMain(HINSTANCE hInstance,
304                        HINSTANCE hPrevInstance,
305                        LPTSTR    lpCmdLine,
306                        int       nCmdShow)
307 {
308 
309     INITCOMMONCONTROLSEX InitControls;
310 
311     UNREFERENCED_PARAMETER(hPrevInstance);
312     UNREFERENCED_PARAMETER(lpCmdLine);
313     UNREFERENCED_PARAMETER(nCmdShow);
314 
315     InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
316     InitControls.dwICC = ICC_TAB_CLASSES | ICC_LISTVIEW_CLASSES;
317     InitCommonControlsEx(&InitControls);
318 
319     hInst = hInstance;
320 
321     DialogBox(hInst, (LPCTSTR)IDD_MSCONFIG_DIALOG, NULL,  MsConfigWndProc);
322 
323     return 0;
324 }
325 
326 /* EOF */
327