1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
void CMainFrame::SetLanguage(LANGUAGES nLanguage,UINT nID)
{
CString strBuffer = _T("");
HINSTANCE hInst = NULL;
LCID lcid = NULL;
// Store the Default resource instance
if(!m_hInstFrench)
m_hInstFrench = AfxGetInstanceHandle();
if(nLanguage == Default)
{
lcid= GetThreadLocale();
// We only want the low order 8 bits
lcid &= 0xFF;
// Evaluate what the locale is and map onto the languages we have
switch(lcid)
{
default:
case LANG_ENGLISH:
nLanguage = English;
break;
case LANG_FRENCH:
nLanguage = French;
break;
}
}
// Load the relevant resource DLL
m_nLanguage = nLanguage;
switch(nLanguage)
{
case English:
// Only call LoadLibrary once, because
// using LoadLibrary() and FreeLibrary()
// seemed to cause problems, i,e repeatedly
// removing the library after use, in VC++ 6.0 & NT 4.0
if(!m_hInstEnglish)
m_hInstEnglish = LoadLibrary(_T("LangEng.dll"));
hInst = m_hInstEnglish;
break;
}
// If we have succesfully loaded a resource DLL, use it, otherwise
// load the resources from the EXE
if(hInst)
AfxSetResourceHandle(hInst);
else
AfxSetResourceHandle(m_hInstFrench);
// we MUST get a handle to the menu in the Mainframe
// YOU may need to use a pointer to the Frame:-
// CMainFrame* pFrame = (CMainFrame *) AfxGetApp()->m_pMainWnd;
// i.e. pFrame->GetMenu()
// pFrame->m_hMenu()
//
// Or without using CMainFrame, using Win32 calls
// HMENU hMenu= ::GetMenu(AfxGetApp()->m_pMainWnd->GetSafeHwnd());
// CMenu *pMenuCurrent = CMenu::FromHandle(hMenu);
CMenu *pMenuCurrent;
/*if(pDocFrame)
pMenuCurrent= pDocFrame->GetMenu();
else*/
pMenuCurrent= GetMenu();
// Create a new menu instance, we need to use this in SetMenu
m_pMenuNew = new CMenu;
// has the menu changed?
// m_hMenuDefault is the default menu resource for this frame see AFXWIN.H
if(pMenuCurrent->m_hMenu != m_hMenuDefault)
{
// Destroy the "New" menu and delete the resource
// We, after all created it!
pMenuCurrent->DestroyMenu();
//delete pMenuCurrent;
}
// Load our new resource menu
m_pMenuNew->LoadMenu(nID);
// Display the new menu
SetMenu(m_pMenuNew);
// Update any other text strings that are displayed
// e.g. The Status bar
strBuffer.LoadString(AFX_IDS_IDLEMESSAGE);
m_wndStatusBar.SetPaneText(0, strBuffer);
// We need to change the accelerators
// m_hAccelTable is used in Winfrm.cpp as the accelerator handle,
// only one accelerator can be loaded at a time so we MUST clear it
m_hAccelTable = NULL;
//if(!LoadAccelTable(MAKEINTRESOURCE(IDR_MAINFRAME)))
// ReportError(_T("LoadAccelTable(MAKEINTRESOURCE(IDR_MAINFRAME)"), GetLastError());
} |
Partager