3 * Copyright (C) 2004 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * PROJECT: ReactOS International Control Panel
21 * FILE: dll/cpl/intl/intl.c
22 * PURPOSE: Property sheet code
23 * PROGRAMMER: Eric Kohl
30 #define NUM_APPLETS (1)
32 #define BUFFERSIZE 512
35 Applet(HWND hwnd
, UINT uMsg
, LPARAM wParam
, LPARAM lParam
);
38 HINSTANCE hApplet
= 0;
40 HINF hSetupInf
= INVALID_HANDLE_VALUE
;
41 DWORD IsUnattendedSetupEnabled
= 0;
42 DWORD UnattendLCID
= 0;
46 APPLET Applets
[NUM_APPLETS
] =
48 {IDC_CPLICON
, IDS_CPLNAME
, IDS_CPLDESCRIPTION
, Applet
}
52 PrintErrorMsgBox(UINT msg
)
54 WCHAR szErrorText
[BUFFERSIZE
];
55 WCHAR szErrorCaption
[BUFFERSIZE
];
57 LoadStringW(hApplet
, msg
, szErrorText
, sizeof(szErrorText
) / sizeof(WCHAR
));
58 LoadStringW(hApplet
, IDS_ERROR
, szErrorCaption
, sizeof(szErrorCaption
) / sizeof(WCHAR
));
60 MessageBoxW(NULL
, szErrorText
, szErrorCaption
, MB_OK
| MB_ICONERROR
);
70 WCHAR szErrorText
[BUFFERSIZE
];
71 WCHAR szErrorCaption
[BUFFERSIZE
];
73 LoadStringW(hApplet
, uMessageId
, szErrorText
, sizeof(szErrorText
) / sizeof(WCHAR
));
74 LoadStringW(hApplet
, uCaptionId
, szErrorCaption
, sizeof(szErrorCaption
) / sizeof(WCHAR
));
76 return MessageBoxW(hwnd
, szErrorText
, szErrorCaption
, uType
);
80 InitPropSheetPage(PROPSHEETPAGE
*psp
, WORD idDlg
, DLGPROC DlgProc
, LPARAM lParam
)
82 ZeroMemory(psp
, sizeof(PROPSHEETPAGE
));
83 psp
->dwSize
= sizeof(PROPSHEETPAGE
);
84 psp
->dwFlags
= PSP_DEFAULT
;
85 psp
->hInstance
= hApplet
;
86 psp
->pszTemplate
= MAKEINTRESOURCE(idDlg
);
87 psp
->pfnDlgProc
= DlgProc
;
98 lpCmdLine
= GetCommandLineW();
100 lpSwitch
= wcsstr(lpCmdLine
, L
"/f:\"");
104 len
= wcslen(lpSwitch
);
105 if (len
< 5 || lpSwitch
[len
-1] != L
'\"')
107 DPRINT1("Invalid switch: %ls\n", lpSwitch
);
111 lpSwitch
[len
-1] = L
'\0';
113 hSetupInf
= SetupOpenInfFileW(&lpSwitch
[4], NULL
, INF_STYLE_OLDNT
, NULL
);
114 if (hSetupInf
== INVALID_HANDLE_VALUE
)
116 DPRINT1("Failed to open INF file: %ls\n", &lpSwitch
[4]);
126 INFCONTEXT InfContext
;
129 if (!SetupFindFirstLineW(hSetupInf
,
134 SetupCloseInfFile(hSetupInf
);
135 DPRINT1("SetupFindFirstLine failed\n");
139 if (!SetupGetStringFieldW(&InfContext
, 1, szBuffer
,
140 sizeof(szBuffer
) / sizeof(WCHAR
), NULL
))
142 SetupCloseInfFile(hSetupInf
);
143 DPRINT1("SetupGetStringField failed\n");
147 UnattendLCID
= wcstoul(szBuffer
, NULL
, 16);
148 IsUnattendedSetupEnabled
= 1;
149 SetupCloseInfFile(hSetupInf
);
153 Applet(HWND hwnd
, UINT uMsg
, LPARAM wParam
, LPARAM lParam
)
155 TCHAR Caption
[BUFFERSIZE
];
156 PROPSHEETPAGE psp
[3];
158 PGLOBALDATA pGlobalData
;
166 pGlobalData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(GLOBALDATA
));
167 if (pGlobalData
== NULL
)
170 pGlobalData
->SystemLCID
= GetSystemDefaultLCID();
171 pGlobalData
->bIsUserAdmin
= IsUserAdmin();
173 LoadString(hApplet
, IDS_CPLNAME
, Caption
, sizeof(Caption
) / sizeof(TCHAR
));
175 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
176 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
177 psh
.dwFlags
= PSH_PROPSHEETPAGE
;
178 psh
.hwndParent
= hCPLWindow
;
179 psh
.hInstance
= hApplet
;
180 psh
.hIcon
= LoadIcon(hApplet
, MAKEINTRESOURCE(IDC_CPLICON
));
181 psh
.pszCaption
= Caption
;
182 psh
.nPages
= 0; //sizeof(psp) / sizeof(PROPSHEETPAGE);
186 InitPropSheetPage(&psp
[0], IDD_GENERALPAGE
, GeneralPageProc
, (LPARAM
)pGlobalData
);
188 InitPropSheetPage(&psp
[1], IDD_LANGUAGESPAGE
, LanguagesPageProc
, (LPARAM
)pGlobalData
);
191 if (pGlobalData
->bIsUserAdmin
)
193 InitPropSheetPage(&psp
[2], IDD_ADVANCEDPAGE
, AdvancedPageProc
, (LPARAM
)pGlobalData
);
197 ret
= (LONG
)(PropertySheet(&psh
) != -1);
199 HeapFree(GetProcessHeap(), 0, pGlobalData
);
205 /* Control Panel Callback */
207 CPlApplet(HWND hwndCpl
,
222 CPLINFO
*CPlInfo
= (CPLINFO
*)lParam2
;
223 UINT uAppIndex
= (UINT
)lParam1
;
226 CPlInfo
->idIcon
= Applets
[uAppIndex
].idIcon
;
227 CPlInfo
->idName
= Applets
[uAppIndex
].idName
;
228 CPlInfo
->idInfo
= Applets
[uAppIndex
].idDescription
;
234 UINT uAppIndex
= (UINT
)lParam1
;
235 hCPLWindow
= hwndCpl
;
236 Applets
[uAppIndex
].AppletProc(hwndCpl
, uMsg
, lParam1
, lParam2
);
246 DllMain(HINSTANCE hinstDLL
,
252 case DLL_PROCESS_ATTACH
:
253 case DLL_THREAD_ATTACH
: