mirror of
https://github.com/reactos/reactos.git
synced 2025-07-27 07:41:51 +00:00
[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
This commit is contained in:
parent
501c2bdd63
commit
ab199cc147
5 changed files with 43 additions and 7 deletions
|
@ -43,6 +43,7 @@ enum HITTEST // hit
|
||||||
|
|
||||||
/* FUNCTIONS ********************************************************/
|
/* FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
|
void ShowOutOfMemory(void);
|
||||||
BOOL nearlyEqualPoints(INT x0, INT y0, INT x1, INT y1);
|
BOOL nearlyEqualPoints(INT x0, INT y0, INT x1, INT y1);
|
||||||
BOOL OpenMailer(HWND hWnd, LPCWSTR pszPathName);
|
BOOL OpenMailer(HWND hWnd, LPCWSTR pszPathName);
|
||||||
|
|
||||||
|
|
|
@ -228,7 +228,10 @@ HBITMAP InitializeImage(LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isFile)
|
||||||
COLORREF white = RGB(255, 255, 255);
|
COLORREF white = RGB(255, 255, 255);
|
||||||
HBITMAP hBitmap = CreateColorDIB(registrySettings.BMPWidth, registrySettings.BMPHeight, white);
|
HBITMAP hBitmap = CreateColorDIB(registrySettings.BMPWidth, registrySettings.BMPHeight, white);
|
||||||
if (hBitmap == NULL)
|
if (hBitmap == NULL)
|
||||||
|
{
|
||||||
|
ShowOutOfMemory();
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
HDC hScreenDC = ::GetDC(NULL);
|
HDC hScreenDC = ::GetDC(NULL);
|
||||||
g_xDpi = (float)::GetDeviceCaps(hScreenDC, LOGPIXELSX);
|
g_xDpi = (float)::GetDeviceCaps(hScreenDC, LOGPIXELSX);
|
||||||
|
|
|
@ -116,13 +116,31 @@ void ImageModel::ClearHistory()
|
||||||
m_redoSteps = 0;
|
m_redoSteps = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImageModel::PushImageForUndo()
|
||||||
|
{
|
||||||
|
HBITMAP hbm = CopyBitmap();
|
||||||
|
if (hbm)
|
||||||
|
{
|
||||||
|
ShowOutOfMemory();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PushImageForUndo(hbm);
|
||||||
|
}
|
||||||
|
|
||||||
void ImageModel::PushImageForUndo(HBITMAP hbm)
|
void ImageModel::PushImageForUndo(HBITMAP hbm)
|
||||||
{
|
{
|
||||||
ATLTRACE("%s: %d\n", __FUNCTION__, m_currInd);
|
ATLTRACE("%s: %d\n", __FUNCTION__, m_currInd);
|
||||||
|
|
||||||
|
if (hbm == NULL)
|
||||||
|
{
|
||||||
|
ShowOutOfMemory();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Go to the next item with an HBITMAP or current item
|
// Go to the next item with an HBITMAP or current item
|
||||||
::DeleteObject(m_hBms[(m_currInd + 1) % HISTORYSIZE]);
|
::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;
|
m_currInd = (m_currInd + 1) % HISTORYSIZE;
|
||||||
::SelectObject(m_hDrawingDC, m_hBms[m_currInd]);
|
::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
|
// Create an HBITMAP
|
||||||
HBITMAP hbmCropped = CreateDIBWithProperties(nWidth, nHeight);
|
HBITMAP hbmCropped = CreateDIBWithProperties(nWidth, nHeight);
|
||||||
if (!hbmCropped)
|
if (!hbmCropped)
|
||||||
|
{
|
||||||
|
ShowOutOfMemory();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Select the HBITMAP by memory DC
|
// Select the HBITMAP by memory DC
|
||||||
HDC hdcMem = ::CreateCompatibleDC(m_hDrawingDC);
|
HDC hdcMem = ::CreateCompatibleDC(m_hDrawingDC);
|
||||||
|
@ -251,7 +272,6 @@ void ImageModel::RotateNTimes90Degrees(int iN)
|
||||||
case 3:
|
case 3:
|
||||||
{
|
{
|
||||||
HBITMAP hbm = Rotate90DegreeBlt(m_hDrawingDC, GetWidth(), GetHeight(), iN == 1, FALSE);
|
HBITMAP hbm = Rotate90DegreeBlt(m_hDrawingDC, GetWidth(), GetHeight(), iN == 1, FALSE);
|
||||||
if (hbm)
|
|
||||||
PushImageForUndo(hbm);
|
PushImageForUndo(hbm);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -294,7 +314,6 @@ void ImageModel::PushBlackAndWhite()
|
||||||
HBITMAP hNewBitmap = ConvertToBlackAndWhite(hBitmap);
|
HBITMAP hNewBitmap = ConvertToBlackAndWhite(hBitmap);
|
||||||
UnlockBitmap(hBitmap);
|
UnlockBitmap(hBitmap);
|
||||||
|
|
||||||
if (hNewBitmap)
|
|
||||||
PushImageForUndo(hNewBitmap);
|
PushImageForUndo(hNewBitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,7 +338,7 @@ void ImageModel::SelectionClone(BOOL bUndoable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (bUndoable)
|
if (bUndoable)
|
||||||
PushImageForUndo(CopyBitmap());
|
PushImageForUndo();
|
||||||
|
|
||||||
selectionModel.DrawSelection(m_hDrawingDC, paletteModel.GetBgColor(),
|
selectionModel.DrawSelection(m_hDrawingDC, paletteModel.GetBgColor(),
|
||||||
toolsModel.IsBackgroundTransparent());
|
toolsModel.IsBackgroundTransparent());
|
||||||
|
|
|
@ -19,7 +19,8 @@ public:
|
||||||
HDC GetDC();
|
HDC GetDC();
|
||||||
BOOL CanUndo() const { return m_undoSteps > 0; }
|
BOOL CanUndo() const { return m_undoSteps > 0; }
|
||||||
BOOL CanRedo() const { return m_redoSteps > 0; }
|
BOOL CanRedo() const { return m_redoSteps > 0; }
|
||||||
void PushImageForUndo(HBITMAP hbm = NULL);
|
void PushImageForUndo();
|
||||||
|
void PushImageForUndo(HBITMAP hbm);
|
||||||
void ResetToPrevious(void);
|
void ResetToPrevious(void);
|
||||||
void Undo(BOOL bClearRedo = FALSE);
|
void Undo(BOOL bClearRedo = FALSE);
|
||||||
void Redo(void);
|
void Redo(void);
|
||||||
|
|
|
@ -22,6 +22,18 @@ CMainWindow mainWindow;
|
||||||
|
|
||||||
/* FUNCTIONS ********************************************************/
|
/* 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
|
// get file name extension from filter string
|
||||||
static BOOL
|
static BOOL
|
||||||
FileExtFromFilter(LPTSTR pExt, OPENFILENAME *pOFN)
|
FileExtFromFilter(LPTSTR pExt, OPENFILENAME *pOFN)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue