home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
msj
/
v10n04
/
multilin.exe
/
TRANSLAT.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-01
|
8KB
|
276 lines
// translat.cpp : implementation file
//
#include "stdafx.h"
#include "global.h"
#include "translat.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTranslations dialog
CTranslations::CTranslations(CWnd* pParent /*=NULL*/)
: CDialog(CTranslations::IDD, pParent)
{
//{{AFX_DATA_INIT(CTranslations)
m_SysTrans = _T("");
//}}AFX_DATA_INIT
}
void CTranslations::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTranslations)
DDX_Text(pDX, IDC_SYSTRANS, m_SysTrans);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTranslations, CDialog)
//{{AFX_MSG_MAP(CTranslations)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTranslations message handlers
#define GT_SYSTEMFILE TRUE
typedef UINT CPID; // code page identifier
BOOL GetTranslations(
CString &str, // reference to string variable
LPTSTR lpszFile, // address of filename
BOOL fSysDir // True if in System directory
)
{
DWORD dwHandle=0; // unused parameter for some APIs,must be 0
const int cchSysDir = MAX_PATH;
TCHAR * lpszSysDir = new TCHAR[cchSysDir];
// if file is a system file, look in system directory
if(fSysDir)
{
UINT cchActual = GetSystemDirectory(lpszSysDir, cchSysDir);
if( cchActual >= cchSysDir + _tcslen(lpszFile) )
{
// Not enough space for system dir path
} else {
lpszSysDir = _tcscat(lpszSysDir, TEXT("\\"));
lpszFile = _tcscat(lpszSysDir, lpszFile);
}
}
DWORD cbBuf=GetFileVersionInfoSize(
lpszFile, // address of filename
&dwHandle // always set to zero
);
BYTE * lpvData = new BYTE[cbBuf];
if(!lpvData)
{
// memory allocation failed
return FALSE;
}
BOOL rc = GetFileVersionInfo(
lpszFile, // address of filename
dwHandle, // ignored
cbBuf, // size of buffer
lpvData // address of buffer for file-version info.
);
// VerQueryValue returns pairs of Language/characterset information
// (need to use debug to get the exact format)
UINT cbTrans = 0;
DWORD *lpdwTrans = NULL;
if(!(rc= VerQueryValue(lpvData,_T("\\VarFileInfo\\Translation"), (VOID**)&lpdwTrans, &cbTrans)))
{
DWORD dwerr = GetLastError();
}
else
{
// Get the language name for
for(int i = cbTrans/sizeof(DWORD); i > 0; --i) // each language
{
LCID lcid = LOWORD(lpdwTrans[i-1]);
#if 0
CPID cpid = HIWORD(lpdwTrans[i-1]);
LCIDToCString(lcid, str);
#else
UINT cchLangName = 32;
DWORD cchActual = VerLanguageName(lcid,
str.GetBufferSetLength(cchLangName),
cchLangName);
if( cchActual > cchLangName )
{
// Language name doesn't fit the buffer
}
// Add name to listbox
{
}
#endif
}
}
delete []lpszSysDir;
delete []lpvData;
return TRUE; // for now
}
/////////////////////
// The following code will locate all the available languages for a resource,
// no matter whether you are using resources in separate DLLs, resources in
// the EXE, or both. This example assumes that the DLLs follow the naming
// convention from the earlier example. With a sufficiently unique combination
// of resource name and type as a flag you could search for your DLLs anywhere
// on the path, no matter what their names.
BOOL CALLBACK EnumResLangProc(
HINSTANCE hModule, // resource-module handle
LPCTSTR lpszType, // address of resource type
LPCTSTR lpszName, // address of resource name
LANGID wIDLanguage, // resource language identifier
LPARAM lParam) // application-defined parameter
{
PLBDATA pLBData = (PLBDATA)lParam;
static TCHAR szItemText[ NAMESTART + MAX_PATH];
// Display language ID components in the list
// box text. The format of the text will be:
// PriLang SubLang - File Name
wsprintf( szItemText, TEXT("%#02x %#02x - "),
PRIMARYLANGID(wIDLanguage),
SUBLANGID(wIDLanguage));
// Append the name of the file containing the
// resource.
if ( GetModuleFileName( hModule,
&szItemText[ lstrlen( szItemText)],
MAX_PATH) > 0 )
{
// Add the line to the list box
::SendDlgItemMessage( pLBData->hWnd, pLBData->nListBox, LB_ADDSTRING,
0, (LPARAM)szItemText);
}
else
{ // Send reason for the failure of the
// GetModuleFileName call back to our caller.
pLBData->dwErrCode = GetLastError();
}
// If this call failed, cause the enumeration
// process in EnumResourceLanguages to halt.
return( pLBData->dwErrCode == ERROR_SUCCESS ? TRUE : FALSE);
}
///////////////////////////
// MyFindAllLanguages
//
// Fill the given list box with the languages in which the given resource is
// available. This function will add the data to the given list box. No
// assumption is made about any of the list box's attributes (sorted, etc.).
// This function first empties the list box.
//
// Return code is ERROR_SUCCESS if successful or restults of GetLastError().
DWORD CTranslations::FindTranslationsOf(
LPCTSTR lpszType, // Name or ID number of resource type to be enum'd
LPCTSTR lpszName) // Name or ID number of resource name to be enum'd
{
// make sure the list box is empty
LBDATA lbData;
lbData.hWnd = m_hWnd; // Fill in the LBData fields so the
lbData.nListBox = IDC_APPTRANS; // data gets sent to EnumResLangProc
lbData.dwErrCode = ERROR_SUCCESS; // Assume we will be successful
SendDlgItemMessage( lbData.nListBox, LB_RESETCONTENT, 0, 0);
WIN32_FIND_DATA ffd; // for info from Find{First,Next}File
HANDLE hFind = FindFirstFile(TEXT("???.DLL"), &ffd);
if ( hFind != INVALID_HANDLE_VALUE )
{
do
{
HINSTANCE hModule = LoadLibrary( ffd.cFileName);
if ( ! EnumResourceLanguages(hModule, // Look in the .DLL
lpszType, // Given resource type
lpszName, // Given resource name
(ENUMRESLANGPROC)
EnumResLangProc, // address of callback function
(LPARAM)&lbData) ) // application-defined parameter
{
lbData.dwErrCode = GetLastError();
}
FreeLibrary(hModule);
} while( lbData.dwErrCode == ERROR_SUCCESS
&& FindNextFile(hFind, &ffd) );
FindClose( hFind );
}
else
{
lbData.dwErrCode = GetLastError();
}
if ( lbData.dwErrCode == ERROR_SUCCESS
|| lbData.dwErrCode == ERROR_FILE_NOT_FOUND )
{
lbData.dwErrCode = ERROR_SUCCESS;
if ( ! EnumResourceLanguages( NULL, // look in current EXE
lpszType, // Given resource type
lpszName, // Given resource name
(ENUMRESLANGPROC)
EnumResLangProc,// callback function
(LPARAM)&lbData) )
{
lbData.dwErrCode = GetLastError();
}
}
return( lbData.dwErrCode);
}
BOOL CTranslations::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
// Translations field
BOOL rcgt= GetTranslations(m_SysTrans, _T("Kernel32.DLL"), GT_SYSTEMFILE);
// Additional translations
DWORD dwRetCode = FindTranslationsOf( MAKEINTRESOURCE( RT_MENU),
MAKEINTRESOURCE( IDR_MAINFRAME));
/*-----
rcgt= GetTranslations(m_UserTrans,_T("Global.EXE"), !GT_SYSTEMFILE);
--*/
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}