Changed: Convert std::string <> TCHAR

This commit is contained in:
kervala 2016-12-10 13:01:27 +01:00
parent d3b6102228
commit a184dd7d8f
6 changed files with 44 additions and 19 deletions

View file

@ -1528,7 +1528,8 @@ void CParticleTreeCtrl::insertNewPS(CParticleWorkspace &pws)
CFileDialog fd(TRUE, _T(".ps"), _T("*.ps"), OFN_ALLOWMULTISELECT|OFN_FILEMUSTEXIST, szFilter, this); CFileDialog fd(TRUE, _T(".ps"), _T("*.ps"), OFN_ALLOWMULTISELECT|OFN_FILEMUSTEXIST, szFilter, this);
const uint MAX_NUM_CHAR = 65536; const uint MAX_NUM_CHAR = 65536;
TCHAR filenamesBuf[MAX_NUM_CHAR]; TCHAR filenamesBuf[MAX_NUM_CHAR];
_tcscpy(filenamesBuf, _T("*.ps")); _tcscpy_s(filenamesBuf, MAX_NUM_CHAR, _T("*.ps"));
fd.m_ofn.lpstrFile = filenamesBuf; fd.m_ofn.lpstrFile = filenamesBuf;
fd.m_ofn.nMaxFile = MAX_NUM_CHAR - 1; fd.m_ofn.nMaxFile = MAX_NUM_CHAR - 1;
if (fd.DoModal() == IDOK) if (fd.DoModal() == IDOK)

View file

@ -62,7 +62,8 @@ INT_PTR CALLBACK CalculatingDialogCallback (
(((uint32)TimeLeft)/60)%60, (((uint32)TimeLeft)/60)%60,
(((uint32)TimeLeft))%60 ); (((uint32)TimeLeft))%60 );
if (pClass->bCancelCalculation) if (pClass->bCancelCalculation)
_tcscpy (temp, _T("INTERRUPTED - Finishing current object...")); _tcscpy_s (temp, 256, _T("INTERRUPTED - Finishing current object..."));
SendMessage (GetDlgItem (hwndDlg, IDC_STATICTIMELEFT), WM_SETTEXT, 0, (LPARAM)temp); SendMessage (GetDlgItem (hwndDlg, IDC_STATICTIMELEFT), WM_SETTEXT, 0, (LPARAM)temp);
SendMessage (GetDlgItem (hwndDlg, IDC_BUTTONCANCEL), WM_PAINT, 0, 0); SendMessage (GetDlgItem (hwndDlg, IDC_BUTTONCANCEL), WM_PAINT, 0, 0);
} }

View file

@ -312,7 +312,7 @@ LRESULT CMyListCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
Ctrl->getBrowseInfo (Ctrl->Item, Ctrl->SubItem, defExt, defFilename, defDir, filter); Ctrl->getBrowseInfo (Ctrl->Item, Ctrl->SubItem, defExt, defFilename, defDir, filter);
TCHAR buffer[MAX_PATH]; TCHAR buffer[MAX_PATH];
_tcscpy(buffer, utf8ToTStr(defDir)); _tcscpy_s(buffer, MAX_PATH, utf8ToTStr(defDir));
CFileDialog dlgFile (TRUE, utf8ToTStr(defExt), utf8ToTStr(defFilename), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, utf8ToTStr(filter), theApp.m_pMainWnd); CFileDialog dlgFile (TRUE, utf8ToTStr(defExt), utf8ToTStr(defFilename), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, utf8ToTStr(filter), theApp.m_pMainWnd);
dlgFile.m_ofn.lpstrInitialDir = buffer; dlgFile.m_ofn.lpstrInitialDir = buffer;

View file

@ -73,9 +73,19 @@ INT_PTR CFileDialogEx::DoModal ()
if ((result = CFileDialog::DoModal ()) == IDOK) if ((result = CFileDialog::DoModal ()) == IDOK)
{ {
// Update the path // Update the path
std::string newPath = tStrToUtf8(GetPathName ()); std::string newPath = NLMISC::CFile::getPath (tStrToUtf8(GetPathName()));
newPath = NLMISC::CFile::getPath (newPath);
RegSetValueEx (hKey, utf8ToTStr(_FileType), 0, REG_SZ, (LPBYTE)newPath.c_str (), newPath.size ()+1); #ifdef _UNICODE
ucstring tmp;
tmp.fromUtf8(newPath);
const uint cs = 2;
#else
std::stringg tmp = newPath;
const uint cs = 1;
#endif
uint length = (tmp.length() + 1) * cs;
RegSetValueEx (hKey, utf8ToTStr(_FileType), 0, REG_SZ, (LPBYTE)tmp.c_str(), length);
// Update the path list // Update the path list
set<string> oldPath; set<string> oldPath;
@ -91,7 +101,14 @@ INT_PTR CFileDialogEx::DoModal ()
uint index = 0; uint index = 0;
while (ite != oldPath.end ()) while (ite != oldPath.end ())
{ {
RegSetValueEx (hKey, utf8ToTStr(toString(index)), 0, REG_SZ, (LPBYTE)ite->c_str (), ite->size ()+1); #ifdef _UNICODE
tmp.fromUtf8(*ite);
#else
tmp = *ite;
#endif
length = (tmp.length() + 1) * cs;
RegSetValueEx (hKey, utf8ToTStr(toString(index)), 0, REG_SZ, (LPBYTE)tmp.c_str (), length);
ite++; ite++;
index++; index++;
} }

View file

@ -318,7 +318,7 @@ void CDialogFlags::loadEntityDisplayInfoToRegistry(TEntityDisplayInfoVect &infos
if (infos[k].Value == value) if (infos[k].Value == value)
{ {
int r, g, b, visible; int r, g, b, visible;
if (sscanf((const char *) dataStr, "%d, %d, %d, visible = %d", &r, &g, &b, &visible) == 4) if (_stscanf((const TCHAR *) dataStr, _T("%d, %d, %d, visible = %d"), &r, &g, &b, &visible) == 4)
{ {
infos[k].Color = CRGBA(r, g, b); infos[k].Color = CRGBA(r, g, b);
infos[k].Visible = visible != 0; infos[k].Visible = visible != 0;
@ -342,10 +342,14 @@ void CDialogFlags::saveEntityDisplayInfoToRegistry(const TEntityDisplayInfoVect
{ {
for(uint k = 0; k < infos.size(); ++k) for(uint k = 0; k < infos.size(); ++k)
{ {
char colorStr[128];
CRGBA color = infos[k].Color; CRGBA color = infos[k].Color;
sprintf(colorStr, "%d, %d, %d, visible = %d", (int) color.R, (int) color.G, (int) color.B, (int) (infos[k].Visible ? 1 : 0));
LONG result = RegSetValueEx(hKey, utf8ToTStr(toString(infos[k].Value)), 0, REG_SZ, (const BYTE *) colorStr, strlen(colorStr)); TCHAR colorStr[32];
_stprintf_s(colorStr, 32, _T("%d, %d, %d, visible = %d"), (int) color.R, (int) color.G, (int) color.B, (int) (infos[k].Visible ? 1 : 0));
TCHAR id[16];
LONG result = RegSetValueEx(hKey, _itot(infos[k].Value, id, 10), 0, REG_SZ, (const BYTE *)colorStr, (_tcslen(colorStr) + 1)*sizeof(TCHAR));
if (result != ERROR_SUCCESS) if (result != ERROR_SUCCESS)
{ {
nlwarning("Couldn't write registry key for entity % color", infos[k].Name); nlwarning("Couldn't write registry key for entity % color", infos[k].Name);

View file

@ -225,7 +225,11 @@ void CDialogFlags::OnTimer(UINT_PTR nIDEvent)
c = _SbList.GetItemCount(); c = _SbList.GetItemCount();
for (i=0; i<SampleBanks.size(); ++i) for (i=0; i<SampleBanks.size(); ++i)
{ {
std::string temp = toString("%6.2f", SampleBanks[i].second / (1024.0f*1024.0f)); TCHAR temp[1024];
_stprintf(temp, _T("%6.2f"), SampleBanks[i].second / (1024.0f*1024.0f));
TCHAR bankName[1024];
_tcscpy_s(bankName, 1024, utf8ToTStr(SampleBanks[i].first));
if (i < c) if (i < c)
{ {
@ -233,12 +237,12 @@ void CDialogFlags::OnTimer(UINT_PTR nIDEvent)
TCHAR temp2[1024]; TCHAR temp2[1024];
_SbList.GetItemText(i, 0, temp2, 1024); _SbList.GetItemText(i, 0, temp2, 1024);
if (_tcscmp(utf8ToTStr(SampleBanks[i].first), temp2) != 0) if (_tcscmp(bankName, temp2) != 0)
_SbList.SetItemText(i, 0, utf8ToTStr(SampleBanks[i].first)); _SbList.SetItemText(i, 0, bankName);
_SbList.GetItemText(i, 1, temp2, 1024); _SbList.GetItemText(i, 1, temp2, 1024);
if (_tcscmp(utf8ToTStr(temp), temp2) != 0) if (_tcscmp(temp, temp2) != 0)
_SbList.SetItemText(i, 1, utf8ToTStr(temp)); _SbList.SetItemText(i, 1, temp);
} }
else else
{ {
@ -247,13 +251,11 @@ void CDialogFlags::OnTimer(UINT_PTR nIDEvent)
lvi.mask = LVIF_TEXT; lvi.mask = LVIF_TEXT;
lvi.iItem = i; lvi.iItem = i;
lvi.iSubItem = 0; lvi.iSubItem = 0;
lvi.pszText = (char*) SampleBanks[i].first.c_str(); lvi.pszText = bankName;
_SbList.InsertItem(&lvi); _SbList.InsertItem(&lvi);
lvi.iItem = i; lvi.iItem = i;
lvi.iSubItem = 1; lvi.iSubItem = 1;
char temp[1024];
sprintf(temp, "%6.2f", SampleBanks[i].second / (1024.0f*1024.0f));
lvi.pszText = temp; lvi.pszText = temp;
_SbList.InsertItem(&lvi); _SbList.InsertItem(&lvi);
} }