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;
39 HINF hSetupInf
= INVALID_HANDLE_VALUE
;
40 DWORD IsUnattendedSetupEnabled
= 0;
41 DWORD UnattendLCID
= 0;
45 APPLET Applets
[NUM_APPLETS
] =
47 {IDC_CPLICON
, IDS_CPLNAME
, IDS_CPLDESCRIPTION
, Applet
}
51 PrintErrorMsgBox(UINT msg
)
53 WCHAR szErrorText
[BUFFERSIZE
];
54 WCHAR szErrorCaption
[BUFFERSIZE
];
56 LoadStringW(hApplet
, msg
, szErrorText
, sizeof(szErrorText
) / sizeof(WCHAR
));
57 LoadStringW(hApplet
, IDS_ERROR
, szErrorCaption
, sizeof(szErrorCaption
) / sizeof(WCHAR
));
59 MessageBoxW(NULL
, szErrorText
, szErrorCaption
, MB_OK
| MB_ICONERROR
);
69 WCHAR szErrorText
[BUFFERSIZE
];
70 WCHAR szErrorCaption
[BUFFERSIZE
];
72 LoadStringW(hApplet
, uMessageId
, szErrorText
, sizeof(szErrorText
) / sizeof(WCHAR
));
73 LoadStringW(hApplet
, uCaptionId
, szErrorCaption
, sizeof(szErrorCaption
) / sizeof(WCHAR
));
75 return MessageBoxW(hwnd
, szErrorText
, szErrorCaption
, uType
);
79 InitIntlPropSheetPage(PROPSHEETPAGE
*psp
, WORD idDlg
, DLGPROC DlgProc
, LPARAM lParam
)
81 ZeroMemory(psp
, sizeof(PROPSHEETPAGE
));
82 psp
->dwSize
= sizeof(PROPSHEETPAGE
);
83 psp
->dwFlags
= PSP_DEFAULT
;
84 psp
->hInstance
= hApplet
;
85 psp
->pszTemplate
= MAKEINTRESOURCE(idDlg
);
86 psp
->pfnDlgProc
= DlgProc
;
97 lpCmdLine
= GetCommandLineW();
99 lpSwitch
= wcsstr(lpCmdLine
, L
"/f:\"");
103 len
= wcslen(lpSwitch
);
104 if (len
< 5 || lpSwitch
[len
-1] != L
'\"')
106 DPRINT1("Invalid switch: %ls\n", lpSwitch
);
110 lpSwitch
[len
-1] = L
'\0';
112 hSetupInf
= SetupOpenInfFileW(&lpSwitch
[4], NULL
, INF_STYLE_OLDNT
, NULL
);
113 if (hSetupInf
== INVALID_HANDLE_VALUE
)
115 DPRINT1("Failed to open INF file: %ls\n", &lpSwitch
[4]);
125 INFCONTEXT InfContext
;
128 if (!SetupFindFirstLineW(hSetupInf
,
133 SetupCloseInfFile(hSetupInf
);
134 DPRINT1("SetupFindFirstLine failed\n");
138 if (!SetupGetStringFieldW(&InfContext
, 1, szBuffer
,
139 sizeof(szBuffer
) / sizeof(WCHAR
), NULL
))
141 SetupCloseInfFile(hSetupInf
);
142 DPRINT1("SetupGetStringField failed\n");
146 UnattendLCID
= wcstoul(szBuffer
, NULL
, 16);
147 IsUnattendedSetupEnabled
= 1;
148 SetupCloseInfFile(hSetupInf
);
152 PropSheetProc(HWND hwndDlg
, UINT uMsg
, LPARAM lParam
)
154 // NOTE: This callback is needed to set large icon correctly.
158 case PSCB_INITIALIZED
:
160 hIcon
= LoadIconW(hApplet
, MAKEINTRESOURCEW(IDC_CPLICON
));
161 SendMessageW(hwndDlg
, WM_SETICON
, ICON_BIG
, (LPARAM
)hIcon
);
169 Applet(HWND hwnd
, UINT uMsg
, LPARAM wParam
, LPARAM lParam
)
171 PROPSHEETPAGE psp
[3];
173 PGLOBALDATA pGlobalData
;
182 if (uMsg
== CPL_STARTWPARMSW
&& lParam
!= 0)
183 nPage
= _wtoi((PWSTR
)lParam
);
185 pGlobalData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(GLOBALDATA
));
186 if (pGlobalData
== NULL
)
189 pGlobalData
->SystemLCID
= GetSystemDefaultLCID();
190 pGlobalData
->bIsUserAdmin
= IsUserAdmin();
192 ZeroMemory(&psh
, sizeof(PROPSHEETHEADER
));
193 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
194 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_USEICONID
| PSH_USECALLBACK
;
195 psh
.hwndParent
= hwnd
;
196 psh
.hInstance
= hApplet
;
197 psh
.pszIcon
= MAKEINTRESOURCEW(IDC_CPLICON
);
198 psh
.pszCaption
= MAKEINTRESOURCEW(IDS_CPLNAME
);
202 psh
.pfnCallback
= PropSheetProc
;
204 InitIntlPropSheetPage(&psp
[0], IDD_GENERALPAGE
, GeneralPageProc
, (LPARAM
)pGlobalData
);
206 InitIntlPropSheetPage(&psp
[1], IDD_LANGUAGESPAGE
, LanguagesPageProc
, (LPARAM
)pGlobalData
);
209 if (pGlobalData
->bIsUserAdmin
)
211 InitIntlPropSheetPage(&psp
[2], IDD_ADVANCEDPAGE
, AdvancedPageProc
, (LPARAM
)pGlobalData
);
215 if (nPage
!= 0 && nPage
<= psh
.nPages
)
216 psh
.nStartPage
= nPage
;
218 ret
= (LONG
)(PropertySheet(&psh
) != -1);
220 SendMessageW(HWND_BROADCAST
, WM_SETTINGCHANGE
, 0, (LPARAM
)L
"intl");
222 HeapFree(GetProcessHeap(), 0, pGlobalData
);
228 /* Control Panel Callback */
230 CPlApplet(HWND hwndCpl
,
235 UINT i
= (UINT
)lParam1
;
248 CPLINFO
*CPlInfo
= (CPLINFO
*)lParam2
;
250 CPlInfo
->idIcon
= Applets
[i
].idIcon
;
251 CPlInfo
->idName
= Applets
[i
].idName
;
252 CPlInfo
->idInfo
= Applets
[i
].idDescription
;
262 Applets
[i
].AppletProc(hwndCpl
, uMsg
, lParam1
, lParam2
);
267 case CPL_STARTWPARMSW
:
269 return Applets
[i
].AppletProc(hwndCpl
, uMsg
, lParam1
, lParam2
);
278 DllMain(HINSTANCE hinstDLL
,
284 case DLL_PROCESS_ATTACH
:
285 case DLL_THREAD_ATTACH
: