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