https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ab199cc147afab56d975d…
commit ab199cc147afab56d975d100ebbc5816e5993aed
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Wed Oct 25 02:35:49 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Wed Oct 25 02:35:49 2023 +0900
[MSPAINT] Show out-of-memory message (#5817)
- Improve ImageModel::PushImageForUndo.
- Use FormatMessage in newly added
ShowOutOfMemory function.
- Call ShowOutOfMemory() when out of memory.
CORE-19227, CORE-19094
---
base/applications/mspaint/common.h | 1 +
base/applications/mspaint/dib.cpp | 3 +++
base/applications/mspaint/history.cpp | 31 +++++++++++++++++++++++++------
base/applications/mspaint/history.h | 3 ++-
base/applications/mspaint/main.cpp | 12 ++++++++++++
5 files changed, 43 insertions(+), 7 deletions(-)
diff --git a/base/applications/mspaint/common.h b/base/applications/mspaint/common.h
index 3dda6703441..125a9cb53a6 100644
--- a/base/applications/mspaint/common.h
+++ b/base/applications/mspaint/common.h
@@ -43,6 +43,7 @@ enum HITTEST // hit
/* FUNCTIONS ********************************************************/
+void ShowOutOfMemory(void);
BOOL nearlyEqualPoints(INT x0, INT y0, INT x1, INT y1);
BOOL OpenMailer(HWND hWnd, LPCWSTR pszPathName);
diff --git a/base/applications/mspaint/dib.cpp b/base/applications/mspaint/dib.cpp
index eede3325c55..2c13cc2f785 100644
--- a/base/applications/mspaint/dib.cpp
+++ b/base/applications/mspaint/dib.cpp
@@ -228,7 +228,10 @@ HBITMAP InitializeImage(LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL
isFile)
COLORREF white = RGB(255, 255, 255);
HBITMAP hBitmap = CreateColorDIB(registrySettings.BMPWidth,
registrySettings.BMPHeight, white);
if (hBitmap == NULL)
+ {
+ ShowOutOfMemory();
return NULL;
+ }
HDC hScreenDC = ::GetDC(NULL);
g_xDpi = (float)::GetDeviceCaps(hScreenDC, LOGPIXELSX);
diff --git a/base/applications/mspaint/history.cpp
b/base/applications/mspaint/history.cpp
index 2d28cb5def2..003d0ab5877 100644
--- a/base/applications/mspaint/history.cpp
+++ b/base/applications/mspaint/history.cpp
@@ -116,13 +116,31 @@ void ImageModel::ClearHistory()
m_redoSteps = 0;
}
+void ImageModel::PushImageForUndo()
+{
+ HBITMAP hbm = CopyBitmap();
+ if (hbm)
+ {
+ ShowOutOfMemory();
+ return;
+ }
+
+ PushImageForUndo(hbm);
+}
+
void ImageModel::PushImageForUndo(HBITMAP hbm)
{
ATLTRACE("%s: %d\n", __FUNCTION__, m_currInd);
+ if (hbm == NULL)
+ {
+ ShowOutOfMemory();
+ return;
+ }
+
// Go to the next item with an HBITMAP or current item
::DeleteObject(m_hBms[(m_currInd + 1) % HISTORYSIZE]);
- m_hBms[(m_currInd + 1) % HISTORYSIZE] = (hbm ? hbm :
CopyDIBImage(m_hBms[m_currInd]));
+ m_hBms[(m_currInd + 1) % HISTORYSIZE] = hbm;
m_currInd = (m_currInd + 1) % HISTORYSIZE;
::SelectObject(m_hDrawingDC, m_hBms[m_currInd]);
@@ -145,7 +163,10 @@ void ImageModel::Crop(int nWidth, int nHeight, int nOffsetX, int
nOffsetY)
// Create an HBITMAP
HBITMAP hbmCropped = CreateDIBWithProperties(nWidth, nHeight);
if (!hbmCropped)
+ {
+ ShowOutOfMemory();
return;
+ }
// Select the HBITMAP by memory DC
HDC hdcMem = ::CreateCompatibleDC(m_hDrawingDC);
@@ -251,8 +272,7 @@ void ImageModel::RotateNTimes90Degrees(int iN)
case 3:
{
HBITMAP hbm = Rotate90DegreeBlt(m_hDrawingDC, GetWidth(), GetHeight(), iN ==
1, FALSE);
- if (hbm)
- PushImageForUndo(hbm);
+ PushImageForUndo(hbm);
break;
}
case 2:
@@ -294,8 +314,7 @@ void ImageModel::PushBlackAndWhite()
HBITMAP hNewBitmap = ConvertToBlackAndWhite(hBitmap);
UnlockBitmap(hBitmap);
- if (hNewBitmap)
- PushImageForUndo(hNewBitmap);
+ PushImageForUndo(hNewBitmap);
}
HBITMAP ImageModel::LockBitmap()
@@ -319,7 +338,7 @@ void ImageModel::SelectionClone(BOOL bUndoable)
return;
if (bUndoable)
- PushImageForUndo(CopyBitmap());
+ PushImageForUndo();
selectionModel.DrawSelection(m_hDrawingDC, paletteModel.GetBgColor(),
toolsModel.IsBackgroundTransparent());
diff --git a/base/applications/mspaint/history.h b/base/applications/mspaint/history.h
index 24f1e09cd13..093dd1c34dd 100644
--- a/base/applications/mspaint/history.h
+++ b/base/applications/mspaint/history.h
@@ -19,7 +19,8 @@ public:
HDC GetDC();
BOOL CanUndo() const { return m_undoSteps > 0; }
BOOL CanRedo() const { return m_redoSteps > 0; }
- void PushImageForUndo(HBITMAP hbm = NULL);
+ void PushImageForUndo();
+ void PushImageForUndo(HBITMAP hbm);
void ResetToPrevious(void);
void Undo(BOOL bClearRedo = FALSE);
void Redo(void);
diff --git a/base/applications/mspaint/main.cpp b/base/applications/mspaint/main.cpp
index ac1a037ddae..63db53f02de 100644
--- a/base/applications/mspaint/main.cpp
+++ b/base/applications/mspaint/main.cpp
@@ -22,6 +22,18 @@ CMainWindow mainWindow;
/* FUNCTIONS ********************************************************/
+void ShowOutOfMemory(void)
+{
+ WCHAR szText[256];
+ ::FormatMessageW(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ ERROR_OUTOFMEMORY,
+ 0,
+ szText, _countof(szText),
+ NULL);
+ mainWindow.MessageBox(szText, NULL, MB_ICONERROR);
+}
+
// get file name extension from filter string
static BOOL
FileExtFromFilter(LPTSTR pExt, OPENFILENAME *pOFN)