From cdb7cdcfd510001dcd449b561d00e8803f4dc376 Mon Sep 17 00:00:00 2001 From: zilmar Date: Tue, 20 Apr 2021 12:26:16 +0930 Subject: [PATCH] Replace getwindow text with GetCWindowText --- Source/Project64/UserInterface/CheatUI.cpp | 39 +++----- Source/Project64/UserInterface/CheatUI.h | 1 - .../Debugger/Debugger-AddBreakpoint.cpp | 5 +- .../Debugger/Debugger-AddSymbol.cpp | 8 +- .../Debugger/Debugger-Commands.cpp | 28 ++---- .../Debugger/Debugger-DMALogView.cpp | 30 +++--- .../Debugger/Debugger-MemorySearch.cpp | 98 +++++++------------ .../Debugger/Debugger-MemorySearch.h | 55 +++++------ .../Debugger/Debugger-RegisterTabData.h | 16 ++- .../Debugger/Debugger-RegisterTabs.cpp | 63 +++++------- .../Debugger/Debugger-RegisterTabs.h | 1 - .../Debugger/Debugger-Scripts.cpp | 28 +++--- .../UserInterface/Debugger/Debugger-Scripts.h | 4 +- .../Debugger/Debugger-Symbols.cpp | 8 +- .../Settings/SettingsPage-Directories.cpp | 5 +- .../Settings/SettingsPage-DiskDrive.cpp | 9 +- .../UserInterface/Settings/SettingsPage.h | 2 +- .../UserInterface/SupportEnterCode.cpp | 7 +- .../WTLControls/EditNumber32.cpp | 95 ++++++++---------- .../UserInterface/WTLControls/EditNumber32.h | 1 - .../WTLControls/ModifiedEditBox.cpp | 6 -- .../WTLControls/ModifiedEditBox.h | 1 - .../WTLControls/PartialGroupBox.cpp | 10 +- 23 files changed, 195 insertions(+), 325 deletions(-) diff --git a/Source/Project64/UserInterface/CheatUI.cpp b/Source/Project64/UserInterface/CheatUI.cpp index 4e96889b2..9a7f0055c 100644 --- a/Source/Project64/UserInterface/CheatUI.cpp +++ b/Source/Project64/UserInterface/CheatUI.cpp @@ -680,7 +680,7 @@ LRESULT CEditCheat::OnEditCheat(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, LRESULT CEditCheat::OnAddCheat(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { - std::string NewCheatName = GetItemText(IDC_CODE_NAME); + std::string NewCheatName = GetCWindowText(GetDlgItem(IDC_CODE_NAME)); for (CEnhancementList::const_iterator itr = m_Cheats.begin(); itr != m_Cheats.end(); itr++) { const CEnhancement & Enhancement = itr->second; @@ -708,7 +708,7 @@ LRESULT CEditCheat::OnAddCheat(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCt m_EditEnhancement->SetName(NewCheatName.c_str()); m_EditEnhancement->SetEntries(Enhancement.GetEntries()); m_EditEnhancement->SetOptions(Enhancement.GetOptions()); - m_EditEnhancement->SetNote(GetItemText(IDC_NOTES).c_str()); + m_EditEnhancement->SetNote(GetCWindowText(GetDlgItem(IDC_NOTES)).c_str()); } else { @@ -759,8 +759,8 @@ LRESULT CEditCheat::OnCheatOptionsChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HW bool CEditCheat::ReadEnhancement(CEnhancement & Enhancement) { CEnhancement TestEnhancement(CEnhancement::CheatIdent); - TestEnhancement.SetName(GetItemText(IDC_CODE_NAME).c_str()); - TestEnhancement.SetNote(GetItemText(IDC_NOTES).c_str()); + TestEnhancement.SetName(GetCWindowText(GetDlgItem(IDC_CODE_NAME)).c_str()); + TestEnhancement.SetNote(GetCWindowText(GetDlgItem(IDC_NOTES)).c_str()); CEnhancement::CodeEntries Entries; CEdit CheatCodes(GetDlgItem(IDC_CHEAT_CODES)); @@ -851,10 +851,10 @@ void CEditCheat::DetailsChanged(void) void CEditCheat::RecordCurrentValues(void) { - m_EditName = GetItemText(IDC_CODE_NAME); - m_EditCode = GetItemText(IDC_CHEAT_CODES); - m_EditOptions = GetItemText(IDC_CHEAT_OPTIONS); - m_EditNotes = GetItemText(IDC_NOTES); + m_EditName = GetCWindowText(GetDlgItem(IDC_CODE_NAME)); + m_EditCode = GetCWindowText(GetDlgItem(IDC_CHEAT_CODES)); + m_EditOptions = GetCWindowText(GetDlgItem(IDC_CHEAT_OPTIONS)); + m_EditNotes = GetCWindowText(GetDlgItem(IDC_NOTES)); } bool CEditCheat::ValuesChanged(void) @@ -862,10 +862,10 @@ bool CEditCheat::ValuesChanged(void) bool Changed = false; if (m_hWnd != nullptr) { - if (m_EditName != GetItemText(IDC_CODE_NAME) || - m_EditCode != GetItemText(IDC_CHEAT_CODES) || - m_EditOptions != GetItemText(IDC_CHEAT_OPTIONS) || - m_EditNotes != GetItemText(IDC_NOTES)) + if (m_EditName != GetCWindowText(GetDlgItem(IDC_CODE_NAME)) || + m_EditCode != GetCWindowText(GetDlgItem(IDC_CHEAT_CODES)) || + m_EditOptions != GetCWindowText(GetDlgItem(IDC_CHEAT_OPTIONS)) || + m_EditNotes != GetCWindowText(GetDlgItem(IDC_NOTES))) { Changed = true; } @@ -895,21 +895,6 @@ bool CEditCheat::ValuesChanged(void) return false; } -std::string CEditCheat::GetItemText(int nIDDlgItem) -{ - CWindow Window = GetDlgItem(nIDDlgItem); - int length = Window.GetWindowTextLength(); - if (length == 0) - { - return ""; - } - - std::wstring Result; - Result.resize(length + 1); - Window.GetWindowText((wchar_t *)Result.c_str(), Result.length()); - return stdstr().FromUTF16(Result.c_str()); -} - CEnhancementCodeEx::CEnhancementCodeEx(CEnhancement * Enhancement) : m_Enhancement(Enhancement) { diff --git a/Source/Project64/UserInterface/CheatUI.h b/Source/Project64/UserInterface/CheatUI.h index e348c9ebb..f291ce6ef 100644 --- a/Source/Project64/UserInterface/CheatUI.h +++ b/Source/Project64/UserInterface/CheatUI.h @@ -111,7 +111,6 @@ private: void DetailsChanged(void); void RecordCurrentValues(void); bool ValuesChanged(void); - std::string GetItemText(int nIDDlgItem); CEnhancementList & m_Cheats; CCheatList & m_CheatList; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-AddBreakpoint.cpp b/Source/Project64/UserInterface/Debugger/Debugger-AddBreakpoint.cpp index 28d35d59c..03829a816 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-AddBreakpoint.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-AddBreakpoint.cpp @@ -18,9 +18,8 @@ LRESULT CAddBreakpointDlg::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL& { case IDOK: { - wchar_t addrStr[9]; - m_AddressEdit.GetWindowText(addrStr, 9); - uint32_t address = wcstoul(addrStr, nullptr, 16); + std::string addrStr = GetCWindowText(m_AddressEdit); + uint32_t address = stoul(addrStr.c_str(), nullptr, 16); CBreakpoints* breakpoints = m_Debugger->Breakpoints(); diff --git a/Source/Project64/UserInterface/Debugger/Debugger-AddSymbol.cpp b/Source/Project64/UserInterface/Debugger/Debugger-AddSymbol.cpp index e8870570f..9c33b8d18 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-AddSymbol.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-AddSymbol.cpp @@ -72,14 +72,8 @@ LRESULT CAddSymbolDlg::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl* MessageBox(L"Name and/or description required", L"Error", MB_OK); return 0; } - - wchar_t name[128]; - wchar_t description[256]; - - m_NameEdit.GetWindowText(name, nameLen + 1); - m_DescriptionEdit.GetWindowText(description, descLen + 1); - m_Debugger->SymbolTable()->AddSymbol(type, address, stdstr().FromUTF16(name).c_str(), stdstr().FromUTF16(description).c_str()); + m_Debugger->SymbolTable()->AddSymbol(type, address, GetCWindowText(m_NameEdit).c_str(), GetCWindowText(m_DescriptionEdit).c_str()); m_Debugger->SymbolTable()->Save(); m_Debugger->Debug_RefreshSymbolsWindow(); diff --git a/Source/Project64/UserInterface/Debugger/Debugger-Commands.cpp b/Source/Project64/UserInterface/Debugger/Debugger-Commands.cpp index 8a9286fcf..f1298b075 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-Commands.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-Commands.cpp @@ -1676,10 +1676,8 @@ LRESULT CDebugCommandsView::OnOpEditKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM } else if (wParam == VK_RETURN) { - wchar_t text[256] = { 0 }; - m_OpEdit.GetWindowText(text, (sizeof(text) / sizeof(text[0])) - 1); uint32_t op; - bool bValid = CAssembler::AssembleLine(stdstr().FromUTF16(text).c_str(), &op, m_SelectedAddress); + bool bValid = CAssembler::AssembleLine(GetCWindowText(m_OpEdit).c_str(), &op, m_SelectedAddress); if (bValid) { m_OpEdit.SetWindowText(L""); @@ -1700,19 +1698,15 @@ LRESULT CDebugCommandsView::OnOpEditKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM LRESULT CDebugCommandsView::OnOpEditChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) { // Handle multiline input - size_t length = m_OpEdit.GetWindowTextLength(); - wchar_t* text = new wchar_t[length + 1]; - m_OpEdit.GetWindowText(text, length + 1); - - if (wcschr(text, L'\n') == nullptr) + std::string text = GetCWindowText(m_OpEdit); + if (strchr(text.c_str(), '\n') == nullptr) { - delete[] text; return FALSE; } EndOpEdit(); - for (size_t i = 0; i < length; i++) + for (size_t i = 0 , n = text.size(); i < n; i++) { if (text[i] == '\r') { @@ -1720,15 +1714,15 @@ LRESULT CDebugCommandsView::OnOpEditChanged(WORD /*wNotifyCode*/, WORD /*wID*/, } } - wchar_t *tokctx; - wchar_t *line = wcstok_s(text, L"\n", &tokctx); + char * tokctx; + char * line = strtok_s((char *)text.c_str(), "\n", &tokctx); while (line != nullptr) { - if (wcslen(line) != 0) + if (strlen(line) != 0) { uint32_t op; - bool bValid = CAssembler::AssembleLine(stdstr().FromUTF16(line).c_str(), &op, m_SelectedAddress); + bool bValid = CAssembler::AssembleLine(line, &op, m_SelectedAddress); if (bValid) { @@ -1739,18 +1733,16 @@ LRESULT CDebugCommandsView::OnOpEditChanged(WORD /*wNotifyCode*/, WORD /*wID*/, { ShowAddress(m_StartAddress, TRUE); BeginOpEdit(m_SelectedAddress); - m_OpEdit.SetWindowText(line); - delete[] text; + m_OpEdit.SetWindowText(stdstr(line).ToUTF16().c_str()); return FALSE; } } - line = wcstok_s(nullptr, L"\n", &tokctx); + line = strtok_s(nullptr, "\n", &tokctx); } ShowAddress(m_StartAddress, TRUE); BeginOpEdit(m_SelectedAddress); - delete[] text; return FALSE; } diff --git a/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.cpp b/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.cpp index 378a07945..1035aeca7 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-DMALogView.cpp @@ -301,29 +301,25 @@ LRESULT CDebugDMALogView::OnRamAddrChanged(WORD /*wNotifyCode*/, WORD /*wID*/, H return FALSE; } - wchar_t szRamAddr[9]; - char szRomAddr[9]; - - m_DMARamEdit.GetWindowText(szRamAddr, 9); - uint32_t ramAddr = wcstoul(szRamAddr, nullptr, 16); + stdstr szRomAddr; + uint32_t ramAddr = strtoul(GetCWindowText(m_DMARamEdit).c_str(), nullptr, 16); uint32_t romAddr, offset; - - DMALOGENTRY* lpEntry = m_DMALog->GetEntryByRamAddress(ramAddr, &romAddr, &offset); + DMALOGENTRY * lpEntry = m_DMALog->GetEntryByRamAddress(ramAddr, &romAddr, &offset); if (lpEntry != nullptr) { - sprintf(szRomAddr, "%08X", romAddr); + szRomAddr.Format("%08X", romAddr); stdstr_f blockInfo("Block: %08X -> %08X [%X] +%X", romAddr, ramAddr, lpEntry->length, offset); m_BlockInfo.SetWindowText(blockInfo.ToUTF16().c_str()); } else { - sprintf(szRomAddr, "????????"); + szRomAddr = "????????"; m_BlockInfo.SetWindowText(L"Block: ?"); } m_bConvertingAddress = true; - m_DMARomEdit.SetWindowText(stdstr(szRomAddr).ToUTF16().c_str()); + m_DMARomEdit.SetWindowText(szRomAddr.ToUTF16().c_str()); m_bConvertingAddress = false; return FALSE; } @@ -335,29 +331,25 @@ LRESULT CDebugDMALogView::OnRomAddrChanged(WORD /*wNotifyCode*/, WORD /*wID*/, H return FALSE; } - wchar_t szRamAddr[9]; - wchar_t szRomAddr[9]; - - m_DMARomEdit.GetWindowText(szRomAddr, 9); - uint32_t romAddr = wcstoul(szRomAddr, nullptr, 16); + stdstr szRamAddr = GetCWindowText(m_DMARomEdit); + uint32_t romAddr = strtoul(szRamAddr.c_str(), nullptr, 16); uint32_t ramAddr, offset; - DMALOGENTRY* lpEntry = m_DMALog->GetEntryByRomAddress(romAddr, &ramAddr, &offset); if (lpEntry != nullptr) { - wsprintf(szRamAddr, L"%08X", ramAddr); + szRamAddr.Format("%08X", ramAddr); stdstr blockInfo = stdstr_f("Block: %08X -> %08X [%X] +%X", romAddr, ramAddr, lpEntry->length, offset); m_BlockInfo.SetWindowText(blockInfo.ToUTF16().c_str()); } else { - wsprintf(szRamAddr, L"????????"); + szRamAddr = "????????"; m_BlockInfo.SetWindowText(L"Block: ?"); } m_bConvertingAddress = true; - m_DMARamEdit.SetWindowText(szRamAddr); + m_DMARamEdit.SetWindowText(szRamAddr.ToUTF16().c_str()); m_bConvertingAddress = false; return FALSE; } diff --git a/Source/Project64/UserInterface/Debugger/Debugger-MemorySearch.cpp b/Source/Project64/UserInterface/Debugger/Debugger-MemorySearch.cpp index 4a2fc4cdf..dbbaefb4e 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-MemorySearch.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-MemorySearch.cpp @@ -96,7 +96,7 @@ LRESULT CDebugMemorySearch::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARA m_bDraggingSeparator = false; ::GetWindowRect(GetDlgItem(IDC_SEPARATOR), &m_InitialSeparatorRect); ScreenToClient(&m_InitialSeparatorRect); - + uint32_t ramSize = (g_MMU != nullptr) ? g_MMU->RdramSize() : 0x00400000; m_AddrStart.SetValue(0x80000000, DisplayMode::AllHex); @@ -104,7 +104,7 @@ LRESULT CDebugMemorySearch::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARA FixListHeader(m_WatchListCtrl); FixListHeader(m_ResultsListCtrl); - + UpdateResultsList(true); UpdateWatchList(); @@ -523,9 +523,9 @@ LRESULT CDebugMemorySearch::OnResultsPopupSetValue(WORD /*wNotifyCode*/, WORD /* { int index = m_ResultsListCtrl.GetItemData(iItem); CScanResult* presult = m_MemoryScanner.GetResult(index); - wchar_t* enteredString = m_SetValueDlg.GetEnteredString(); - presult->SetMemoryValueFromString(stdstr().FromUTF16(enteredString).c_str()); - m_ResultsListCtrl.SetItemText(iItem, ResultsListCtrl_Col_Value, enteredString); + const std::string & enteredString = m_SetValueDlg.GetEnteredString(); + presult->SetMemoryValueFromString(enteredString.c_str()); + m_ResultsListCtrl.SetItemText(iItem, ResultsListCtrl_Col_Value, stdstr(enteredString).ToUTF16().c_str()); } } } @@ -662,8 +662,7 @@ LRESULT CDebugMemorySearch::OnWatchListDblClick(LPNMHDR /*lpnmh*/) { if (m_SetValueDlg.DoModal("Change address", "New address:", stdstr_f("0x%08X", presult->m_Address).c_str())) { - std::string szEnteredString = stdstr().FromUTF16(m_SetValueDlg.GetEnteredString()); - uint32_t newAddr = strtoul(szEnteredString.c_str(), nullptr, 0); + uint32_t newAddr = strtoul(m_SetValueDlg.GetEnteredString().c_str(), nullptr, 0); if (presult->SetAddressSafe(newAddr)) { m_WatchListCtrl.SetItemText(iItem, WatchListCtrl_Col_Address, stdstr_f("0x%08X", newAddr).ToUTF16().c_str()); @@ -677,7 +676,7 @@ LRESULT CDebugMemorySearch::OnWatchListDblClick(LPNMHDR /*lpnmh*/) presult->GetMemoryValueString(szInitialValue, 1024); if (m_SetValueDlg.DoModal("Change value", "New value:", szInitialValue)) { - presult->SetMemoryValueFromString(stdstr().FromUTF16(m_SetValueDlg.GetEnteredString()).c_str()); + presult->SetMemoryValueFromString(m_SetValueDlg.GetEnteredString().c_str()); } } break; @@ -685,9 +684,9 @@ LRESULT CDebugMemorySearch::OnWatchListDblClick(LPNMHDR /*lpnmh*/) { if (m_SetValueDlg.DoModal("Set description", "New description:", presult->GetDescription())) { - stdstr szEnteredString = stdstr().FromUTF16(m_SetValueDlg.GetEnteredString()); - presult->SetDescription(szEnteredString.c_str()); - m_WatchListCtrl.SetItemText(iItem, WatchListCtrl_Col_Description, stdstr(szEnteredString).ToUTF16().c_str()); + stdstr EnteredString = m_SetValueDlg.GetEnteredString(); + presult->SetDescription(EnteredString.c_str()); + m_WatchListCtrl.SetItemText(iItem, WatchListCtrl_Col_Description, EnteredString.ToUTF16().c_str()); } } break; @@ -702,8 +701,7 @@ LRESULT CDebugMemorySearch::OnWatchListDblClick(LPNMHDR /*lpnmh*/) { if (m_SetValueDlg.DoModal("String length", "New string length:", stdstr_f("%d", presult->GetStrLength()).c_str())) { - stdstr enteredString = stdstr().FromUTF16(m_SetValueDlg.GetEnteredString()); - int length = atoi(enteredString.c_str()); + int length = atoi(m_SetValueDlg.GetEnteredString().c_str()); presult->SetStrLengthSafe(length); } @@ -896,10 +894,9 @@ LRESULT CDebugMemorySearch::OnWatchListPopupChangeValue(WORD /*wNotifyCode*/, WO { int index = m_WatchListCtrl.GetItemData(iItem); CScanResult* presult = &m_WatchList[index]; - stdstr enteredString = stdstr().FromUTF16(m_SetValueDlg.GetEnteredString()); // TODO: prompt for size change if string is too long - presult->SetMemoryValueFromString(enteredString.c_str()); - m_WatchListCtrl.SetItemText(iItem, WatchListCtrl_Col_Value, stdstr(enteredString).ToUTF16().c_str()); + presult->SetMemoryValueFromString(m_SetValueDlg.GetEnteredString().c_str()); + m_WatchListCtrl.SetItemText(iItem, WatchListCtrl_Col_Value, stdstr(m_SetValueDlg.GetEnteredString()).ToUTF16().c_str()); } } } @@ -927,7 +924,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupChangeDescription(WORD /*wNotifyCode { int index = m_WatchListCtrl.GetItemData(iItem); CScanResult* presult = &m_WatchList[index]; - stdstr description = stdstr().FromUTF16(m_SetValueDlg.GetEnteredString()); + stdstr description = m_SetValueDlg.GetEnteredString(); presult->SetDescription(description.c_str()); m_WatchListCtrl.SetItemText(iItem, WatchListCtrl_Col_Description, description.ToUTF16().c_str()); } @@ -956,8 +953,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupChangeType(WORD /*wNotifyCode*/, WOR if (m_SetValueDlg.DoModal("String length", "New string length:", stdstr_f("%d", pFirstResult->GetStrLength()).c_str())) { - stdstr enteredString = stdstr().FromUTF16(m_SetValueDlg.GetEnteredString()); - length = atoi(enteredString.c_str()); + length = atoi(m_SetValueDlg.GetEnteredString().c_str()); if (length <= 0) { @@ -1005,15 +1001,14 @@ LRESULT CDebugMemorySearch::OnWatchListPopupChangeAddress(WORD /*wNotifyCode*/, if (m_SetValueDlg.DoModal("Change address", "New address:", stdstr_f("0x%08X", pFirstResult->m_Address).c_str())) { - stdstr enteredString = stdstr().FromUTF16(m_SetValueDlg.GetEnteredString()); - uint32_t newAddr = strtoul(enteredString.c_str(), nullptr, 0); + uint32_t newAddr = strtoul(m_SetValueDlg.GetEnteredString().c_str(), nullptr, 0); stdstr newAddrStr = stdstr_f("0x%08X", newAddr); int nItems = m_WatchListCtrl.GetItemCount(); for (int iItem = 0; iItem < nItems; iItem++) { bool bSelected = (m_WatchListCtrl.GetItemState(iItem, LVNI_SELECTED) != 0); - + if (bSelected) { int index = m_WatchListCtrl.GetItemData(iItem); @@ -1038,14 +1033,13 @@ LRESULT CDebugMemorySearch::OnWatchListPopupChangeAddressBy(WORD /*wNotifyCode*/ if (m_SetValueDlg.DoModal("Adjust address", "Address offset (+/-):", "0")) { - stdstr szEnteredString = stdstr().FromUTF16(m_SetValueDlg.GetEnteredString()); - int offset = atoi(szEnteredString.c_str()); + int offset = atoi(m_SetValueDlg.GetEnteredString().c_str()); int nItems = m_WatchListCtrl.GetItemCount(); for (int iItem = 0; iItem < nItems; iItem++) { bool bSelected = (m_WatchListCtrl.GetItemState(iItem, LVNI_SELECTED) != 0); - + if (bSelected) { int index = m_WatchListCtrl.GetItemData(iItem); @@ -1102,7 +1096,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupCopyGamesharkCode(WORD /*wNotifyCode bool haveOddLength = (length & 1) != 0; int evenLength = length & ~1; - + if (length >= 2) { for (int j = 0; j < evenLength; j += 2) @@ -1451,7 +1445,7 @@ bool CDebugMemorySearch::MouseHovering(WORD ctrlId, int hMargin, int vMargin) } ::GetWindowRect(GetDlgItem(ctrlId), &ctrlRect); - + return ( pointerPos.x >= ctrlRect.left - hMargin && pointerPos.x <= ctrlRect.right + hMargin && @@ -1641,7 +1635,6 @@ void CDebugMemorySearch::Search(void) goto value_parse_error; } } - m_MemoryScanner.SetValue(value._string); m_MemoryScanner.SetStringValueLength(stringValueLength); break; @@ -1651,7 +1644,7 @@ void CDebugMemorySearch::Search(void) { goto value_parse_error; } - + m_MemoryScanner.SetValue(value._string); m_MemoryScanner.SetStringValueLength(stringValueLength); break; @@ -1660,7 +1653,7 @@ void CDebugMemorySearch::Search(void) return; } } - + if (!m_MemoryScanner.DidFirstScan()) { m_MemoryScanner.SetAddressType(bPhysicalChecked ? AddressType_Physical : AddressType_Virtual); @@ -1919,7 +1912,7 @@ void CDebugMemorySearch::RefreshResultsListValues(void) } int numShownResults = m_ResultsListCtrl.GetItemCount(); - + if (numShownResults > 0) { m_ResultsListCtrl.SetRedraw(FALSE); @@ -2044,7 +2037,7 @@ void CDebugMemorySearch::LoadWatchList(void) { ClearWatchList(); } - + CPath wlPath = GetWatchListPath(); m_WatchListFile.Open(wlPath, CFileBase::modeRead); @@ -2052,18 +2045,18 @@ void CDebugMemorySearch::LoadWatchList(void) { return; } - + uint32_t length = m_WatchListFile.GetLength(); char* szWlFile = new char[length + 1]; - + m_WatchListFile.SeekToBegin(); m_WatchListFile.Read(szWlFile, length); szWlFile[length] = '\0'; m_WatchListFile.Close(); - + char* p = szWlFile; - + while (*p) { CScanResult result(AddressType_Virtual, DisplayDefault); @@ -2126,10 +2119,10 @@ void CDebugMemorySearch::LoadWatchList(void) } UpdateWatchList(); - + parse_error: delete[] szWlFile; - + } void CDebugMemorySearch::FixListHeader(CListViewCtrl& listCtrl) @@ -2186,7 +2179,7 @@ INT_PTR CSetValueDlg::DoModal(const char* caption, const char* label, DWORD_PTR return CDialogImpl::DoModal(); } -wchar_t* CSetValueDlg::GetEnteredString(void) +const std::string & CSetValueDlg::GetEnteredString(void) { return m_EnteredString; } @@ -2246,24 +2239,14 @@ LRESULT CSetValueDlg::OnDestroy(void) LRESULT CSetValueDlg::OnOK(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) { - if (m_EnteredString != nullptr) - { - delete[] m_EnteredString; - m_EnteredString = nullptr; - } - + m_EnteredString.clear(); if (m_Mode == Mode_TextBox) { - int length = m_Value.GetWindowTextLength(); - m_EnteredString = new wchar_t[length + 1]; - m_Value.GetWindowText(m_EnteredString, length + 1); + m_EnteredString = GetCWindowText(m_Value); } else if (m_Mode == Mode_ComboBox) { - int length = m_CmbValue.GetWindowTextLength(); - m_EnteredString = new wchar_t[length + 1]; - m_CmbValue.GetWindowText(m_EnteredString, length + 1); - + m_EnteredString = GetCWindowText(m_CmbValue); m_EnteredData = m_CmbValue.GetItemData(m_CmbValue.GetCurSel()); } @@ -2277,17 +2260,12 @@ LRESULT CSetValueDlg::OnCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/ return FALSE; } -CSetValueDlg::CSetValueDlg(void) : - m_EnteredString(nullptr) +CSetValueDlg::CSetValueDlg(void) { } CSetValueDlg::~CSetValueDlg(void) { - if (m_EnteredString != nullptr) - { - delete[] m_EnteredString; - } } CEditMixed::CEditMixed(void) : @@ -2297,10 +2275,6 @@ CEditMixed::CEditMixed(void) : CEditMixed::~CEditMixed(void) { - if (m_String != nullptr) - { - delete[] m_String; - } } DisplayFormat CEditMixed::GetDisplayFormat(void) diff --git a/Source/Project64/UserInterface/Debugger/Debugger-MemorySearch.h b/Source/Project64/UserInterface/Debugger/Debugger-MemorySearch.h index 83b78b9ab..fb7847d3f 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-MemorySearch.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-MemorySearch.h @@ -7,15 +7,6 @@ class CEditMixed : public CWindowImpl, public CMixed { -private: - ValueType m_Type; - DisplayFormat m_DisplayFormat; - wchar_t *m_String; - int m_StringLength; - void ReloadString(void); - - //void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); - public: CEditMixed(void); ~CEditMixed(void); @@ -39,13 +30,26 @@ public: bool GetValueHexString(const wchar_t*& value, int& length); BEGIN_MSG_MAP_EX(CEditMixed) - //MSG_WM_CHAR(OnChar) END_MSG_MAP() + +private: + ValueType m_Type; + DisplayFormat m_DisplayFormat; + wchar_t *m_String; + int m_StringLength; + void ReloadString(void); }; class CSetValueDlg : public CDialogImpl { public: + BEGIN_MSG_MAP_EX(CSetValueDlg) + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) + COMMAND_HANDLER(IDOK, BN_CLICKED, OnOK) + COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnCancel) + MSG_WM_DESTROY(OnDestroy) + END_MSG_MAP() + enum { IDD = IDD_Debugger_Search_SetValue }; typedef struct @@ -54,15 +58,20 @@ public: DWORD_PTR data; } ComboItem; - INT_PTR DoModal(const char* caption, const char* label, const char* initialText); - INT_PTR DoModal(const char* caption, const char* label, DWORD_PTR initialData, const ComboItem items[]); - wchar_t* GetEnteredString(void); - DWORD_PTR GetEnteredData(void); - CSetValueDlg(void); virtual ~CSetValueDlg(void); + INT_PTR DoModal(const char* caption, const char* label, const char* initialText); + INT_PTR DoModal(const char* caption, const char* label, DWORD_PTR initialData, const ComboItem items[]); + const std::string & GetEnteredString(void); + DWORD_PTR GetEnteredData(void); + private: + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); + LRESULT OnDestroy(void); + LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); + LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); + enum Mode { Mode_TextBox, @@ -75,8 +84,8 @@ private: const char* m_Label; const ComboItem* m_ComboItems; - const char* m_InitialText; - wchar_t *m_EnteredString; + const char * m_InitialText; + std::string m_EnteredString; DWORD_PTR m_InitialData; DWORD_PTR m_EnteredData; @@ -84,18 +93,6 @@ private: CStatic m_Prompt; CEdit m_Value; CComboBox m_CmbValue; - - LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); - LRESULT OnDestroy(void); - LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hwnd, BOOL& bHandled); - - BEGIN_MSG_MAP_EX(CSetValueDlg) - MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) - COMMAND_HANDLER(IDOK, BN_CLICKED, OnOK) - COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnCancel) - MSG_WM_DESTROY(OnDestroy) - END_MSG_MAP() }; class CDebugMemorySearch : diff --git a/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabData.h b/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabData.h index b9c698f5d..155f30d1e 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabData.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabData.h @@ -7,8 +7,8 @@ struct FieldPair const WORD EditId; }; -using FieldPairWithStopCallback = std::function; -using FieldPairCallback = std::function; +using FieldPairWithStopCallback = std::function; +using FieldPairCallback = std::function; struct TabRecord { @@ -47,28 +47,24 @@ struct TabRecord return -1; } - void Iterate(const CWindow *parent, FieldPairWithStopCallback callback) const + void Iterate(const CWindow & parent, FieldPairWithStopCallback callback) const { for (size_t i = 0, end = FieldCount; i < end; i++) { const FieldPair *pair = (Fields + i); - const CWindow label = parent->GetDescendantWindow(pair->LabelId); - const CWindow edit = parent->GetDescendantWindow(pair->EditId); - if (callback(&label, &edit)) + if (callback(parent.GetDescendantWindow(pair->LabelId), parent.GetDescendantWindow(pair->EditId))) { break; } } } - void Iterate(const CWindow *parent, FieldPairCallback callback) const + void Iterate(const CWindow & parent, FieldPairCallback callback) const { for (size_t i = 0, end = FieldCount; i < end; i++) { const FieldPair *pair = (Fields + i); - const CWindow label = parent->GetDescendantWindow(pair->LabelId); - const CWindow edit = parent->GetDescendantWindow(pair->EditId); - callback(&label, &edit); + callback(parent.GetDescendantWindow(pair->LabelId), parent.GetDescendantWindow(pair->EditId)); } } }; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabs.cpp b/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabs.cpp index a78a91192..526917f75 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabs.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabs.cpp @@ -271,14 +271,12 @@ void CRegisterTabs::RegisterChanged(HWND hDlg, TAB_ID srcTabId, WPARAM wParam) } WORD ctrlId = LOWORD(wParam); - CWindow editCtrl = ::GetDlgItem(hDlg, ctrlId); - wchar_t text[20]; - editCtrl.GetWindowText(text, 20); + std::string text = GetCWindowText(editCtrl); if (srcTabId == TabGPR) { - uint64_t value = CEditReg64::ParseValue(stdstr().FromUTF16(text).c_str()); + uint64_t value = CEditReg64::ParseValue(text.c_str()); if (ctrlId == IDC_HI_EDIT) { g_Reg->m_HI.UDW = value; @@ -295,9 +293,8 @@ void CRegisterTabs::RegisterChanged(HWND hDlg, TAB_ID srcTabId, WPARAM wParam) return; } - uint32_t value = wcstoul(text, nullptr, 16); - wsprintf(text, L"%08X", value); - editCtrl.SetWindowText(text); // Reformat text + uint32_t value = strtoul(text.c_str(), nullptr, 16); + editCtrl.SetWindowText(stdstr_f("%08X", value).ToUTF16().c_str()); if (srcTabId == TabFPR) { @@ -921,25 +918,22 @@ stdstr CRegisterTabs::CopyTabRegisters(int id) break; } - record->Iterate(&tab, [&str](const CWindow *label, const CWindow *edit) + record->Iterate(tab, [&str](const CWindow & label, const CWindow & edit) { - str += stdstr_f( - "\r\n%s %s", - ::GetCWindowText(*label).c_str(), - ::GetCWindowText(*edit).c_str()); + str += stdstr_f( "\r\n%s %s", GetCWindowText(label).c_str(), GetCWindowText(edit).c_str()); }); switch (id) { case 0: - str += stdstr_f("\r\nHI %s", m_HIEdit.GetValueText().c_str()); - str += stdstr_f("\r\nLO %s", m_LOEdit.GetValueText().c_str()); + str += stdstr_f("\r\nHI %s", GetCWindowText(m_HIEdit).c_str()); + str += stdstr_f("\r\nLO %s", GetCWindowText(m_LOEdit).c_str()); break; case 1: - str += stdstr_f("\r\nFCSR %s", m_FCSREdit.GetValueText().c_str()); + str += stdstr_f("\r\nFCSR %s", GetCWindowText(m_FCSREdit).c_str()); break; case 4: - str += stdstr_f("\r\nSP (A4080000)\r\n00 SP_PC %s", m_SPPCEdit.GetValueText().c_str()); + str += stdstr_f("\r\nSP (A4080000)\r\n00 SP_PC %s", GetCWindowText(m_SPPCEdit).c_str()); break; } @@ -972,9 +966,10 @@ BOOL CEditReg64::Attach(HWND hWndNew) LRESULT CEditReg64::OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { + bHandled = TRUE; if (!isStepping()) { - goto canceled; + return 0; } char charCode = (char)wParam; @@ -983,20 +978,19 @@ LRESULT CEditReg64::OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandl { if (!isalnum(charCode)) { - goto unhandled; + bHandled = FALSE; } - goto canceled; + return 0; } if (isalpha(charCode) && !isupper(charCode)) { SendMessage(uMsg, toupper(wParam), lParam); - goto canceled; + return 0; } - wchar_t text[20]; - GetWindowText(text, 20); - int textLen = wcslen(text); + std::string text = GetCWindowText(*this); + int textLen = text.size(); if (textLen >= 17) { @@ -1004,39 +998,26 @@ LRESULT CEditReg64::OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandl GetSel(selStart, selEnd); if (selEnd - selStart == 0) { - goto canceled; + return 0; } } - if (charCode == ' ' && wcschr(text, ' ') != nullptr) + if (charCode == ' ' && strchr(text.c_str(), ' ') != nullptr) { - goto canceled; + return 0; } - -unhandled: bHandled = FALSE; return 0; - -canceled: - bHandled = TRUE; - return 0; } uint64_t CEditReg64::GetValue() { - wchar_t text[20]; - GetWindowText(text, 20); - return ParseValue(stdstr().FromUTF16(text).c_str()); -} - -stdstr CEditReg64::GetValueText() -{ - return ::GetCWindowText(*this); + return ParseValue(GetCWindowText(*this).c_str()); } LRESULT CEditReg64::OnLostFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) { - SetValue(GetValue()); // Clean up + SetValue(GetValue()); bHandled = FALSE; return 0; } diff --git a/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabs.h b/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabs.h index 57a13e402..e26f54480 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabs.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-RegisterTabs.h @@ -12,7 +12,6 @@ public: LRESULT OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnLostFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); uint64_t GetValue(); - stdstr GetValueText(); void SetValue(uint32_t h, uint32_t l); void SetValue(uint64_t value); diff --git a/Source/Project64/UserInterface/Debugger/Debugger-Scripts.cpp b/Source/Project64/UserInterface/Debugger/Debugger-Scripts.cpp index 0431ceae7..e52726802 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-Scripts.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-Scripts.cpp @@ -474,10 +474,9 @@ LRESULT CEditEval::OnKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BO { if (m_HistoryIdx > 0) { - wchar_t* code = m_History[--m_HistoryIdx]; - SetWindowText(code); - int selEnd = wcslen(code); - SetSel(selEnd, selEnd); + const std::string & Code = m_History[--m_HistoryIdx]; + SetWindowText(stdstr(Code).ToUTF16().c_str()); + SetSel((int)Code.length(), (int)Code.length()); } } else if (wParam == VK_DOWN) @@ -485,10 +484,9 @@ LRESULT CEditEval::OnKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BO int size = m_History.size(); if (m_HistoryIdx < size - 1) { - wchar_t* code = m_History[++m_HistoryIdx]; - SetWindowText(code); - int selEnd = wcslen(code); - SetSel(selEnd, selEnd); + const std::string & Code = m_History[++m_HistoryIdx]; + SetWindowText(stdstr(Code).ToUTF16().c_str()); + SetSel((int)Code.length(), (int)Code.length()); } else if (m_HistoryIdx < size) { @@ -504,11 +502,8 @@ LRESULT CEditEval::OnKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BO return 0; } - size_t codeLength = GetWindowTextLength() + 1; - wchar_t* code = (wchar_t*)malloc(codeLength * sizeof(wchar_t)); - GetWindowText(code, codeLength); - - m_ScriptWindow->EvaluateInSelectedInstance(stdstr().FromUTF16(code).c_str()); + std::string Code = GetCWindowText(*this); + m_ScriptWindow->EvaluateInSelectedInstance(Code.c_str()); SetWindowText(L""); int historySize = m_History.size(); @@ -516,9 +511,8 @@ LRESULT CEditEval::OnKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BO // Remove duplicate for (int i = 0; i < historySize; i++) { - if (wcscmp(code, m_History[i]) == 0) + if (strcmp(Code.c_str(), m_History[i].c_str()) == 0) { - free(m_History[i]); m_History.erase(m_History.begin() + i); historySize--; break; @@ -532,8 +526,8 @@ LRESULT CEditEval::OnKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BO historySize--; } - m_History.push_back(code); - m_HistoryIdx = ++historySize; + m_History.push_back(Code); + m_HistoryIdx = historySize++; } bHandled = FALSE; return 0; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-Scripts.h b/Source/Project64/UserInterface/Debugger/Debugger-Scripts.h index a4085633a..9f58523e8 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-Scripts.h +++ b/Source/Project64/UserInterface/Debugger/Debugger-Scripts.h @@ -3,6 +3,7 @@ #include "ScriptSystem.h" #include #include +#include class CScriptList : public CListViewCtrl { @@ -14,9 +15,8 @@ public: class CEditEval : public CWindowImpl { private: - //static char* m_EvalString; static const int HISTORY_MAX_ENTRIES = 20; - vector m_History; + std::vector m_History; int m_HistoryIdx; CDebugScripts* m_ScriptWindow; diff --git a/Source/Project64/UserInterface/Debugger/Debugger-Symbols.cpp b/Source/Project64/UserInterface/Debugger/Debugger-Symbols.cpp index 61a0a1c04..d7fccfdab 100644 --- a/Source/Project64/UserInterface/Debugger/Debugger-Symbols.cpp +++ b/Source/Project64/UserInterface/Debugger/Debugger-Symbols.cpp @@ -175,9 +175,8 @@ LRESULT CDebugSymbols::OnListDblClicked(NMHDR* pNMHDR) case SymbolsListView_Col_Name: if (m_SetValueDlg.DoModal("Set name", "New name:", symbol.m_Name)) { - wchar_t* szEnteredString = m_SetValueDlg.GetEnteredString(); m_Debugger->SymbolTable()->RemoveSymbolById(id); - m_Debugger->SymbolTable()->AddSymbol(symbol.m_Type, symbol.m_Address, stdstr().FromUTF16(szEnteredString).c_str(), symbol.m_Description); + m_Debugger->SymbolTable()->AddSymbol(symbol.m_Type, symbol.m_Address, m_SetValueDlg.GetEnteredString().c_str(), symbol.m_Description); } break; case SymbolsListView_Col_Value: @@ -187,7 +186,7 @@ LRESULT CDebugSymbols::OnListDblClicked(NMHDR* pNMHDR) m_Debugger->SymbolTable()->GetValueString(szValue, &symbol); if (m_SetValueDlg.DoModal("Change value", "New value:", szValue)) { - stdstr EnteredString = stdstr().FromUTF16(m_SetValueDlg.GetEnteredString()); + const std::string & EnteredString = m_SetValueDlg.GetEnteredString(); switch (symbol.m_Type) { @@ -272,9 +271,8 @@ LRESULT CDebugSymbols::OnListDblClicked(NMHDR* pNMHDR) case SymbolsListView_Col_Description: if (m_SetValueDlg.DoModal("Set description", "New description:", symbol.m_Description)) { - stdstr szEnteredString = stdstr().FromUTF16(m_SetValueDlg.GetEnteredString()); m_Debugger->SymbolTable()->RemoveSymbolById(id); - m_Debugger->SymbolTable()->AddSymbol(symbol.m_Type, symbol.m_Address, symbol.m_Name, szEnteredString.c_str()); + m_Debugger->SymbolTable()->AddSymbol(symbol.m_Type, symbol.m_Address, symbol.m_Name, m_SetValueDlg.GetEnteredString().c_str()); } break; } diff --git a/Source/Project64/UserInterface/Settings/SettingsPage-Directories.cpp b/Source/Project64/UserInterface/Settings/SettingsPage-Directories.cpp index 6cad7f5e0..e1920b7bc 100644 --- a/Source/Project64/UserInterface/Settings/SettingsPage-Directories.cpp +++ b/Source/Project64/UserInterface/Settings/SettingsPage-Directories.cpp @@ -67,7 +67,7 @@ void COptionsDirectoriesPage::SelectDirectory(LanguageStringID Title, CModifiedE LPITEMIDLIST pidl; BROWSEINFO bi; - stdstr InitialDir = EditBox.GetWindowText(); + std::string InitialDir = GetCWindowText(EditBox); std::wstring wTitle = wGS(Title); bi.hwndOwner = m_hWnd; bi.pidlRoot = nullptr; @@ -264,8 +264,7 @@ void COptionsDirectoriesPage::UpdateDirectory(CModifiedEditBox & EditBox, Settin { if (EditBox.IsChanged()) { - stdstr dir = EditBox.GetWindowText(); - g_Settings->SaveString(Type, dir.c_str()); + g_Settings->SaveString(Type, GetCWindowText(EditBox).c_str()); } if (EditBox.IsReset()) { diff --git a/Source/Project64/UserInterface/Settings/SettingsPage-DiskDrive.cpp b/Source/Project64/UserInterface/Settings/SettingsPage-DiskDrive.cpp index ee88f7c03..c0d0c79b5 100644 --- a/Source/Project64/UserInterface/Settings/SettingsPage-DiskDrive.cpp +++ b/Source/Project64/UserInterface/Settings/SettingsPage-DiskDrive.cpp @@ -44,8 +44,7 @@ void CDiskDrivePage::ApplySettings(bool UpdateScreen) { if (m_IplDirJp.IsChanged()) { - stdstr file = m_IplDirJp.GetWindowText(); - g_Settings->SaveString(File_DiskIPLPath, file.c_str()); + g_Settings->SaveString(File_DiskIPLPath, GetCWindowText(m_IplDirJp).c_str()); } if (m_IplDirJp.IsReset()) { @@ -54,8 +53,7 @@ void CDiskDrivePage::ApplySettings(bool UpdateScreen) if (m_IplDirUs.IsChanged()) { - stdstr file = m_IplDirUs.GetWindowText(); - g_Settings->SaveString(File_DiskIPLUSAPath, file.c_str()); + g_Settings->SaveString(File_DiskIPLUSAPath, GetCWindowText(m_IplDirUs).c_str()); } if (m_IplDirUs.IsReset()) { @@ -64,8 +62,7 @@ void CDiskDrivePage::ApplySettings(bool UpdateScreen) if (m_IplDirTl.IsChanged()) { - stdstr file = m_IplDirTl.GetWindowText(); - g_Settings->SaveString(File_DiskIPLTOOLPath, file.c_str()); + g_Settings->SaveString(File_DiskIPLTOOLPath, GetCWindowText(m_IplDirTl).c_str()); } if (m_IplDirTl.IsReset()) { diff --git a/Source/Project64/UserInterface/Settings/SettingsPage.h b/Source/Project64/UserInterface/Settings/SettingsPage.h index aaa7c2345..28bc8508c 100644 --- a/Source/Project64/UserInterface/Settings/SettingsPage.h +++ b/Source/Project64/UserInterface/Settings/SettingsPage.h @@ -86,7 +86,7 @@ protected: { if (EditBox.IsChanged()) { - stdstr Value = EditBox.GetWindowText(); + stdstr Value = GetCWindowText(EditBox); if (EditBox.IsbString()) { g_Settings->SaveString(Type, Value); diff --git a/Source/Project64/UserInterface/SupportEnterCode.cpp b/Source/Project64/UserInterface/SupportEnterCode.cpp index 44058e5ab..9021fc94a 100644 --- a/Source/Project64/UserInterface/SupportEnterCode.cpp +++ b/Source/Project64/UserInterface/SupportEnterCode.cpp @@ -237,14 +237,9 @@ LRESULT CRequestCode::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*l LRESULT CRequestCode::OnOkCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { - CWindow EmailWnd(GetDlgItem(IDC_EMAIL)); - int EmailLen = EmailWnd.GetWindowTextLength(); - std::wstring Email; - Email.resize(EmailLen + 1); - EmailWnd.GetWindowText((wchar_t *)Email.c_str(), Email.length()); GetDlgItem(IDOK).EnableWindow(false); GetDlgItem(IDCANCEL).EnableWindow(false); - if (m_Support.RequestCode(stdstr().FromUTF16(Email.c_str()).c_str())) + if (m_Support.RequestCode(GetCWindowText(GetDlgItem(IDC_EMAIL)).c_str())) { MessageBox(wGS(MSG_SUPPORT_REQUESTCODE_SUCCESS).c_str(), wGS(MSG_SUPPORT_REQUESTCODE_TITLE).c_str(), MB_OK); EndDialog(wID); diff --git a/Source/Project64/UserInterface/WTLControls/EditNumber32.cpp b/Source/Project64/UserInterface/WTLControls/EditNumber32.cpp index de488de42..1cd3362fe 100644 --- a/Source/Project64/UserInterface/WTLControls/EditNumber32.cpp +++ b/Source/Project64/UserInterface/WTLControls/EditNumber32.cpp @@ -15,13 +15,11 @@ bool CEditNumber32::IsHexConvertableText(LPTSTR _text) int start, end; GetSel(start, end); - wchar_t WindowText[200]; - GetWindowText(WindowText, sizeof(WindowText) / sizeof(WindowText[0])); - + std::string WindowText = GetCWindowText(*this); bool bPaste = true; - size_t Len = wcslen(WindowText); - wchar_t head = Len > 0 ? WindowText[0] : 0; - wchar_t second = Len > 1 ? WindowText[1] : 0; + size_t Len = WindowText.size(); + char head = Len > 0 ? WindowText[0] : 0; + char second = Len > 1 ? WindowText[1] : 0; if (second == 'X' || second == 'x') { @@ -170,12 +168,9 @@ LRESULT CEditNumber32::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& { int start, end; GetSel(start, end); - wchar_t WindowText[200]; - GetWindowText(WindowText, sizeof(WindowText) / sizeof(WindowText[0])); - size_t Len = wcslen(WindowText); - - wchar_t head = Len > 0 ? WindowText[0] : 0; - wchar_t second = Len > 1 ? WindowText[1] : 0; + std::string WindowText = GetCWindowText(*this); + char Head = WindowText.length() > 0 ? WindowText[0] : 0; + char Second = WindowText.length() > 1 ? WindowText[1] : 0; if (uMsg == WM_CHAR) { @@ -184,7 +179,7 @@ LRESULT CEditNumber32::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& if (m_DisplayType == DisplayHex) { MaxLen = 8; - if (second == L'x' || second == L'X') + if (Second == L'x' || Second == L'X') { MaxLen += 2; } @@ -192,7 +187,7 @@ LRESULT CEditNumber32::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& wchar_t c = (wchar_t)wParam; if (wParam < 32) { - if (wParam == 8 && (second == L'x' || second == L'X') && head == L'0' && end == 1) + if (wParam == 8 && (Second == 'x' || Second == 'X') && Head == '0' && end == 1) { // Does not allow to delete '0' before x bHandled = true; @@ -203,7 +198,7 @@ LRESULT CEditNumber32::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& return TRUE; } - if (second == L'x' || second == L'X') + if (Second == 'x' || Second == 'X') { // Does not allow to change head except select includes first and second if (start <= 1 && end <= 1) @@ -212,9 +207,9 @@ LRESULT CEditNumber32::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& return TRUE; } } - if (start == 1 && (c == L'X' || c == L'x') && head == L'0') + if (start == 1 && (c == 'X' || c == 'x') && Head == '0') { - if (c == L'X') + if (c == 'X') { SendMessage(uMsg, L'x', lParam); bHandled = true; @@ -226,7 +221,7 @@ LRESULT CEditNumber32::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& } else if (c >= L'0' && c <= L'9' || c >= L'A' && c <= L'F') { - if (Len >= MaxLen && start == end) + if (WindowText.length() >= MaxLen && start == end) { bHandled = true; return true; @@ -236,7 +231,7 @@ LRESULT CEditNumber32::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& } else if (c >= L'a' && c <= L'f') { - if (Len >= MaxLen && start == end) + if (WindowText.length() >= MaxLen && start == end) { bHandled = true; return true; @@ -272,16 +267,15 @@ void CEditNumber32::SetDisplayType(DisplayType Type) uint32_t CEditNumber32::GetValue(void) { - wchar_t text[200]; - GetWindowText(text, sizeof(text) / sizeof(text[0])); + std::string Text = GetCWindowText(*this); if (m_DisplayType == DisplayDec) { - return _wtoi(text); + return atoi(Text.c_str()); } - size_t Finish = wcslen(text); - wchar_t second = Finish > 1 ? text[1] : 0; - size_t Start = (second == L'x' || second == L'X') ? 2 : 0; + size_t Finish = Text.length(); + wchar_t Second = Finish > 1 ? Text[1] : 0; + size_t Start = (Second == 'x' || Second == 'X') ? 2 : 0; if (Finish > 8 + Start) { Finish = 8 + Start; } @@ -289,30 +283,30 @@ uint32_t CEditNumber32::GetValue(void) for (size_t i = Start; i < Finish; i++) { Value = (Value << 4); - switch (text[i]) + switch (Text[i]) { - case L'0': break; - case L'1': Value += 1; break; - case L'2': Value += 2; break; - case L'3': Value += 3; break; - case L'4': Value += 4; break; - case L'5': Value += 5; break; - case L'6': Value += 6; break; - case L'7': Value += 7; break; - case L'8': Value += 8; break; - case L'9': Value += 9; break; - case L'A': Value += 10; break; - case L'a': Value += 10; break; - case L'B': Value += 11; break; - case L'b': Value += 11; break; - case L'C': Value += 12; break; - case L'c': Value += 12; break; - case L'D': Value += 13; break; - case L'd': Value += 13; break; - case L'E': Value += 14; break; - case L'e': Value += 14; break; - case L'F': Value += 15; break; - case L'f': Value += 15; break; + case '0': break; + case '1': Value += 1; break; + case '2': Value += 2; break; + case '3': Value += 3; break; + case '4': Value += 4; break; + case '5': Value += 5; break; + case '6': Value += 6; break; + case '7': Value += 7; break; + case '8': Value += 8; break; + case '9': Value += 9; break; + case 'A': Value += 10; break; + case 'a': Value += 10; break; + case 'B': Value += 11; break; + case 'b': Value += 11; break; + case 'C': Value += 12; break; + case 'c': Value += 12; break; + case 'D': Value += 13; break; + case 'd': Value += 13; break; + case 'E': Value += 14; break; + case 'e': Value += 14; break; + case 'F': Value += 15; break; + case 'f': Value += 15; break; default: Value = (Value >> 4); i = Finish; @@ -321,11 +315,6 @@ uint32_t CEditNumber32::GetValue(void) return Value; } -stdstr CEditNumber32::GetValueText(void) -{ - return ::GetCWindowText(*this); -} - void CEditNumber32::SetValue(uint32_t Value, DisplayMode Display) { stdstr text; diff --git a/Source/Project64/UserInterface/WTLControls/EditNumber32.h b/Source/Project64/UserInterface/WTLControls/EditNumber32.h index cdd0e0b33..14619da18 100644 --- a/Source/Project64/UserInterface/WTLControls/EditNumber32.h +++ b/Source/Project64/UserInterface/WTLControls/EditNumber32.h @@ -20,7 +20,6 @@ public: BOOL AttachToDlgItem(HWND parent, UINT dlgID); void SetDisplayType(DisplayType Type); uint32_t GetValue(void); - stdstr GetValueText(void); void SetValue(uint32_t Value, DisplayMode Display = DisplayMode::ShowHexIdent); protected: diff --git a/Source/Project64/UserInterface/WTLControls/ModifiedEditBox.cpp b/Source/Project64/UserInterface/WTLControls/ModifiedEditBox.cpp index eaeeddcdf..0c0cc8036 100644 --- a/Source/Project64/UserInterface/WTLControls/ModifiedEditBox.cpp +++ b/Source/Project64/UserInterface/WTLControls/ModifiedEditBox.cpp @@ -67,12 +67,6 @@ void CModifiedEditBox::SetChanged(bool Changed) } } -stdstr CModifiedEditBox::GetWindowText(void) -{ - ATLASSERT(::IsWindow(m_hWnd)); - return ::GetCWindowText(*this); -} - void CModifiedEditBox::SetTextField(HWND hWnd) { if (m_TextField && m_OriginalFont) diff --git a/Source/Project64/UserInterface/WTLControls/ModifiedEditBox.h b/Source/Project64/UserInterface/WTLControls/ModifiedEditBox.h index a1d8aa8ea..a5b76d6ce 100644 --- a/Source/Project64/UserInterface/WTLControls/ModifiedEditBox.h +++ b/Source/Project64/UserInterface/WTLControls/ModifiedEditBox.h @@ -17,7 +17,6 @@ public: void SetReset ( bool Reset ); void SetChanged (bool Changed); - stdstr GetWindowText(); void SetTextField (HWND hWnd); inline bool IsChanged ( void ) const diff --git a/Source/Project64/UserInterface/WTLControls/PartialGroupBox.cpp b/Source/Project64/UserInterface/WTLControls/PartialGroupBox.cpp index 19c74b396..da51bdd7d 100644 --- a/Source/Project64/UserInterface/WTLControls/PartialGroupBox.cpp +++ b/Source/Project64/UserInterface/WTLControls/PartialGroupBox.cpp @@ -54,11 +54,9 @@ void CPartialGroupBox::OnPaint(HDC /*hDC*/) dc.SetMapMode(MM_TEXT); dc.SelectBrush(GetSysColorBrush(COLOR_BTNFACE)); - wchar_t grptext[500]; - ::GetWindowText(m_hWnd, grptext, sizeof(grptext) / sizeof(grptext[0])); - + stdstr grptext = GetCWindowText(m_hWnd); CRect fontsizerect(0, 0, 0, 0); - dc.DrawText(grptext, -1, fontsizerect, DT_SINGLELINE | DT_LEFT | DT_CALCRECT); + dc.DrawText(grptext.ToUTF16().c_str(), -1, fontsizerect, DT_SINGLELINE | DT_LEFT | DT_CALCRECT); CRect framerect(controlrect); framerect.top += (fontsizerect.Height()) / 2; @@ -77,7 +75,7 @@ void CPartialGroupBox::OnPaint(HDC /*hDC*/) Draw3dLine(dc, framerect, GetSysColor(COLOR_3DHILIGHT), GetSysColor(COLOR_3DSHADOW)); } - if (wcslen(grptext)) + if (!grptext.empty()) { CRect fontrect(controlrect); fontrect.bottom = controlrect.top + fontsizerect.Height(); @@ -106,6 +104,6 @@ void CPartialGroupBox::OnPaint(HDC /*hDC*/) dc.SetBkMode(OPAQUE); dc.SetBkColor(GetSysColor(COLOR_BTNFACE)); - dc.DrawText(grptext, -1, fontrect, DT_SINGLELINE | DT_LEFT); + dc.DrawText(grptext.ToUTF16().c_str(), -1, fontrect, DT_SINGLELINE | DT_LEFT); } }