mirror of
https://github.com/reactos/reactos.git
synced 2025-02-20 15:35:04 +00:00
[MSPAINT] Send mail with image (retry) (#5404)
- Add OpenMailer function. - Add IDS_CANTSENDMAIL. - Send a mail by using mapi32!MAPISendMail/W. - Extend SaveDIBToFile function by adding a parameter. CORE-19094
This commit is contained in:
parent
3463a3fba3
commit
ba53f72a87
36 changed files with 159 additions and 3 deletions
|
@ -47,3 +47,4 @@ BOOL zoomTo(int newZoom, int mouseX, int mouseY);
|
|||
BOOL nearlyEqualPoints(INT x0, INT y0, INT x1, INT y1);
|
||||
void updateStartAndLast(LONG x, LONG y);
|
||||
void updateLast(LONG x, LONG y);
|
||||
BOOL OpenMailer(HWND hWnd, LPCWSTR pszPathName);
|
||||
|
|
|
@ -142,11 +142,11 @@ GetDIBHeight(HBITMAP hBitmap)
|
|||
return bm.bmHeight;
|
||||
}
|
||||
|
||||
BOOL SaveDIBToFile(HBITMAP hBitmap, LPCWSTR FileName, BOOL fIsMainFile)
|
||||
BOOL SaveDIBToFile(HBITMAP hBitmap, LPCWSTR FileName, BOOL fIsMainFile, REFGUID guidFileType)
|
||||
{
|
||||
CImageDx img;
|
||||
img.Attach(hBitmap);
|
||||
HRESULT hr = img.SaveDx(FileName, GUID_NULL, g_xDpi, g_yDpi);
|
||||
HRESULT hr = img.SaveDx(FileName, guidFileType, g_xDpi, g_yDpi);
|
||||
img.Detach();
|
||||
|
||||
if (FAILED(hr))
|
||||
|
|
|
@ -22,7 +22,7 @@ static inline HBITMAP CopyDIBImage(HBITMAP hbm, INT cx = 0, INT cy = 0)
|
|||
int GetDIBWidth(HBITMAP hbm);
|
||||
int GetDIBHeight(HBITMAP hbm);
|
||||
|
||||
BOOL SaveDIBToFile(HBITMAP hBitmap, LPCWSTR FileName, BOOL fIsMainFile);
|
||||
BOOL SaveDIBToFile(HBITMAP hBitmap, LPCWSTR FileName, BOOL fIsMainFile, REFGUID guidFileType = GUID_NULL);
|
||||
|
||||
HBITMAP DoLoadImageFile(HWND hwnd, LPCWSTR name, BOOL fIsMainFile);
|
||||
|
||||
|
|
|
@ -263,4 +263,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -263,4 +263,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -262,4 +262,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -262,4 +262,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -263,4 +263,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -265,4 +265,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -262,4 +262,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -263,4 +263,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -263,4 +263,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -265,4 +265,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -263,4 +263,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -262,4 +262,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -263,4 +263,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -264,4 +264,5 @@ BEGIN
|
|||
IDS_PRINTRES "%d x %d ピクセル/cm"
|
||||
IDS_CANTPASTE "クリップボードからの貼り付けに失敗しました。データ形式が間違っているか、未対応です。"
|
||||
IDS_SAVEERROR "次のファイルとして画像を保存するのに失敗しました:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -262,4 +262,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -262,4 +262,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -265,4 +265,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -263,4 +263,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -263,4 +263,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -264,4 +264,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -266,4 +266,5 @@ BEGIN
|
|||
IDS_PRINTRES "%d x %d точек/см"
|
||||
IDS_CANTPASTE "Не удалось вставить из буфера обмена. Формат данных либо некорректный, либо не поддерживается."
|
||||
IDS_SAVEERROR "Не удалось сохранить точечный рисунок в файл:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -262,4 +262,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -262,4 +262,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -263,4 +263,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -263,4 +263,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -264,4 +264,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -262,4 +262,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -265,4 +265,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -263,4 +263,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -263,4 +263,5 @@ BEGIN
|
|||
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 the bitmap to file:\n\n%s"
|
||||
IDS_CANTSENDMAIL "Failed to send a mail."
|
||||
END
|
||||
|
|
|
@ -7,10 +7,14 @@
|
|||
|
||||
#include "precomp.h"
|
||||
|
||||
#include <mapi.h>
|
||||
#include <mapicode.h>
|
||||
|
||||
POINT g_ptStart, g_ptEnd;
|
||||
BOOL g_askBeforeEnlarging = FALSE; // TODO: initialize from registry
|
||||
HINSTANCE g_hinstExe = NULL;
|
||||
TCHAR g_szFileName[MAX_LONG_PATH] = { 0 };
|
||||
WCHAR g_szMailTempFile[MAX_LONG_PATH] = { 0 };
|
||||
BOOL g_isAFile = FALSE;
|
||||
BOOL g_imageSaved = FALSE;
|
||||
BOOL g_showGrid = FALSE;
|
||||
|
@ -69,6 +73,116 @@ OFNHookProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||
return 0;
|
||||
}
|
||||
|
||||
typedef ULONG (WINAPI *FN_MAPISendMail)(LHANDLE, ULONG_PTR, lpMapiMessage, FLAGS, ULONG);
|
||||
typedef ULONG (WINAPI *FN_MAPISendMailW)(LHANDLE, ULONG_PTR, lpMapiMessageW, FLAGS, ULONG);
|
||||
|
||||
BOOL OpenMailer(HWND hWnd, LPCWSTR pszPathName)
|
||||
{
|
||||
// Delete the temporary file if any
|
||||
if (g_szMailTempFile[0])
|
||||
{
|
||||
::DeleteFileW(g_szMailTempFile);
|
||||
g_szMailTempFile[0] = UNICODE_NULL;
|
||||
}
|
||||
|
||||
CStringW strFileTitle;
|
||||
if (PathFileExistsW(pszPathName) && imageModel.IsImageSaved())
|
||||
{
|
||||
strFileTitle = PathFindFileNameW(pszPathName);
|
||||
}
|
||||
else // Not existing or not saved
|
||||
{
|
||||
// Get the name of a temporary file
|
||||
WCHAR szTempDir[MAX_PATH];
|
||||
::GetTempPathW(_countof(szTempDir), szTempDir);
|
||||
if (!::GetTempFileNameW(szTempDir, L"afx", 0, g_szMailTempFile))
|
||||
return FALSE; // Failure
|
||||
|
||||
if (PathFileExistsW(g_szFileName))
|
||||
{
|
||||
// Set file title
|
||||
strFileTitle = PathFindFileNameW(g_szFileName);
|
||||
|
||||
// Copy to the temporary file
|
||||
if (!::CopyFileW(g_szFileName, g_szMailTempFile, FALSE))
|
||||
{
|
||||
g_szMailTempFile[0] = UNICODE_NULL;
|
||||
return FALSE; // Failure
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set file title
|
||||
strFileTitle.LoadString(IDS_DEFAULTFILENAME);
|
||||
strFileTitle += L".png";
|
||||
|
||||
// Save it to the temporary file
|
||||
HBITMAP hbm = imageModel.CopyBitmap();
|
||||
BOOL ret = SaveDIBToFile(hbm, g_szMailTempFile, FALSE, Gdiplus::ImageFormatPNG);
|
||||
::DeleteObject(hbm);
|
||||
if (!ret)
|
||||
{
|
||||
g_szMailTempFile[0] = UNICODE_NULL;
|
||||
return FALSE; // Failure
|
||||
}
|
||||
}
|
||||
|
||||
// Use the temporary file
|
||||
pszPathName = g_szMailTempFile;
|
||||
}
|
||||
|
||||
// Load "mapi32.dll"
|
||||
HINSTANCE hMAPI = LoadLibraryW(L"mapi32.dll");
|
||||
if (!hMAPI)
|
||||
return FALSE; // Failure
|
||||
|
||||
// Attachment
|
||||
MapiFileDescW attachmentW = { 0 };
|
||||
attachmentW.nPosition = (ULONG)-1;
|
||||
attachmentW.lpszPathName = (LPWSTR)pszPathName;
|
||||
attachmentW.lpszFileName = (LPWSTR)(LPCWSTR)strFileTitle;
|
||||
|
||||
// Message with attachment
|
||||
MapiMessageW messageW = { 0 };
|
||||
messageW.lpszSubject = NULL;
|
||||
messageW.nFileCount = 1;
|
||||
messageW.lpFiles = &attachmentW;
|
||||
|
||||
// First, try to open the mailer by the function of Unicode version
|
||||
FN_MAPISendMailW pMAPISendMailW = (FN_MAPISendMailW)::GetProcAddress(hMAPI, "MAPISendMailW");
|
||||
if (pMAPISendMailW)
|
||||
{
|
||||
pMAPISendMailW(0, (ULONG_PTR)hWnd, &messageW, MAPI_DIALOG | MAPI_LOGON_UI, 0);
|
||||
::FreeLibrary(hMAPI);
|
||||
return TRUE; // MAPISendMailW will show an error message on failure
|
||||
}
|
||||
|
||||
// Convert to ANSI strings
|
||||
CStringA szPathNameA(pszPathName), szFileTitleA(strFileTitle);
|
||||
|
||||
MapiFileDesc attachment = { 0 };
|
||||
attachment.nPosition = (ULONG)-1;
|
||||
attachment.lpszPathName = (LPSTR)(LPCSTR)szPathNameA;
|
||||
attachment.lpszFileName = (LPSTR)(LPCSTR)szFileTitleA;
|
||||
|
||||
MapiMessage message = { 0 };
|
||||
message.lpszSubject = NULL;
|
||||
message.nFileCount = 1;
|
||||
message.lpFiles = &attachment;
|
||||
|
||||
// Try again but in ANSI version
|
||||
FN_MAPISendMail pMAPISendMail = (FN_MAPISendMail)::GetProcAddress(hMAPI, "MAPISendMail");
|
||||
if (pMAPISendMail)
|
||||
{
|
||||
pMAPISendMail(0, (ULONG_PTR)hWnd, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0);
|
||||
::FreeLibrary(hMAPI);
|
||||
return TRUE; // MAPISendMail will show an error message on failure
|
||||
}
|
||||
|
||||
::FreeLibrary(hMAPI);
|
||||
return FALSE; // Failure
|
||||
}
|
||||
|
||||
BOOL CMainWindow::GetOpenFileName(IN OUT LPTSTR pszFile, INT cchMaxFile)
|
||||
{
|
||||
static OPENFILENAME ofn = { 0 };
|
||||
|
@ -238,6 +352,9 @@ _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, INT nC
|
|||
// Write back settings to registry
|
||||
registrySettings.Store();
|
||||
|
||||
if (g_szMailTempFile[0])
|
||||
::DeleteFileW(g_szMailTempFile);
|
||||
|
||||
// Return the value that PostQuitMessage() gave
|
||||
return (INT)msg.wParam;
|
||||
}
|
||||
|
|
|
@ -221,3 +221,4 @@
|
|||
#define IDS_PRINTRES 939
|
||||
#define IDS_CANTPASTE 940
|
||||
#define IDS_SAVEERROR 941
|
||||
#define IDS_CANTSENDMAIL 942
|
||||
|
|
|
@ -666,6 +666,13 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
|
|||
if (pd.hDevNames)
|
||||
GlobalFree(pd.hDevNames);
|
||||
break;
|
||||
case IDM_FILESEND:
|
||||
canvasWindow.finishDrawing();
|
||||
if (!OpenMailer(m_hWnd, g_szFileName))
|
||||
{
|
||||
ShowError(IDS_CANTSENDMAIL);
|
||||
}
|
||||
break;
|
||||
case IDM_FILEASWALLPAPERPLANE:
|
||||
RegistrySettings::SetWallpaper(g_szFileName, RegistrySettings::TILED);
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue