CLanguageSupport.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 
10 //
11 // CLanguageSupport : Language selection support and resource DLLs management for MFC.
12 //
13 // Portions copied from:
14 // Author : Serge Wautier.
15 // Source : Code project article (http://www.codeproject.com/cpp/LanguageMenu.asp)
16 //
17 
18 // To use CLanguageSupport, link with nativewindow.lib.
19 
20 #include <afxcoll.h>
21 
22 #if !defined (DLLEXPORT)
23 #define DLLEXPORT __declspec( dllexport )
24 #endif
25 //
26 // CLanguageSupport : Language selection support and resource DLLs management for MFC.
27 //
28 // Portions copied from:
29 // Author : Serge Wautier.
30 // Source : Code project article (http://www.codeproject.com/cpp/LanguageMenu.asp)
31 // @remark Required Library: nativewindow.lib
32 // To use CLanguageSupport, link with nativewindow.lib.
33 
34 
36  {
37  public:
40 
41  DLLEXPORT void SetCurrentModule (HMODULE hModule);
42  DLLEXPORT void SetAbbrevNameFromLanguage (LPCTSTR language);
43  DLLEXPORT void SetDefaultAbbrevName (LPCTSTR abbrevName);
44  DLLEXPORT void LoadBestLanguage (); // Called on start-up to load the required language dll
45 
46  protected:
50  HMODULE m_currentModule;
51 
52  HINSTANCE m_hDll; // Satellite DLL.
53 
54  static LANGID GetLangIdFromFile (LPCTSTR pszFilename);
55  static CString GetLanguageName (LANGID wLangId);
56 
57  static LANGID GetUserUILanguage ();
58  static LANGID GetSystemUILanguage ();
59 
60  bool LoadLanguage (); // Try to load the language m_nCurrentLanguage.
61  // If it doesn't exist, try to fallback on the neutral or default sublanguage for this language.
62 
63  bool LoadLanguageDll (); // Identifies and loads the resource DLL for language m_nCurrentLanguage
64  bool LoadLanguageDllFromAbbrevName (LPCTSTR szAbbrevName);
65 
66  void LookupModuleLanguage (); // Initializes m_nModuleLanguage with the original language of the app (stored in the exe)
67 
68  void UnloadResourceDll (); // Unloads the current resource DLL (if any)
69 
70  static void SetResourceHandle (HINSTANCE hDll); // Tells MFC where the resources are stored.
71  };
static LANGID GetUserUILanguage()
static CString GetLanguageName(LANGID wLangId)
static LANGID GetLangIdFromFile(LPCTSTR pszFilename)
static LANGID GetSystemUILanguage()
LANGID m_nModuleLanguage
Definition: CLanguageSupport.h:47
void SetAbbrevNameFromLanguage(LPCTSTR language)
void SetDefaultAbbrevName(LPCTSTR abbrevName)
HANDLE HINSTANCE
Definition: msnativewindow.h:29
LANGID m_nCurrentLanguage
Definition: CLanguageSupport.h:48
static void SetResourceHandle(HINSTANCE hDll)
Definition: CLanguageSupport.h:35
#define DLLEXPORT
Definition: basedefs.h:137
bool LoadLanguageDll()
HMODULE m_currentModule
Definition: CLanguageSupport.h:50
HINSTANCE m_hDll
Definition: CLanguageSupport.h:52
void UnloadResourceDll()
void LoadBestLanguage()
bool LoadLanguageDllFromAbbrevName(LPCTSTR szAbbrevName)
void SetCurrentModule(HMODULE hModule)
void LookupModuleLanguage()
CString m_defaultAbbrevName
Definition: CLanguageSupport.h:49

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.