home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
msj
/
v10n04
/
multilin.exe
/
LANGLIST.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-01
|
8KB
|
285 lines
// langlist.cpp : implementation file
//
#include "stdafx.h"
#include "global.h"
#include "langlist.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
BOOL GetLocaleName(LCID lcid, CString& str, PLANGVALS pLangVals)
{
// Obtain required buffer size
int cchData = GetLocaleInfo( lcid, pLangVals->lctLanguageForm, NULL, 0) + 2;
cchData += GetLocaleInfo( lcid, pLangVals->lctCountryForm, NULL, 0);
if( cchData < 3) // LocaleInfo failed both times
{
str += "<No entry>";
return FALSE;
}
else
{
LPTSTR lpzLang = str.GetBufferSetLength(cchData);
int cch = GetLocaleInfo( lcid,
pLangVals->lctLanguageForm,
lpzLang,
cchData-3);
str.ReleaseBuffer(-1);
str+= TEXT(" - ");
lpzLang = str.GetBufferSetLength(cchData);
cch += 3;
GetLocaleInfo( lcid,
pLangVals->lctCountryForm,
lpzLang + (cch-1),
cchData - (cch-1));
str.ReleaseBuffer(-1);
return TRUE;
}
}
//.............................................................................
// Callback function for enumerating the system's locals
PLANGVALS pLangVals = NULL;
BOOL CALLBACK EnumLocalesProc( LPTSTR lpzLocale)
{
BOOL fRC = FALSE; // Assume failure
LCID lcid = 0; // For LCID value.
// translate locale string to lcid value.
int cchData = _stscanf( lpzLocale, TEXT("%x"), &lcid);
if ( cchData > 0 )
{ // Build the string from lang and ctry names.
CString str;
GetLocaleName(lcid, str, pLangVals);
// fill the listbox
int lid = SendDlgItemMessage( pLangVals->hwndDlg,
IDC_LANGLIST,
LB_ADDSTRING,
0,
(LPARAM)(LPCTSTR)str);
SendDlgItemMessage( pLangVals->hwndDlg,
IDC_LANGLIST,
LB_SETITEMDATA,
lid,
lcid);
fRC = TRUE;
}
return fRC;
}
//.............................................................................
VOID CLanglist::LoadLanguageListBox( )
{
pLangVals = &m_LangVals;
m_LangVals.hwndDlg = m_hWnd;
SendDlgItemMessage( IDC_LANGLIST, LB_RESETCONTENT, 0, 0);
EnumSystemLocales( (LOCALE_ENUMPROC)EnumLocalesProc,
m_LangVals.dwInstalledForm);
// rotate current locale into view
CString str;
GetLocaleName(GetUserDefaultLCID(), str, pLangVals);
int lid = SendDlgItemMessage(
IDC_LANGLIST,
LB_FINDSTRING,
0,
(LPARAM)(LPCTSTR)str);
SendDlgItemMessage( IDC_LANGLIST,
LB_SETCURSEL,
lid,
0);
}
///////////////////////////////
// LoadLanguage
//
// Load a language module. This function assumes that the language modules
// to load are .DLLs and further that those .DLLs use a naming convention
// in which the base name of the file is the three characters used in
// Windows NT as the abbreviation for a language name (e.g., deu==German).
//
// Returns TRUE if module loaded, else FALSE
BOOL LoadLanguage(
LCID lcid) // Locale ID
{
SetThreadLocale( lcid); // Change thread locale
// Get the handle to the current resource DLL and free it
HINSTANCE hInstRes = AfxGetResourceHandle();
HINSTANCE hInst = AfxGetInstanceHandle();
if( hInstRes != hInst)
{
FreeLibrary(hInstRes);
// Set resource handle to current Exe
AfxSetResourceHandle(hInst);
}
// Get the file name and try to load resource DLL
TCHAR lpszLang[4];
GetLocaleInfo( lcid, LOCALE_SABBREVLANGNAME, lpszLang, 4);
if ( (int)(hInstRes = LoadLibrary( lpszLang)) < HINSTANCE_ERROR )
{
// We didn't get an exact match. Try the default sublanguage
// first
lcid = MAKELANGID( PRIMARYLANGID( lcid), SUBLANG_DEFAULT);
GetLocaleInfo( lcid, LOCALE_SABBREVLANGNAME, lpszLang, 4);
if( (int)(hInstRes=LoadLibrary(lpszLang)) < HINSTANCE_ERROR )
{
// wildcard search for any sublanguage
lpszLang[3] = _T('?');
WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(lpszLang, &ffd);
if ( hFind != INVALID_HANDLE_VALUE )
{
do
{
hInstRes = LoadLibrary( ffd.cFileName) ;
} while( (int) hInstRes < HINSTANCE_ERROR
&& FindNextFile(hFind, &ffd) );
FindClose( hFind );
}
}
// Execise: look for English before giving up
if( (int)(hInstRes) < HINSTANCE_ERROR )
{
// nothing found, use EXE file for resources
return( FALSE);
}
}
// If we get here we got a resource DLL matching the requested
// language and tell MFC to use it
AfxSetResourceHandle(hInstRes);
return( TRUE); // announce success
}
/////////////////////////////////////////////////////////////////////////////
// CLanglist dialog
CLanglist::CLanglist(CWnd* pParent /*=NULL*/)
: CDialog(CLanglist::IDD, pParent)
{
//{{AFX_DATA_INIT(CLanglist)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CLanglist::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLanglist)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLanglist, CDialog)
//{{AFX_MSG_MAP(CLanglist)
ON_BN_CLICKED(IDC_RADIOENGLISH, OnRadioEnglish)
ON_BN_CLICKED(IDC_RADIOLOCALIZED, OnRadioLocalized)
ON_BN_CLICKED(IDC_RADIONATIVE, OnRadioNative)
ON_BN_CLICKED(IDC_CHECKINSTALLED, OnCheckInstalled)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLanglist message handlers
BOOL CLanglist::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_LangVals.dwInstalledForm = LCID_INSTALLED;
m_LangVals.lctLanguageForm = LOCALE_SENGLANGUAGE;
m_LangVals.lctCountryForm = LOCALE_SENGCOUNTRY;
// m_LangVals.lctLanguageForm = LOCALE_SNATIVELANGNAME;
// m_LangVals.lctCountryForm = LOCALE_SNATIVECTRYNAME;
CheckDlgButton( IDC_CHECKINSTALLED,
(m_LangVals.dwInstalledForm == LCID_INSTALLED
? TRUE : FALSE));
CheckRadioButton( IDC_RADIOENGLISH,
IDC_RADIONATIVE,
IDC_RADIOENGLISH
);
LoadLanguageListBox();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CLanglist::OnRadioEnglish()
{
// TODO: Add your control notification handler code here
m_LangVals.lctLanguageForm = LOCALE_SENGLANGUAGE;
m_LangVals.lctCountryForm = LOCALE_SENGCOUNTRY;
LoadLanguageListBox();
}
void CLanglist::OnRadioLocalized()
{
// TODO: Add your control notification handler code here
m_LangVals.lctLanguageForm = LOCALE_SLANGUAGE;
m_LangVals.lctCountryForm = LOCALE_SCOUNTRY;
LoadLanguageListBox();
}
void CLanglist::OnRadioNative()
{
// TODO: Add your control notification handler code here
m_LangVals.lctLanguageForm = LOCALE_SNATIVELANGNAME;
m_LangVals.lctCountryForm = LOCALE_SNATIVECTRYNAME;
LoadLanguageListBox();
}
void CLanglist::OnCheckInstalled()
{
// TODO: Add your control notification handler code here
m_LangVals.dwInstalledForm =
(IsDlgButtonChecked(IDC_CHECKINSTALLED))
? LCID_INSTALLED : LCID_SUPPORTED;
LoadLanguageListBox();
}
void CLanglist::OnOK()
{
int i = SendDlgItemMessage( IDC_LANGLIST,
LB_GETCARETINDEX, 0, 0);
LCID lcid = SendDlgItemMessage( IDC_LANGLIST,
LB_GETITEMDATA, i, 0);
LoadLanguage( lcid);
// TODO: Add extra validation here
CDialog::OnOK();
}