[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 ********************************************************/
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)
{
CheckDlgButton(IDD_MIRRORROTATERB1, BST_CHECKED);

View file

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

View file

@ -142,76 +142,65 @@ GetDIBHeight(HBITMAP hBitmap)
return bm.bmHeight;
}
BOOL SaveDIBToFile(HBITMAP hBitmap, LPCTSTR FileName, HDC hDC)
BOOL SaveDIBToFile(HBITMAP hBitmap, LPCWSTR FileName, BOOL fIsMainFile)
{
CImageDx img;
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();
WIN32_FIND_DATA find;
HANDLE hFind = FindFirstFile(FileName, &find);
if (hFind == INVALID_HANDLE_VALUE)
if (FAILED(hr))
{
ShowFileLoadError(FileName);
ShowError(IDS_SAVEERROR, FileName);
return FALSE;
}
FindClose(hFind);
// update time and size
FILETIME ft;
FileTimeToLocalFileTime(&find.ftLastWriteTime, &ft);
FileTimeToSystemTime(&ft, &g_fileTime);
g_fileSize = find.nFileSizeLow;
if (!fIsMainFile)
return TRUE;
// 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);
g_isAFile = TRUE;
SetFileInfo(FileName, &find, TRUE);
g_imageSaved = TRUE;
return TRUE;
}
void ShowFileLoadError(LPCTSTR name)
void SetFileInfo(LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isAFile)
{
CString strText;
strText.Format(IDS_LOADERRORTEXT, (LPCTSTR) name);
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)
// update file time and size
if (pFound)
{
COLORREF white = RGB(255, 255, 255);
hBitmap = CreateColorDIB(registrySettings.BMPWidth,
registrySettings.BMPHeight, white);
if (hBitmap == NULL)
return FALSE;
FILETIME ft;
::FileTimeToLocalFileTime(&pFound->ftLastWriteTime, &ft);
::FileTimeToSystemTime(&ft, &g_fileTime);
HDC hScreenDC = GetDC(NULL);
g_xDpi = GetDeviceCaps(hScreenDC, LOGPIXELSX);
g_yDpi = GetDeviceCaps(hScreenDC, LOGPIXELSY);
ReleaseDC(NULL, hScreenDC);
ZeroMemory(&g_fileTime, sizeof(g_fileTime));
g_fileSize = pFound->nFileSizeLow;
}
else
{
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
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
LoadString(g_hinstExe, IDS_DEFAULTFILENAME, g_szFileName, _countof(g_szFileName));
{
::LoadStringW(g_hinstExe, IDS_DEFAULTFILENAME, g_szFileName, _countof(g_szFileName));
}
// set title
CString strTitle;
@ -219,71 +208,80 @@ HBITMAP SetBitmapAndInfo(HBITMAP hBitmap, LPCTSTR name, DWORD dwFileSize, BOOL i
mainWindow.SetWindowText(strTitle);
// update file info and recent
g_isAFile = isFile;
g_isAFile = isAFile;
if (g_isAFile)
registrySettings.SetMostRecentFile(g_szFileName);
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;
}
HBITMAP DoLoadImageFile(HWND hwnd, LPCTSTR name, BOOL fIsMainFile)
HBITMAP DoLoadImageFile(HWND hwnd, LPCWSTR name, BOOL fIsMainFile)
{
// find the file
WIN32_FIND_DATA find;
HANDLE hFind = FindFirstFile(name, &find);
if (hFind == INVALID_HANDLE_VALUE)
HANDLE hFind = ::FindFirstFileW(name, &find);
if (hFind == INVALID_HANDLE_VALUE) // does not exist
{
// does not exist
CStringW strText;
strText.Format(IDS_LOADERRORTEXT, name);
MessageBoxW(hwnd, strText, NULL, MB_ICONERROR);
ShowError(IDS_LOADERRORTEXT, name);
return NULL;
}
DWORD dwFileSize = find.nFileSizeLow; // get file size
FindClose(hFind);
::FindClose(hFind);
// is file empty?
if (dwFileSize == 0)
if (find.nFileSizeLow == 0 && find.nFileSizeHigh == 0)
{
if (fIsMainFile)
{
FILETIME ft;
FileTimeToLocalFileTime(&find.ftLastWriteTime, &ft);
FileTimeToSystemTime(&ft, &g_fileTime);
return SetBitmapAndInfo(NULL, name, dwFileSize, TRUE);
}
return InitializeImage(name, &find, TRUE);
}
// load the image
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)
g_xDpi = 96;
if (g_yDpi <= 0)
g_yDpi = 96;
HBITMAP hBitmap = img.Detach();
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);
}
SetBitmapAndInfo(hBitmap, name, &find, TRUE);
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 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);

View file

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

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Вертикален"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -264,4 +264,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -264,4 +264,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

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

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -264,4 +264,5 @@ BEGIN
IDS_VERTICAL "Pionowe"
IDS_PRINTRES "%d x %d piksel/cm"
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

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -263,4 +263,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

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

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "Düşey"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -263,4 +263,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -261,4 +261,5 @@ BEGIN
IDS_VERTICAL "Vertical"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -264,4 +264,5 @@ BEGIN
IDS_VERTICAL "垂直"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "垂直"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

@ -262,4 +262,5 @@ BEGIN
IDS_VERTICAL "垂直"
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_SAVEERROR "Failed to save an image as the following file:\n\n%s"
END

View file

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

View file

@ -220,3 +220,4 @@
#define IDS_VERTICAL 938
#define IDS_PRINTRES 939
#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)))
{
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);
imageModel.PushImageForUndo();
selectionModel.InsertFromHBITMAP(bitmap, 0, 0);
selectionModel.m_bShow = TRUE;
imageModel.NotifyImageChanged();
@ -380,9 +374,10 @@ void CMainWindow::ProcessFileMenu(HMENU hPopupMenu)
isBMP = TRUE;
}
EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERPLANE, ENABLED_IF(g_isAFile && isBMP));
EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERCENTERED, ENABLED_IF(g_isAFile && isBMP));
EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERSTRETCHED, ENABLED_IF(g_isAFile && isBMP));
UINT uWallpaperEnabled = ENABLED_IF(g_isAFile && isBMP && g_fileSize > 0);
::EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERPLANE, uWallpaperEnabled);
::EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERCENTERED, uWallpaperEnabled);
::EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERSTRETCHED, uWallpaperEnabled);
for (INT iItem = 0; iItem < MAX_RECENT_FILES; ++iItem)
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:
if (ConfirmSave())
{
SetBitmapAndInfo(NULL, NULL, 0, FALSE);
InitializeImage(NULL, NULL, FALSE);
}
break;
case IDM_FILEOPEN:
@ -850,25 +845,26 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
}
case IDM_EDITCOPYTO:
{
TCHAR szFileName[MAX_LONG_PATH] = _T("");
WCHAR szFileName[MAX_LONG_PATH] = L"*.png";
if (GetSaveFileName(szFileName, _countof(szFileName)))
{
HBITMAP hbm = selectionModel.CopyBitmap();
SaveDIBToFile(hbm, szFileName, imageModel.GetDC());
if (!SaveDIBToFile(hbm, szFileName, FALSE))
ShowError(IDS_SAVEERROR, szFileName);
::DeleteObject(hbm);
}
break;
}
case IDM_EDITPASTEFROM:
{
TCHAR szFileName[MAX_LONG_PATH] = _T("");
WCHAR szFileName[MAX_LONG_PATH] = L"";
if (GetOpenFileName(szFileName, _countof(szFileName)))
{
HBITMAP hbmNew = DoLoadImageFile(m_hWnd, szFileName, FALSE);
if (hbmNew)
{
InsertSelectionFromHBITMAP(hbmNew, m_hWnd);
}
else
ShowError(IDS_LOADERRORTEXT, szFileName);
}
break;
}