https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d7ece626cbda18c8d76b9…
commit d7ece626cbda18c8d76b93a3d0f5dfa049646a35
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Sat Nov 4 05:56:10 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Sat Nov 4 05:56:10 2023 +0900
[MSPAINT] Fix Copy-To-File feature (#5877)
The Copy-To-File feature had some bugs that the user couldn't save.
- Modify SelectionModel::GetSelectionContents.
- Delete SelectionModel::CopyBitmap, SelectionModel::LockBitmap,
and SelectionModel::UnlockBitmap functions.
CORE-19186
---
base/applications/mspaint/dialogs.cpp | 6 ++---
base/applications/mspaint/main.cpp | 15 ++++++-----
base/applications/mspaint/precomp.h | 1 +
base/applications/mspaint/registry.cpp | 6 ++---
base/applications/mspaint/selectionmodel.cpp | 35 +++++++-----------------
base/applications/mspaint/selectionmodel.h | 5 +---
base/applications/mspaint/textedit.cpp | 2 +-
base/applications/mspaint/winproc.cpp | 40 +++++++++++++++++-----------
8 files changed, 51 insertions(+), 59 deletions(-)
diff --git a/base/applications/mspaint/dialogs.cpp
b/base/applications/mspaint/dialogs.cpp
index faaf5d3fbfa..c56eaaf5f49 100644
--- a/base/applications/mspaint/dialogs.cpp
+++ b/base/applications/mspaint/dialogs.cpp
@@ -361,10 +361,10 @@ void CFontsDialog::InitFontSizes()
HWND hwndSizes = GetDlgItem(IDD_FONTSSIZES);
ComboBox_ResetContent(hwndSizes);
- TCHAR szText[16];
+ WCHAR szText[16];
for (UINT i = 0; i < _countof(s_sizes); ++i)
{
- wsprintf(szText, TEXT("%d"), s_sizes[i]);
+ StringCchPrintfW(szText, _countof(szText), L"%d", s_sizes[i]);
INT iItem = ComboBox_AddString(hwndSizes, szText);
if (s_sizes[i] == (INT)registrySettings.PointSize)
ComboBox_SetCurSel(hwndSizes, iItem);
@@ -372,7 +372,7 @@ void CFontsDialog::InitFontSizes()
if (ComboBox_GetCurSel(hwndSizes) == CB_ERR)
{
- wsprintf(szText, TEXT("%d"), (INT)registrySettings.PointSize);
+ StringCchPrintfW(szText, _countof(szText), L"%d",
(INT)registrySettings.PointSize);
::SetWindowText(hwndSizes, szText);
}
}
diff --git a/base/applications/mspaint/main.cpp b/base/applications/mspaint/main.cpp
index 63db53f02de..0f133cbe485 100644
--- a/base/applications/mspaint/main.cpp
+++ b/base/applications/mspaint/main.cpp
@@ -7,6 +7,7 @@
#include "precomp.h"
+#include <dlgs.h>
#include <mapi.h>
POINT g_ptStart, g_ptEnd;
@@ -55,7 +56,7 @@ FileExtFromFilter(LPTSTR pExt, OPENFILENAME *pOFN)
CharLower(pExt);
return TRUE;
}
- pch += lstrlen(pch) + 1;
+ pch += wcslen(pch) + 1;
}
return FALSE;
}
@@ -66,6 +67,7 @@ OFNHookProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HWND hParent;
OFNOTIFY *pon;
+ WCHAR Path[MAX_PATH];
switch (uMsg)
{
case WM_NOTIFY:
@@ -73,11 +75,10 @@ OFNHookProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
if (pon->hdr.code == CDN_TYPECHANGE)
{
hParent = GetParent(hwnd);
- TCHAR Path[MAX_PATH];
- SendMessage(hParent, CDM_GETFILEPATH, _countof(Path), (LPARAM)Path);
- FileExtFromFilter(PathFindExtension(Path), pon->lpOFN);
- SendMessage(hParent, CDM_SETCONTROLTEXT, 0x047c,
(LPARAM)PathFindFileName(Path));
- lstrcpyn(pon->lpOFN->lpstrFile, Path, pon->lpOFN->nMaxFile);
+ SendMessageW(hParent, CDM_GETFILEPATH, _countof(Path), (LPARAM)Path);
+ FileExtFromFilter(PathFindExtensionW(Path), pon->lpOFN);
+ SendMessageW(hParent, CDM_SETCONTROLTEXT, cmb13,
(LPARAM)PathFindFileNameW(Path));
+ StringCchCopyW(pon->lpOFN->lpstrFile, pon->lpOFN->nMaxFile,
Path);
}
break;
}
@@ -251,7 +252,7 @@ BOOL CMainWindow::GetSaveFileName(IN OUT LPTSTR pszFile, INT
cchMaxFile)
if (*pchDotExt == UNICODE_NULL)
{
// Choose PNG
- wcscat(pszFile, L".png");
+ StringCchCatW(pszFile, cchMaxFile, L".png");
for (INT i = 0; i < aguidFileTypesE.GetSize(); ++i)
{
if (aguidFileTypesE[i] == Gdiplus::ImageFormatPNG)
diff --git a/base/applications/mspaint/precomp.h b/base/applications/mspaint/precomp.h
index a24f1a3b654..6f22eb69e8d 100644
--- a/base/applications/mspaint/precomp.h
+++ b/base/applications/mspaint/precomp.h
@@ -25,6 +25,7 @@
#include <math.h>
#include <shellapi.h>
#include <htmlhelp.h>
+#include <strsafe.h>
#include "atlimagedx.h"
#include <debug.h>
diff --git a/base/applications/mspaint/registry.cpp
b/base/applications/mspaint/registry.cpp
index bdaf7a7cd17..07778117ae8 100644
--- a/base/applications/mspaint/registry.cpp
+++ b/base/applications/mspaint/registry.cpp
@@ -123,7 +123,7 @@ void RegistrySettings::Load(INT nCmdShow)
TCHAR szName[64];
for (INT i = 0; i < MAX_RECENT_FILES; ++i)
{
- wsprintf(szName, _T("File%u"), i + 1);
+ StringCchPrintfW(szName, _countof(szName), L"File%u", i + 1);
ReadString(files, szName, strFiles[i]);
}
}
@@ -204,10 +204,10 @@ void RegistrySettings::Store()
CRegKey files;
if (files.Create(paint, _T("Recent File List")) == ERROR_SUCCESS)
{
- TCHAR szName[64];
+ WCHAR szName[64];
for (INT iFile = 0; iFile < MAX_RECENT_FILES; ++iFile)
{
- wsprintf(szName, _T("File%u"), iFile + 1);
+ StringCchPrintfW(szName, _countof(szName), L"File%u", iFile + 1);
files.SetStringValue(szName, strFiles[iFile]);
}
}
diff --git a/base/applications/mspaint/selectionmodel.cpp
b/base/applications/mspaint/selectionmodel.cpp
index e7263fa4e1f..c66361da6e4 100644
--- a/base/applications/mspaint/selectionmodel.cpp
+++ b/base/applications/mspaint/selectionmodel.cpp
@@ -152,16 +152,19 @@ void SelectionModel::DrawSelection(HDC hDCImage, COLORREF crBg, BOOL
bBgTranspar
DeleteDC(hMemDC);
}
-void SelectionModel::GetSelectionContents(HDC hDCImage)
+HBITMAP SelectionModel::GetSelectionContents()
{
- ClearColorImage();
+ if (m_hbmColor)
+ return CopyDIBImage(m_hbmColor, m_rc.Width(), m_rc.Height());
HDC hMemDC = ::CreateCompatibleDC(NULL);
- m_hbmColor = CreateColorDIB(m_rc.Width(), m_rc.Height(), RGB(255, 255, 255));
- HGDIOBJ hbmOld = ::SelectObject(hMemDC, m_hbmColor);
- ::BitBlt(hMemDC, 0, 0, m_rc.Width(), m_rc.Height(), hDCImage, m_rc.left, m_rc.top,
SRCCOPY);
+ HBITMAP hBitmap = CreateColorDIB(m_rc.Width(), m_rc.Height(), RGB(255, 255, 255));
+ HGDIOBJ hbmOld = ::SelectObject(hMemDC, hBitmap);
+ ::BitBlt(hMemDC, 0, 0, m_rc.Width(), m_rc.Height(), imageModel.GetDC(), m_rc.left,
m_rc.top, SRCCOPY);
::SelectObject(hMemDC, hbmOld);
::DeleteDC(hMemDC);
+
+ return hBitmap;
}
BOOL SelectionModel::IsLanded() const
@@ -178,7 +181,8 @@ BOOL SelectionModel::TakeOff()
m_rgbBack = paletteModel.GetBgColor();
// Get the contents of the selection area
- GetSelectionContents(imageModel.GetDC());
+ ClearColorImage();
+ m_hbmColor = GetSelectionContents();
// RectSel doesn't need the mask image
if (toolsModel.GetActiveTool() == TOOL_RECTSEL)
@@ -406,13 +410,6 @@ void SelectionModel::StretchSkew(int nStretchPercentX, int
nStretchPercentY, int
NotifyContentChanged();
}
-HBITMAP SelectionModel::CopyBitmap()
-{
- if (m_hbmColor == NULL)
- GetSelectionContents(imageModel.GetDC());
- return CopyDIBImage(m_hbmColor);
-}
-
int SelectionModel::PtStackSize() const
{
return m_iPtSP;
@@ -545,18 +542,6 @@ void SelectionModel::SwapWidthAndHeight()
m_rc.bottom = m_rc.top + cx;
}
-HBITMAP SelectionModel::LockBitmap()
-{
- HBITMAP hbm = m_hbmColor;
- m_hbmColor = NULL;
- return hbm;
-}
-
-void SelectionModel::UnlockBitmap(HBITMAP hbmLocked)
-{
- m_hbmColor = hbmLocked;
-}
-
void SelectionModel::StretchSelection(BOOL bShrink)
{
if (!m_bShow)
diff --git a/base/applications/mspaint/selectionmodel.h
b/base/applications/mspaint/selectionmodel.h
index 308952a6e67..e66b2bff0cc 100644
--- a/base/applications/mspaint/selectionmodel.h
+++ b/base/applications/mspaint/selectionmodel.h
@@ -40,10 +40,7 @@ public:
void HideSelection();
void DeleteSelection();
- HBITMAP CopyBitmap();
- HBITMAP LockBitmap();
- void UnlockBitmap(HBITMAP hbmLocked);
- void GetSelectionContents(HDC hDCImage);
+ HBITMAP GetSelectionContents();
void DrawFramePoly(HDC hDCImage);
void DrawBackground(HDC hDCImage);
void DrawBackgroundPoly(HDC hDCImage, COLORREF crBg);
diff --git a/base/applications/mspaint/textedit.cpp
b/base/applications/mspaint/textedit.cpp
index 5261da63a0e..c20ca6bf005 100644
--- a/base/applications/mspaint/textedit.cpp
+++ b/base/applications/mspaint/textedit.cpp
@@ -342,7 +342,7 @@ void CTextEditWindow::UpdateFont()
lf.lfWeight = (registrySettings.Bold ? FW_BOLD : FW_NORMAL);
lf.lfItalic = (BYTE)registrySettings.Italic;
lf.lfUnderline = (BYTE)registrySettings.Underline;
- lstrcpyn(lf.lfFaceName, registrySettings.strFontName, _countof(lf.lfFaceName));
+ StringCchCopyW(lf.lfFaceName, _countof(lf.lfFaceName),
registrySettings.strFontName);
HDC hdc = GetDC();
if (hdc)
diff --git a/base/applications/mspaint/winproc.cpp
b/base/applications/mspaint/winproc.cpp
index c1cbff31b8c..3beb34c290d 100644
--- a/base/applications/mspaint/winproc.cpp
+++ b/base/applications/mspaint/winproc.cpp
@@ -29,7 +29,7 @@ static HWND DoHtmlHelpW(HWND hwndCaller, LPCWSTR pszFile, UINT uCommand,
DWORD_P
{
// The function loads the system library, not local
GetSystemDirectoryW(szPath, _countof(szPath));
- wcscat(szPath, L"\\hhctrl.ocx");
+ StringCchCatW(szPath, _countof(szPath), L"\\hhctrl.ocx");
s_hHHCTRL_OCX = LoadLibraryW(szPath);
if (s_hHHCTRL_OCX)
s_pHtmlHelpW = (FN_HtmlHelpW)GetProcAddress(s_hHHCTRL_OCX,
"HtmlHelpW");
@@ -382,8 +382,8 @@ void CMainWindow::ProcessFileMenu(HMENU hPopupMenu)
assert(_tcslen((LPCTSTR)pathFile) <= MAX_RECENT_PATHNAME_DISPLAY);
// Add an accelerator (by '&') to the item number for quick access
- TCHAR szText[4 + MAX_RECENT_PATHNAME_DISPLAY + 1];
- wsprintf(szText, _T("&%u %s"), iItem + 1, (LPCTSTR)pathFile);
+ WCHAR szText[4 + MAX_RECENT_PATHNAME_DISPLAY + 1];
+ StringCchPrintfW(szText, _countof(szText), L"&%u %s", iItem + 1,
(LPCWSTR)pathFile);
INT iMenuItem = (cMenuItems - 2) + iItem;
InsertMenu(hPopupMenu, iMenuItem, MF_BYPOSITION | MF_STRING, IDM_FILE1 + iItem,
szText);
@@ -720,14 +720,13 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& bH
selectionModel.TakeOff();
{
- HBITMAP hbmLocked = selectionModel.LockBitmap();
- if (hbmLocked)
- {
- HGLOBAL hGlobal = BitmapToClipboardDIB(hbmLocked);
- if (hGlobal)
- ::SetClipboardData(CF_DIB, hGlobal);
- selectionModel.UnlockBitmap(hbmLocked);
- }
+ HBITMAP hbmCopy = selectionModel.GetSelectionContents();
+ HGLOBAL hGlobal = BitmapToClipboardDIB(hbmCopy);
+ if (hGlobal)
+ ::SetClipboardData(CF_DIB, hGlobal);
+ else
+ ShowOutOfMemory();
+ ::DeleteObject(hbmCopy);
}
CloseClipboard();
@@ -841,12 +840,18 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& bH
}
case IDM_EDITCOPYTO:
{
- WCHAR szFileName[MAX_LONG_PATH] = L"*.png";
+ WCHAR szFileName[MAX_LONG_PATH];
+ LoadStringW(g_hinstExe, IDS_DEFAULTFILENAME, szFileName,
_countof(szFileName));
if (GetSaveFileName(szFileName, _countof(szFileName)))
{
- HBITMAP hbmLocked = selectionModel.LockBitmap();
- SaveDIBToFile(hbmLocked, szFileName, FALSE);
- selectionModel.UnlockBitmap(hbmLocked);
+ HBITMAP hbmSelection = selectionModel.GetSelectionContents();
+ if (!hbmSelection)
+ {
+ ShowOutOfMemory();
+ break;
+ }
+ SaveDIBToFile(hbmSelection, szFileName, FALSE);
+ DeleteObject(hbmSelection);
}
break;
}
@@ -982,9 +987,12 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& bH
toolsModel.SetBackgroundTransparent(!toolsModel.IsBackgroundTransparent());
break;
case IDM_IMAGECROP:
- imageModel.PushImageForUndo(selectionModel.CopyBitmap());
+ {
+ HBITMAP hbmCopy = selectionModel.GetSelectionContents();
+ imageModel.PushImageForUndo(hbmCopy);
selectionModel.HideSelection();
break;
+ }
case IDM_VIEWTOOLBOX:
registrySettings.ShowToolBox = !toolBoxContainer.IsWindowVisible();
toolBoxContainer.ShowWindow(registrySettings.ShowToolBox ? SW_SHOWNOACTIVATE
: SW_HIDE);