From 2a5f64604f0786759d303e5b9399192d87796c7d Mon Sep 17 00:00:00 2001 From: Benedikt Freisen Date: Sun, 9 Oct 2016 11:42:37 +0000 Subject: [PATCH] [MSPAINT] get rid of all _stprintf occurrences and the respective magic number sized TCHAR arrays svn path=/trunk/; revision=72945 --- reactos/base/applications/mspaint/dialogs.cpp | 36 +++++++++---------- reactos/base/applications/mspaint/dib.cpp | 12 +++---- reactos/base/applications/mspaint/imgarea.cpp | 24 ++++++------- .../base/applications/mspaint/registry.cpp | 10 +++--- .../base/applications/mspaint/selection.cpp | 6 ++-- reactos/base/applications/mspaint/sizebox.cpp | 20 +++++------ 6 files changed, 51 insertions(+), 57 deletions(-) diff --git a/reactos/base/applications/mspaint/dialogs.cpp b/reactos/base/applications/mspaint/dialogs.cpp index a0c5af1a1e1..dd1887be8d3 100644 --- a/reactos/base/applications/mspaint/dialogs.cpp +++ b/reactos/base/applications/mspaint/dialogs.cpp @@ -76,9 +76,6 @@ ATTDlgWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { case WM_INITDIALOG: { - TCHAR strrc[100]; - TCHAR res[100]; - widthSetInDlg = imageModel.GetWidth(); heightSetInDlg = imageModel.GetHeight(); @@ -90,20 +87,19 @@ ATTDlgWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if (isAFile) { TCHAR date[100]; - TCHAR size[100]; TCHAR temp[100]; GetDateFormat(LOCALE_USER_DEFAULT, 0, &fileTime, NULL, date, SIZEOF(date)); GetTimeFormat(LOCALE_USER_DEFAULT, 0, &fileTime, NULL, temp, SIZEOF(temp)); _tcscat(date, _T(" ")); _tcscat(date, temp); - LoadString(hProgInstance, IDS_FILESIZE, strrc, SIZEOF(strrc)); - _stprintf(size, strrc, fileSize); + CString strSize; + strSize.Format(IDS_FILESIZE, fileSize); SetDlgItemText(hwnd, IDD_ATTRIBUTESTEXT6, date); - SetDlgItemText(hwnd, IDD_ATTRIBUTESTEXT7, size); + SetDlgItemText(hwnd, IDD_ATTRIBUTESTEXT7, strSize); } - LoadString(hProgInstance, IDS_PRINTRES, strrc, SIZEOF(strrc)); - _stprintf(res, strrc, fileHPPM, fileVPPM); - SetDlgItemText(hwnd, IDD_ATTRIBUTESTEXT8, res); + CString strRes; + strRes.Format(IDS_PRINTRES, fileHPPM, fileVPPM); + SetDlgItemText(hwnd, IDD_ATTRIBUTESTEXT8, strRes); return TRUE; } case WM_CLOSE: @@ -128,20 +124,20 @@ ATTDlgWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case IDD_ATTRIBUTESRB1: { - TCHAR number[100]; - _stprintf(number, _T("%.3lf"), widthSetInDlg / (0.0254 * fileHPPM)); - SetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT1, number); - _stprintf(number, _T("%.3lf"), heightSetInDlg / (0.0254 * fileVPPM)); - SetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT2, number); + CString strNum; + strNum.Format(_T("%.3lf"), widthSetInDlg / (0.0254 * fileHPPM)); + SetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT1, strNum); + strNum.Format(_T("%.3lf"), heightSetInDlg / (0.0254 * fileVPPM)); + SetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT2, strNum); break; } case IDD_ATTRIBUTESRB2: { - TCHAR number[100]; - _stprintf(number, _T("%.3lf"), widthSetInDlg * 100.0 / fileHPPM); - SetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT1, number); - _stprintf(number, _T("%.3lf"), heightSetInDlg * 100.0 / fileVPPM); - SetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT2, number); + CString strNum; + strNum.Format(_T("%.3lf"), widthSetInDlg * 100.0 / fileHPPM); + SetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT1, strNum); + strNum.Format(_T("%.3lf"), heightSetInDlg * 100.0 / fileVPPM); + SetDlgItemText(hwnd, IDD_ATTRIBUTESEDIT2, strNum); break; } case IDD_ATTRIBUTESRB3: diff --git a/reactos/base/applications/mspaint/dib.cpp b/reactos/base/applications/mspaint/dib.cpp index ffbc33f3359..de98fee2905 100644 --- a/reactos/base/applications/mspaint/dib.cpp +++ b/reactos/base/applications/mspaint/dib.cpp @@ -73,13 +73,11 @@ SaveDIBToFile(HBITMAP hBitmap, LPTSTR FileName, HDC hDC, LPSYSTEMTIME time, int void ShowFileLoadError(LPCTSTR name) { - TCHAR programname[20]; - TCHAR loaderrortext[100]; - TCHAR temptext[500]; - LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname)); - LoadString(hProgInstance, IDS_LOADERRORTEXT, loaderrortext, SIZEOF(loaderrortext)); - _stprintf(temptext, loaderrortext, name); - mainWindow.MessageBox(temptext, programname, MB_OK | MB_ICONEXCLAMATION); + CString strText; + strText.Format(IDS_LOADERRORTEXT, (LPCTSTR) name); + CString strProgramName; + strProgramName.LoadString(IDS_PROGRAMNAME); + mainWindow.MessageBox(strText, strProgramName, MB_OK | MB_ICONEXCLAMATION); } void diff --git a/reactos/base/applications/mspaint/imgarea.cpp b/reactos/base/applications/mspaint/imgarea.cpp index 8178dc8a678..bf8afea4476 100644 --- a/reactos/base/applications/mspaint/imgarea.cpp +++ b/reactos/base/applications/mspaint/imgarea.cpp @@ -252,9 +252,9 @@ LRESULT CImgAreaWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO if (!drawing) { - TCHAR coordStr[100]; - _stprintf(coordStr, _T("%ld, %ld"), xNow, yNow); - SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM) coordStr); + CString strCoord; + strCoord.Format(_T("%ld, %ld"), xNow, yNow); + SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM) (LPCTSTR) strCoord); } } if (drawing) @@ -291,9 +291,9 @@ LRESULT CImgAreaWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO case TOOL_AIRBRUSH: case TOOL_SHAPE: { - TCHAR coordStr[100]; - _stprintf(coordStr, _T("%ld, %ld"), xNow, yNow); - SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM) coordStr); + CString strCoord; + strCoord.Format(_T("%ld, %ld"), xNow, yNow); + SendMessage(hStatusBar, SB_SETTEXT, 1, (LPARAM) (LPCTSTR) strCoord); break; } } @@ -303,11 +303,11 @@ LRESULT CImgAreaWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO Invalidate(FALSE); if ((toolsModel.GetActiveTool() >= TOOL_TEXT) || (toolsModel.GetActiveTool() == TOOL_RECTSEL) || (toolsModel.GetActiveTool() == TOOL_FREESEL)) { - TCHAR sizeStr[100]; + CString strSize; if ((toolsModel.GetActiveTool() >= TOOL_LINE) && (GetAsyncKeyState(VK_SHIFT) < 0)) yRel = xRel; - _stprintf(sizeStr, _T("%ld x %ld"), xRel, yRel); - SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr); + strSize.Format(_T("%ld x %ld"), xRel, yRel); + SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) (LPCTSTR) strSize); } } if ((wParam & MK_RBUTTON) != 0) @@ -316,11 +316,11 @@ LRESULT CImgAreaWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO Invalidate(FALSE); if (toolsModel.GetActiveTool() >= TOOL_TEXT) { - TCHAR sizeStr[100]; + CString strSize; if ((toolsModel.GetActiveTool() >= TOOL_LINE) && (GetAsyncKeyState(VK_SHIFT) < 0)) yRel = xRel; - _stprintf(sizeStr, _T("%ld x %ld"), xRel, yRel); - SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr); + strSize.Format(_T("%ld x %ld"), xRel, yRel); + SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) (LPCTSTR) strSize); } } } diff --git a/reactos/base/applications/mspaint/registry.cpp b/reactos/base/applications/mspaint/registry.cpp index f89674c731d..040b4a3171b 100644 --- a/reactos/base/applications/mspaint/registry.cpp +++ b/reactos/base/applications/mspaint/registry.cpp @@ -46,15 +46,15 @@ void RegistrySettings::SetWallpaper(LPCTSTR szFileName, DWORD dwStyle, DWORD dwT CRegKey desktop; if (desktop.Open(HKEY_CURRENT_USER, _T("Control Panel\\Desktop")) == ERROR_SUCCESS) { - TCHAR szStyle[3], szTile[3]; + CString strStyle, strTile; desktop.SetStringValue(_T("Wallpaper"), szFileName); - _stprintf(szStyle, _T("%lu"), dwStyle); - _stprintf(szTile, _T("%lu"), dwTile); + strStyle.Format(_T("%lu"), dwStyle); + strTile.Format(_T("%lu"), dwTile); - desktop.SetStringValue(_T("WallpaperStyle"), szStyle); - desktop.SetStringValue(_T("TileWallpaper"), szTile); + desktop.SetStringValue(_T("WallpaperStyle"), strStyle); + desktop.SetStringValue(_T("TileWallpaper"), strTile); } } diff --git a/reactos/base/applications/mspaint/selection.cpp b/reactos/base/applications/mspaint/selection.cpp index d237ebd2724..a9e7530a6b0 100644 --- a/reactos/base/applications/mspaint/selection.cpp +++ b/reactos/base/applications/mspaint/selection.cpp @@ -155,7 +155,6 @@ LRESULT CSelectionWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, B { if (m_bMoving) { - TCHAR sizeStr[100]; imageModel.ResetToPrevious(); m_ptFrac.x += GET_X_LPARAM(lParam) - m_ptPos.x; m_ptFrac.y += GET_Y_LPARAM(lParam) - m_ptPos.y; @@ -173,8 +172,9 @@ LRESULT CSelectionWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, B } selectionModel.ModifyDestRect(m_ptDelta, m_iAction); - _stprintf(sizeStr, _T("%d x %d"), selectionModel.GetDestRectWidth(), selectionModel.GetDestRectHeight()); - SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr); + CString strSize; + strSize.Format(_T("%d x %d"), selectionModel.GetDestRectWidth(), selectionModel.GetDestRectHeight()); + SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) (LPCTSTR) strSize); if (toolsModel.GetActiveTool() == TOOL_TEXT) { diff --git a/reactos/base/applications/mspaint/sizebox.cpp b/reactos/base/applications/mspaint/sizebox.cpp index 29b73eef676..1ea92d7f6bb 100644 --- a/reactos/base/applications/mspaint/sizebox.cpp +++ b/reactos/base/applications/mspaint/sizebox.cpp @@ -42,7 +42,7 @@ LRESULT CSizeboxWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO { if (resizing) { - TCHAR sizeStr[100]; + CString strSize; short xRel; short yRel; int imgXRes = imageModel.GetWidth(); @@ -50,22 +50,22 @@ LRESULT CSizeboxWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOO xRel = (GET_X_LPARAM(lParam) - xOrig) * 1000 / toolsModel.GetZoom(); yRel = (GET_Y_LPARAM(lParam) - yOrig) * 1000 / toolsModel.GetZoom(); if (m_hWnd == sizeboxLeftTop.m_hWnd) - _stprintf(sizeStr, _T("%d x %d"), imgXRes - xRel, imgYRes - yRel); + strSize.Format(_T("%d x %d"), imgXRes - xRel, imgYRes - yRel); if (m_hWnd == sizeboxCenterTop.m_hWnd) - _stprintf(sizeStr, _T("%d x %d"), imgXRes, imgYRes - yRel); + strSize.Format(_T("%d x %d"), imgXRes, imgYRes - yRel); if (m_hWnd == sizeboxRightTop.m_hWnd) - _stprintf(sizeStr, _T("%d x %d"), imgXRes + xRel, imgYRes - yRel); + strSize.Format(_T("%d x %d"), imgXRes + xRel, imgYRes - yRel); if (m_hWnd == sizeboxLeftCenter.m_hWnd) - _stprintf(sizeStr, _T("%d x %d"), imgXRes - xRel, imgYRes); + strSize.Format(_T("%d x %d"), imgXRes - xRel, imgYRes); if (m_hWnd == sizeboxRightCenter.m_hWnd) - _stprintf(sizeStr, _T("%d x %d"), imgXRes + xRel, imgYRes); + strSize.Format(_T("%d x %d"), imgXRes + xRel, imgYRes); if (m_hWnd == sizeboxLeftBottom.m_hWnd) - _stprintf(sizeStr, _T("%d x %d"), imgXRes - xRel, imgYRes + yRel); + strSize.Format(_T("%d x %d"), imgXRes - xRel, imgYRes + yRel); if (m_hWnd == sizeboxCenterBottom.m_hWnd) - _stprintf(sizeStr, _T("%d x %d"), imgXRes, imgYRes + yRel); + strSize.Format(_T("%d x %d"), imgXRes, imgYRes + yRel); if (m_hWnd == sizeboxRightBottom.m_hWnd) - _stprintf(sizeStr, _T("%d x %d"), imgXRes + xRel, imgYRes + yRel); - SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr); + strSize.Format(_T("%d x %d"), imgXRes + xRel, imgYRes + yRel); + SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) (LPCTSTR) strSize); } return 0; } -- 2.17.1