std::string getLocale() { wchar_t lpLocaleName[255]; if (GetSystemDefaultLocaleName(lpLocaleName, 255) != 0) { wstring ws(lpLocaleName); return string(ws.begin(), ws.end()); } return Html::error("ERROR: " + GetLastError()); }
BOOL CALLBACK MyFuncLocaleEx(LPWSTR pStr, DWORD dwFlags, LPARAM lparam) { UNREFERENCED_PARAMETER(dwFlags); WCHAR** argv = (WCHAR**)lparam; WCHAR wcBuffer[BUFFER_SIZE]; int iResult; // Get its LCID LCID lcid = LocaleNameToLCID(pStr, NULL); if (lcid != 0) wprintf(L"LCID for %s is %x\n", pStr, lcid); else wprintf(L"Error %d getting LCID\n", GetLastError()); // Print out the locale name we found iResult = GetLocaleInfoEx(pStr, LOCALE_SENGLANGUAGE, wcBuffer, BUFFER_SIZE); // If it succeeds, print it out if (iResult > 0) wprintf(L"Locale %s (%s)\n", pStr, wcBuffer); else wprintf(L"Locale %s had error %d\n", pStr, GetLastError()); // CompareStringEx if this is the system locale, let us know iResult = GetSystemDefaultLocaleName(wcBuffer, BUFFER_SIZE); if (iResult > 0) { if (CompareStringEx(LOCALE_NAME_INVARIANT, LINGUISTIC_IGNORECASE, wcBuffer, -1, pStr, -1, NULL, NULL, 0) == CSTR_EQUAL) { wprintf(L"\nLocale %s is the system locale!\n", wcBuffer); system("Pause"); } } else { wprintf(L"Error %d getting system locale\n", GetLastError()); system("Pause"); } return (TRUE); }
WString FileTimeToString(const FILETIME& filetime) { SYSTEMTIME localSystemTime; FileTimeToSystemTime(&filetime, &localSystemTime); // Get the correct locale wchar_t localeName[LOCALE_NAME_MAX_LENGTH]={0}; GetSystemDefaultLocaleName(localeName, sizeof(localeName)/sizeof(*localeName)); // Get the localized date string wchar_t dateString[100]={0}; GetDateFormatEx(localeName, DATE_SHORTDATE, &localSystemTime, NULL, dateString, sizeof(dateString)/sizeof(*dateString), NULL); // Get the localized time string wchar_t timeString[100]={0}; GetTimeFormatEx(localeName, TIME_FORCE24HOURFORMAT | TIME_NOSECONDS, &localSystemTime, NULL, timeString, sizeof(timeString)/sizeof(*timeString)); return dateString+WString(L" ")+timeString; }
// get user prefered locale name: en-CA en-CA or en_CA.UTF-8 or empty "" string on error const string openm::getDefaultLocaleName(void) { // try user locale and on error system default locale string name; wchar_t wlcn[LOCALE_NAME_MAX_LENGTH + 1]; if (GetUserDefaultLocaleName(wlcn, LOCALE_NAME_MAX_LENGTH) <= 0) { if (GetSystemDefaultLocaleName(wlcn, LOCALE_NAME_MAX_LENGTH) <= 0) return name; // empty value on error } wlcn[LOCALE_NAME_MAX_LENGTH] = '\0'; // convert from Windows wchar to normal string char lcn[LOCALE_NAME_MAX_LENGTH + 1]; size_t nLcn = std::wcstombs(lcn, wlcn, LOCALE_NAME_MAX_LENGTH); if (nLcn >= LOCALE_NAME_MAX_LENGTH || nLcn == static_cast<size_t>(-1)) return name; // empty value on error lcn[LOCALE_NAME_MAX_LENGTH] = '\0'; name = lcn; return name; }
dc_setup_frame::dc_setup_frame(const wxString& title, int xpos, int ypos, int width, int height) : wxFrame((wxFrame *)NULL, -1, title, wxPoint(xpos, ypos), wxSize(width, height)) { this->SetSizeHints(wxDefaultSize, wxDefaultSize); std::string sysLang = "en"; #ifdef WIN32 WCHAR wcBuffer[512]; int res = GetSystemDefaultLocaleName(wcBuffer, 512); std::wstring sysLangW(wcBuffer); sysLangW = sysLangW.substr(0, 2); sysLang = std::string(sysLangW.begin(), sysLangW.end()); if (sysLang.size() < 2) sysLang = "en"; #endif // Load the default system language, or english if it's not available. lang langReader; m_lang = langReader.loadLanguage(sysLang); // Create split layout wxBoxSizer* bSizerMain; bSizerMain = new wxBoxSizer(wxHORIZONTAL); // Set up left bitmap from an embedded file wxImage::AddHandler(new wxJPEGHandler()); wxBoxSizer* bSizerLeft; bSizerLeft = new wxBoxSizer(wxVERTICAL); wxBitmap b(setup_background); m_bitmapSidebar = new wxStaticBitmap(this, wxID_ANY, (wxGDIImage&)b, wxDefaultPosition, wxDefaultSize, 0); bSizerLeft->Add(m_bitmapSidebar, 0, wxALL, 0); bSizerMain->Add(bSizerLeft, 3, wxEXPAND, 0); // Create right panel wxBoxSizer* bSizerRight; bSizerRight = new wxBoxSizer(wxVERTICAL); m_panel1 = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); wxBoxSizer* bSizerPanel; bSizerPanel = new wxBoxSizer(wxVERTICAL); m_pTextCtrl = new wxStaticText(m_panel1, -1, m_lang[L"Step1_SelectLang"].c_str(), wxPoint(20, 20), wxDefaultSize); bSizerPanel->Add(m_pTextCtrl, 0, wxALL, 5); m_langNames.clear(); m_langNames = langReader.loadLanguageNames(); wxArrayString m_langChoices; int selectedIndex = 0; int currentIndex = 0; for (std::map<std::wstring, std::wstring>::iterator it = m_langNames.begin(); it != m_langNames.end(); ++it) { if (it->first == sysLang) selectedIndex = currentIndex; m_langChoices.Add(it->second); currentIndex++; } m_langChoice = new wxChoice(m_panel1, wxID_ANY, wxDefaultPosition, wxSize(180, 23), m_langChoices, 0); m_langChoice->Select(selectedIndex); bSizerPanel->Add(m_langChoice, 0, wxALL, 5); m_panel1->SetSizer(bSizerPanel); //bSizerPanel->Fit(m_panel1); //m_pTextCtrl->Wrap(180); //wxFont f(14, wxFONTFAMILY_DEFAULT, // wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL;, false, "Verdana"); //m_pTextCtrl->SetFont(f); bSizerRight->Add(m_panel1, 1, wxALL | wxEXPAND, 100); wxBoxSizer* bSizerFooter; bSizerFooter = new wxBoxSizer(wxHORIZONTAL); m_cancelButton = new wxButton(this, BtnCancel, m_lang[L"General_Cancel"].c_str(), wxDefaultPosition, wxDefaultSize, 0); bSizerFooter->Add(m_cancelButton, 0, wxALL, 5); m_nextButton = new wxButton(this, wxID_ANY, m_lang[L"General_Next"].c_str(), wxDefaultPosition, wxDefaultSize, 0); bSizerFooter->Add(m_nextButton, 0, wxALL, 5); bSizerRight->Add(bSizerFooter, 0, wxALL | wxALIGN_RIGHT, 15); bSizerMain->Add(bSizerRight, 7, wxEXPAND, 5); m_panel1->Layout(); m_icon = wxICON(_(IDI_APP_ICON)); this->SetIcon(m_icon); this->SetSizer(bSizerMain); this->Layout(); this->Centre(wxBOTH); this->SetWindowStyle(wxMINIMIZE_BOX | wxCLOSE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN); Layout(); }