[MSPAINT] Some bug fixes on loading/saving files (#5385)

- Display a correct error message on failing to save a file.
- Don't confuse the main file info and the non-main file info.
- Rename ShowFileLoadError as ShowError, and strengthen and move it to dialogs.cpp.
- Add SetFileInfo and InitializeImage helper functions.
- Add IDS_SAVEERROR resource string.
- Modify SaveDIBToFile, SetBitmapAndInfo, and DoLoadImageFile functions.
CORE-18867
This commit is contained in:
Katayama Hirofumi MZ 2023-07-05 12:06:22 +09:00 committed by GitHub
parent 17e9dcc922
commit 3e23cdf9ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 150 additions and 109 deletions

View file

@ -22,6 +22,22 @@ CFontsDialog fontsDialog;
/* FUNCTIONS ********************************************************/ /* FUNCTIONS ********************************************************/
void ShowError(INT stringID, ...)
{
va_list va;
va_start(va, stringID);
CStringW strFormat, strText;
strFormat.LoadString(stringID);
strText.FormatV(strFormat, va);
CStringW strProgramName;
strProgramName.LoadString(IDS_PROGRAMNAME);
mainWindow.MessageBox(strText, strProgramName, MB_ICONERROR);
va_end(va);
}
LRESULT CMirrorRotateDialog::OnInitDialog(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT CMirrorRotateDialog::OnInitDialog(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
CheckDlgButton(IDD_MIRRORROTATERB1, BST_CHECKED); CheckDlgButton(IDD_MIRRORROTATERB1, BST_CHECKED);

View file

@ -7,6 +7,8 @@
#pragma once #pragma once
void ShowError(INT stringID, ...);
class CMirrorRotateDialog : public CDialogImpl<CMirrorRotateDialog> class CMirrorRotateDialog : public CDialogImpl<CMirrorRotateDialog>
{ {
public: public:

View file

@ -142,76 +142,65 @@ GetDIBHeight(HBITMAP hBitmap)
return bm.bmHeight; return bm.bmHeight;
} }
BOOL SaveDIBToFile(HBITMAP hBitmap, LPCTSTR FileName, HDC hDC) BOOL SaveDIBToFile(HBITMAP hBitmap, LPCWSTR FileName, BOOL fIsMainFile)
{ {
CImageDx img; CImageDx img;
img.Attach(hBitmap); img.Attach(hBitmap);
img.SaveDx(FileName, GUID_NULL, g_xDpi, g_yDpi); // TODO: error handling HRESULT hr = img.SaveDx(FileName, GUID_NULL, g_xDpi, g_yDpi);
img.Detach(); img.Detach();
WIN32_FIND_DATA find; if (FAILED(hr))
HANDLE hFind = FindFirstFile(FileName, &find);
if (hFind == INVALID_HANDLE_VALUE)
{ {
ShowFileLoadError(FileName); ShowError(IDS_SAVEERROR, FileName);
return FALSE; return FALSE;
} }
FindClose(hFind);
// update time and size if (!fIsMainFile)
FILETIME ft; return TRUE;
FileTimeToLocalFileTime(&find.ftLastWriteTime, &ft);
FileTimeToSystemTime(&ft, &g_fileTime);
g_fileSize = find.nFileSizeLow;
// TODO: update hRes and vRes WIN32_FIND_DATAW find;
HANDLE hFind = ::FindFirstFileW(FileName, &find);
if (hFind == INVALID_HANDLE_VALUE)
{
ShowError(IDS_SAVEERROR, FileName);
return FALSE;
}
::FindClose(hFind);
registrySettings.SetMostRecentFile(FileName); SetFileInfo(FileName, &find, TRUE);
g_isAFile = TRUE;
g_imageSaved = TRUE; g_imageSaved = TRUE;
return TRUE; return TRUE;
} }
void ShowFileLoadError(LPCTSTR name) void SetFileInfo(LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isAFile)
{ {
CString strText; // update file time and size
strText.Format(IDS_LOADERRORTEXT, (LPCTSTR) name); if (pFound)
CString strProgramName;
strProgramName.LoadString(IDS_PROGRAMNAME);
mainWindow.MessageBox(strText, strProgramName, MB_OK | MB_ICONEXCLAMATION);
}
HBITMAP SetBitmapAndInfo(HBITMAP hBitmap, LPCTSTR name, DWORD dwFileSize, BOOL isFile)
{
if (hBitmap == NULL)
{ {
COLORREF white = RGB(255, 255, 255); FILETIME ft;
hBitmap = CreateColorDIB(registrySettings.BMPWidth, ::FileTimeToLocalFileTime(&pFound->ftLastWriteTime, &ft);
registrySettings.BMPHeight, white); ::FileTimeToSystemTime(&ft, &g_fileTime);
if (hBitmap == NULL)
return FALSE;
HDC hScreenDC = GetDC(NULL); g_fileSize = pFound->nFileSizeLow;
g_xDpi = GetDeviceCaps(hScreenDC, LOGPIXELSX); }
g_yDpi = GetDeviceCaps(hScreenDC, LOGPIXELSY); else
ReleaseDC(NULL, hScreenDC); {
ZeroMemory(&g_fileTime, sizeof(g_fileTime));
ZeroMemory(&g_fileTime, sizeof(g_fileTime)); g_fileSize = 0;
} }
// update image
imageModel.PushImageForUndo(hBitmap);
imageModel.ClearHistory();
// update g_fileSize
g_fileSize = dwFileSize;
// update g_szFileName // update g_szFileName
if (name && name[0]) if (name && name[0])
GetFullPathName(name, _countof(g_szFileName), g_szFileName, NULL); {
CStringW strName = name;
::GetFullPathNameW(strName, _countof(g_szFileName), g_szFileName, NULL);
// The following code won't work correctly when (name == g_szFileName):
// ::GetFullPathNameW(name, _countof(g_szFileName), g_szFileName, NULL);
}
else else
LoadString(g_hinstExe, IDS_DEFAULTFILENAME, g_szFileName, _countof(g_szFileName)); {
::LoadStringW(g_hinstExe, IDS_DEFAULTFILENAME, g_szFileName, _countof(g_szFileName));
}
// set title // set title
CString strTitle; CString strTitle;
@ -219,71 +208,80 @@ HBITMAP SetBitmapAndInfo(HBITMAP hBitmap, LPCTSTR name, DWORD dwFileSize, BOOL i
mainWindow.SetWindowText(strTitle); mainWindow.SetWindowText(strTitle);
// update file info and recent // update file info and recent
g_isAFile = isFile; g_isAFile = isAFile;
if (g_isAFile) if (g_isAFile)
registrySettings.SetMostRecentFile(g_szFileName); registrySettings.SetMostRecentFile(g_szFileName);
g_imageSaved = TRUE; g_imageSaved = TRUE;
}
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)
return NULL;
HDC hScreenDC = ::GetDC(NULL);
g_xDpi = ::GetDeviceCaps(hScreenDC, LOGPIXELSX);
g_yDpi = ::GetDeviceCaps(hScreenDC, LOGPIXELSY);
::ReleaseDC(NULL, hScreenDC);
return SetBitmapAndInfo(hBitmap, name, pFound, isFile);
}
HBITMAP SetBitmapAndInfo(HBITMAP hBitmap, LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isFile)
{
// update image
imageModel.PushImageForUndo(hBitmap);
imageModel.ClearHistory();
SetFileInfo(name, pFound, isFile);
g_imageSaved = TRUE;
return hBitmap; return hBitmap;
} }
HBITMAP DoLoadImageFile(HWND hwnd, LPCTSTR name, BOOL fIsMainFile) HBITMAP DoLoadImageFile(HWND hwnd, LPCWSTR name, BOOL fIsMainFile)
{ {
// find the file // find the file
WIN32_FIND_DATA find; WIN32_FIND_DATA find;
HANDLE hFind = FindFirstFile(name, &find); HANDLE hFind = ::FindFirstFileW(name, &find);
if (hFind == INVALID_HANDLE_VALUE) if (hFind == INVALID_HANDLE_VALUE) // does not exist
{ {
// does not exist ShowError(IDS_LOADERRORTEXT, name);
CStringW strText;
strText.Format(IDS_LOADERRORTEXT, name);
MessageBoxW(hwnd, strText, NULL, MB_ICONERROR);
return NULL; return NULL;
} }
DWORD dwFileSize = find.nFileSizeLow; // get file size ::FindClose(hFind);
FindClose(hFind);
// is file empty? // is file empty?
if (dwFileSize == 0) if (find.nFileSizeLow == 0 && find.nFileSizeHigh == 0)
{ {
if (fIsMainFile) if (fIsMainFile)
{ return InitializeImage(name, &find, TRUE);
FILETIME ft;
FileTimeToLocalFileTime(&find.ftLastWriteTime, &ft);
FileTimeToSystemTime(&ft, &g_fileTime);
return SetBitmapAndInfo(NULL, name, dwFileSize, TRUE);
}
} }
// load the image // load the image
CImageDx img; CImageDx img;
img.LoadDx(name, &g_xDpi, &g_yDpi); float xDpi, yDpi;
HRESULT hr = img.LoadDx(name, &xDpi, &yDpi);
if (FAILED(hr))
{
ShowError(IDS_LOADERRORTEXT, name);
return NULL;
}
HBITMAP hBitmap = img.Detach();
if (!fIsMainFile)
return hBitmap;
g_xDpi = xDpi;
g_yDpi = yDpi;
if (g_xDpi <= 0) if (g_xDpi <= 0)
g_xDpi = 96; g_xDpi = 96;
if (g_yDpi <= 0) if (g_yDpi <= 0)
g_yDpi = 96; g_yDpi = 96;
HBITMAP hBitmap = img.Detach(); SetBitmapAndInfo(hBitmap, name, &find, TRUE);
if (hBitmap == NULL)
{
// cannot open
CStringW strText;
strText.Format(IDS_LOADERRORTEXT, name);
MessageBoxW(hwnd, strText, NULL, MB_ICONERROR);
return NULL;
}
if (fIsMainFile)
{
FILETIME ft;
FileTimeToLocalFileTime(&find.ftLastWriteTime, &ft);
FileTimeToSystemTime(&ft, &g_fileTime);
SetBitmapAndInfo(hBitmap, name, dwFileSize, TRUE);
}
return hBitmap; return hBitmap;
} }

View file

@ -20,16 +20,16 @@ static inline HBITMAP CopyDIBImage(HBITMAP hbm, INT cx = 0, INT cy = 0)
} }
int GetDIBWidth(HBITMAP hbm); int GetDIBWidth(HBITMAP hbm);
int GetDIBHeight(HBITMAP hbm); int GetDIBHeight(HBITMAP hbm);
BOOL SaveDIBToFile(HBITMAP hBitmap, LPCTSTR FileName, HDC hDC); BOOL SaveDIBToFile(HBITMAP hBitmap, LPCWSTR FileName, BOOL fIsMainFile);
HBITMAP DoLoadImageFile(HWND hwnd, LPCTSTR name, BOOL fIsMainFile); HBITMAP DoLoadImageFile(HWND hwnd, LPCWSTR name, BOOL fIsMainFile);
void ShowFileLoadError(LPCTSTR name); void SetFileInfo(LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isAFile);
HBITMAP SetBitmapAndInfo(HBITMAP hBitmap, LPCTSTR name, DWORD dwFileSize, BOOL isFile); HBITMAP InitializeImage(LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isFile);
HBITMAP SetBitmapAndInfo(HBITMAP hBitmap, LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isFile);
HBITMAP Rotate90DegreeBlt(HDC hDC1, INT cx, INT cy, BOOL bRight, BOOL bMono); HBITMAP Rotate90DegreeBlt(HDC hDC1, INT cx, INT cy, BOOL bRight, BOOL bMono);

View file

@ -159,7 +159,7 @@ void ImageModel::Crop(int nWidth, int nHeight, int nOffsetX, int nOffsetY)
void ImageModel::SaveImage(LPCTSTR lpFileName) void ImageModel::SaveImage(LPCTSTR lpFileName)
{ {
SaveDIBToFile(m_hBms[m_currInd], lpFileName, m_hDrawingDC); SaveDIBToFile(m_hBms[m_currInd], lpFileName, TRUE);
} }
BOOL ImageModel::IsImageSaved() const BOOL ImageModel::IsImageSaved() const

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Вертикален" IDS_VERTICAL "Вертикален"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d dots per inch" IDS_PRINTRES "%d x %d dots per inch"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d dots per inch" IDS_PRINTRES "%d x %d dots per inch"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -264,4 +264,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -264,4 +264,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -263,4 +263,5 @@ BEGIN
IDS_VERTICAL "縦書き" IDS_VERTICAL "縦書き"
IDS_PRINTRES "%d x %d ピクセル/cm" IDS_PRINTRES "%d x %d ピクセル/cm"
IDS_CANTPASTE "クリップボードからの貼り付けに失敗しました。データ形式が間違っているか、未対応です。" IDS_CANTPASTE "クリップボードからの貼り付けに失敗しました。データ形式が間違っているか、未対応です。"
IDS_SAVEERROR "次のファイルとして画像を保存するのに失敗しました:\n\n%s"
END END

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -264,4 +264,5 @@ BEGIN
IDS_VERTICAL "Pionowe" IDS_VERTICAL "Pionowe"
IDS_PRINTRES "%d x %d piksel/cm" IDS_PRINTRES "%d x %d piksel/cm"
IDS_CANTPASTE "Nie można wkleić ze schowka. Format danych jest nieprawidłowy lub nieobsługiwany." IDS_CANTPASTE "Nie można wkleić ze schowka. Format danych jest nieprawidłowy lub nieobsługiwany."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -263,4 +263,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixeli/cm" IDS_PRINTRES "%d x %d pixeli/cm"
IDS_CANTPASTE "Nu a putut fi lipit din clipboard. Formatul de date este fie incorect, fie nesuportat." IDS_CANTPASTE "Nu a putut fi lipit din clipboard. Formatul de date este fie incorect, fie nesuportat."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -265,4 +265,5 @@ BEGIN
IDS_VERTICAL "Вертикальный" IDS_VERTICAL "Вертикальный"
IDS_PRINTRES "%d x %d точек/см" IDS_PRINTRES "%d x %d точек/см"
IDS_CANTPASTE "Не удалось вставить из буфера обмена. Формат данных либо некорректный, либо не поддерживается." IDS_CANTPASTE "Не удалось вставить из буфера обмена. Формат данных либо некорректный, либо не поддерживается."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Düşey" IDS_VERTICAL "Düşey"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -263,4 +263,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical" IDS_VERTICAL "Vertical"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -264,4 +264,5 @@ BEGIN
IDS_VERTICAL "垂直" IDS_VERTICAL "垂直"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "垂直" IDS_VERTICAL "垂直"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "垂直" IDS_VERTICAL "垂直"
IDS_PRINTRES "%d x %d pixel/cm" IDS_PRINTRES "%d x %d pixel/cm"
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported." IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
IDS_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END END

View file

@ -209,10 +209,8 @@ _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, INT nC
} }
// Initialize imageModel // Initialize imageModel
imageModel.Crop(registrySettings.BMPWidth, registrySettings.BMPHeight); if (__argc < 2 || !DoLoadImageFile(mainWindow, __targv[1], TRUE))
if (__argc >= 2) InitializeImage(NULL, NULL, FALSE);
DoLoadImageFile(mainWindow, __targv[1], TRUE);
imageModel.ClearHistory();
// Make the window visible on the screen // Make the window visible on the screen
mainWindow.ShowWindow(registrySettings.WindowPlacement.showCmd); mainWindow.ShowWindow(registrySettings.WindowPlacement.showCmd);

View file

@ -220,3 +220,4 @@
#define IDS_VERTICAL 938 #define IDS_VERTICAL 938
#define IDS_PRINTRES 939 #define IDS_PRINTRES 939
#define IDS_CANTPASTE 940 #define IDS_CANTPASTE 940
#define IDS_SAVEERROR 941

View file

@ -148,11 +148,6 @@ void CMainWindow::saveImage(BOOL overwrite)
else if (GetSaveFileName(g_szFileName, _countof(g_szFileName))) else if (GetSaveFileName(g_szFileName, _countof(g_szFileName)))
{ {
imageModel.SaveImage(g_szFileName); imageModel.SaveImage(g_szFileName);
CString strTitle;
strTitle.Format(IDS_WINDOWTITLE, PathFindFileName(g_szFileName));
SetWindowText(strTitle);
g_isAFile = TRUE;
} }
} }
@ -201,7 +196,6 @@ void CMainWindow::InsertSelectionFromHBITMAP(HBITMAP bitmap, HWND window)
toolsModel.SetActiveTool(TOOL_RECTSEL); toolsModel.SetActiveTool(TOOL_RECTSEL);
imageModel.PushImageForUndo();
selectionModel.InsertFromHBITMAP(bitmap, 0, 0); selectionModel.InsertFromHBITMAP(bitmap, 0, 0);
selectionModel.m_bShow = TRUE; selectionModel.m_bShow = TRUE;
imageModel.NotifyImageChanged(); imageModel.NotifyImageChanged();
@ -380,9 +374,10 @@ void CMainWindow::ProcessFileMenu(HMENU hPopupMenu)
isBMP = TRUE; isBMP = TRUE;
} }
EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERPLANE, ENABLED_IF(g_isAFile && isBMP)); UINT uWallpaperEnabled = ENABLED_IF(g_isAFile && isBMP && g_fileSize > 0);
EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERCENTERED, ENABLED_IF(g_isAFile && isBMP)); ::EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERPLANE, uWallpaperEnabled);
EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERSTRETCHED, ENABLED_IF(g_isAFile && isBMP)); ::EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERCENTERED, uWallpaperEnabled);
::EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERSTRETCHED, uWallpaperEnabled);
for (INT iItem = 0; iItem < MAX_RECENT_FILES; ++iItem) for (INT iItem = 0; iItem < MAX_RECENT_FILES; ++iItem)
RemoveMenu(hPopupMenu, IDM_FILE1 + iItem, MF_BYCOMMAND); RemoveMenu(hPopupMenu, IDM_FILE1 + iItem, MF_BYCOMMAND);
@ -612,7 +607,7 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
case IDM_FILENEW: case IDM_FILENEW:
if (ConfirmSave()) if (ConfirmSave())
{ {
SetBitmapAndInfo(NULL, NULL, 0, FALSE); InitializeImage(NULL, NULL, FALSE);
} }
break; break;
case IDM_FILEOPEN: case IDM_FILEOPEN:
@ -850,25 +845,26 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
} }
case IDM_EDITCOPYTO: case IDM_EDITCOPYTO:
{ {
TCHAR szFileName[MAX_LONG_PATH] = _T(""); WCHAR szFileName[MAX_LONG_PATH] = L"*.png";
if (GetSaveFileName(szFileName, _countof(szFileName))) if (GetSaveFileName(szFileName, _countof(szFileName)))
{ {
HBITMAP hbm = selectionModel.CopyBitmap(); HBITMAP hbm = selectionModel.CopyBitmap();
SaveDIBToFile(hbm, szFileName, imageModel.GetDC()); if (!SaveDIBToFile(hbm, szFileName, FALSE))
ShowError(IDS_SAVEERROR, szFileName);
::DeleteObject(hbm); ::DeleteObject(hbm);
} }
break; break;
} }
case IDM_EDITPASTEFROM: case IDM_EDITPASTEFROM:
{ {
TCHAR szFileName[MAX_LONG_PATH] = _T(""); WCHAR szFileName[MAX_LONG_PATH] = L"";
if (GetOpenFileName(szFileName, _countof(szFileName))) if (GetOpenFileName(szFileName, _countof(szFileName)))
{ {
HBITMAP hbmNew = DoLoadImageFile(m_hWnd, szFileName, FALSE); HBITMAP hbmNew = DoLoadImageFile(m_hWnd, szFileName, FALSE);
if (hbmNew) if (hbmNew)
{
InsertSelectionFromHBITMAP(hbmNew, m_hWnd); InsertSelectionFromHBITMAP(hbmNew, m_hWnd);
} else
ShowError(IDS_LOADERRORTEXT, szFileName);
} }
break; break;
} }