2014-02-18 227 views

回答

0

下面是关于如何使用“EnumSystemLocales”的例子:

#include <windows.h> 
#include <tchar.h> 
#include <stdio.h> 

BOOL CALLBACK MyLocaleEnumProc(LPTSTR szLocaleString) 
{ 
    _tprintf(_T("%s\r\n"), szLocaleString); 
    return TRUE; 
} 

int _tmain() 
{ 
    EnumSystemLocales(&MyLocaleEnumProc, LCID_INSTALLED); 
    return 0; 
} 

如果你只是想有语言环境的列表,你可以做到以下几点:

#include <windows.h> 
#include <tchar.h> 
#include <stdio.h> 
#include <vector> 
#include <string> 

typedef std::vector<std::basic_string<TCHAR>> tLocales; 
std::vector<std::basic_string<TCHAR>> g_locales; 

BOOL CALLBACK MyLocaleEnumProc(LPTSTR szLocaleString) 
{ 
    g_locales.push_back(szLocaleString); 
    return TRUE; 
} 
int _tmain() 
{ 
    // Get all locales 
    EnumSystemLocales(&MyLocaleEnumProc, LCID_INSTALLED); 

    // Print out all locales 
    for(tLocales::const_iterator i=g_locales.begin(); i != g_locales.end(); i++) 
    { 
    _tprintf(_T("Locale: %s\r\n"), i->c_str()); 
    } 
    return 0; 
} 
+0

这里有问题,当我想运行你的代码MyLocaleEnumProc被称为很多(在屏幕上多次打印文本)。我想只调用一次MyLocaleEnumProc! – user3291634

+0

什么意思使它能够调用一个函数,该函数应该返回回调中所有已安装的语言环境,而且只需要第一个语言环境? –

+0

@ user3291634:我添加了另一个解决方案,它应该做你想做的事情...... –

相关问题