https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ba53f72a87f5abd3c1abfaf59ebaeb31d2ad7e49

commit ba53f72a87f5abd3c1abfaf59ebaeb31d2ad7e49
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Wed Aug 9 23:59:34 2023 +0900
Commit:     GitHub <[email protected]>
CommitDate: Wed Aug 9 23:59:34 2023 +0900

    [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
---
 base/applications/mspaint/common.h      |   1 +
 base/applications/mspaint/dib.cpp       |   4 +-
 base/applications/mspaint/dib.h         |   2 +-
 base/applications/mspaint/lang/bg-BG.rc |   1 +
 base/applications/mspaint/lang/cs-CZ.rc |   1 +
 base/applications/mspaint/lang/de-DE.rc |   1 +
 base/applications/mspaint/lang/en-GB.rc |   1 +
 base/applications/mspaint/lang/en-US.rc |   1 +
 base/applications/mspaint/lang/es-ES.rc |   1 +
 base/applications/mspaint/lang/et-EE.rc |   1 +
 base/applications/mspaint/lang/eu-ES.rc |   1 +
 base/applications/mspaint/lang/fr-FR.rc |   1 +
 base/applications/mspaint/lang/he-IL.rc |   1 +
 base/applications/mspaint/lang/hu-HU.rc |   1 +
 base/applications/mspaint/lang/id-ID.rc |   1 +
 base/applications/mspaint/lang/it-IT.rc |   1 +
 base/applications/mspaint/lang/ja-JP.rc |   1 +
 base/applications/mspaint/lang/nl-NL.rc |   1 +
 base/applications/mspaint/lang/no-NO.rc |   1 +
 base/applications/mspaint/lang/pl-PL.rc |   1 +
 base/applications/mspaint/lang/pt-BR.rc |   1 +
 base/applications/mspaint/lang/pt-PT.rc |   1 +
 base/applications/mspaint/lang/ro-RO.rc |   1 +
 base/applications/mspaint/lang/ru-RU.rc |   1 +
 base/applications/mspaint/lang/sk-SK.rc |   1 +
 base/applications/mspaint/lang/sq-AL.rc |   1 +
 base/applications/mspaint/lang/sv-SE.rc |   1 +
 base/applications/mspaint/lang/tr-TR.rc |   1 +
 base/applications/mspaint/lang/uk-UA.rc |   1 +
 base/applications/mspaint/lang/vi-VN.rc |   1 +
 base/applications/mspaint/lang/zh-CN.rc |   1 +
 base/applications/mspaint/lang/zh-HK.rc |   1 +
 base/applications/mspaint/lang/zh-TW.rc |   1 +
 base/applications/mspaint/main.cpp      | 117 ++++++++++++++++++++++++++++++++
 base/applications/mspaint/resource.h    |   1 +
 base/applications/mspaint/winproc.cpp   |   7 ++
 36 files changed, 159 insertions(+), 3 deletions(-)

diff --git a/base/applications/mspaint/common.h 
b/base/applications/mspaint/common.h
index a3f3950ff7e..ee103d74911 100644
--- a/base/applications/mspaint/common.h
+++ b/base/applications/mspaint/common.h
@@ -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);
diff --git a/base/applications/mspaint/dib.cpp 
b/base/applications/mspaint/dib.cpp
index a5b3f0b7896..c12a2f013a8 100644
--- a/base/applications/mspaint/dib.cpp
+++ b/base/applications/mspaint/dib.cpp
@@ -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))
diff --git a/base/applications/mspaint/dib.h b/base/applications/mspaint/dib.h
index 9c1e5d4f09c..cefdb6e42b5 100644
--- a/base/applications/mspaint/dib.h
+++ b/base/applications/mspaint/dib.h
@@ -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);
 
diff --git a/base/applications/mspaint/lang/bg-BG.rc 
b/base/applications/mspaint/lang/bg-BG.rc
index f3b6382d5b7..66bf74763c3 100644
--- a/base/applications/mspaint/lang/bg-BG.rc
+++ b/base/applications/mspaint/lang/bg-BG.rc
@@ -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
diff --git a/base/applications/mspaint/lang/cs-CZ.rc 
b/base/applications/mspaint/lang/cs-CZ.rc
index 5e5fcbb6caa..57608b40f96 100644
--- a/base/applications/mspaint/lang/cs-CZ.rc
+++ b/base/applications/mspaint/lang/cs-CZ.rc
@@ -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
diff --git a/base/applications/mspaint/lang/de-DE.rc 
b/base/applications/mspaint/lang/de-DE.rc
index 4cfe2e6c328..fb947b1eeb2 100644
--- a/base/applications/mspaint/lang/de-DE.rc
+++ b/base/applications/mspaint/lang/de-DE.rc
@@ -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
diff --git a/base/applications/mspaint/lang/en-GB.rc 
b/base/applications/mspaint/lang/en-GB.rc
index ce5b06fd04f..9dc21b13c6a 100644
--- a/base/applications/mspaint/lang/en-GB.rc
+++ b/base/applications/mspaint/lang/en-GB.rc
@@ -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
diff --git a/base/applications/mspaint/lang/en-US.rc 
b/base/applications/mspaint/lang/en-US.rc
index 935c3fe4c8b..805c239e8d0 100644
--- a/base/applications/mspaint/lang/en-US.rc
+++ b/base/applications/mspaint/lang/en-US.rc
@@ -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
diff --git a/base/applications/mspaint/lang/es-ES.rc 
b/base/applications/mspaint/lang/es-ES.rc
index ac60a967781..a851b972dfc 100644
--- a/base/applications/mspaint/lang/es-ES.rc
+++ b/base/applications/mspaint/lang/es-ES.rc
@@ -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
diff --git a/base/applications/mspaint/lang/et-EE.rc 
b/base/applications/mspaint/lang/et-EE.rc
index 1f8012d233f..78d33480f3a 100644
--- a/base/applications/mspaint/lang/et-EE.rc
+++ b/base/applications/mspaint/lang/et-EE.rc
@@ -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
diff --git a/base/applications/mspaint/lang/eu-ES.rc 
b/base/applications/mspaint/lang/eu-ES.rc
index 1adb078efad..f9f38cd2056 100644
--- a/base/applications/mspaint/lang/eu-ES.rc
+++ b/base/applications/mspaint/lang/eu-ES.rc
@@ -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
diff --git a/base/applications/mspaint/lang/fr-FR.rc 
b/base/applications/mspaint/lang/fr-FR.rc
index cadd7699281..8ea08410321 100644
--- a/base/applications/mspaint/lang/fr-FR.rc
+++ b/base/applications/mspaint/lang/fr-FR.rc
@@ -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
diff --git a/base/applications/mspaint/lang/he-IL.rc 
b/base/applications/mspaint/lang/he-IL.rc
index 03b1ef391e8..7735f853725 100644
--- a/base/applications/mspaint/lang/he-IL.rc
+++ b/base/applications/mspaint/lang/he-IL.rc
@@ -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
diff --git a/base/applications/mspaint/lang/hu-HU.rc 
b/base/applications/mspaint/lang/hu-HU.rc
index d3299286f57..03315eabded 100644
--- a/base/applications/mspaint/lang/hu-HU.rc
+++ b/base/applications/mspaint/lang/hu-HU.rc
@@ -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
diff --git a/base/applications/mspaint/lang/id-ID.rc 
b/base/applications/mspaint/lang/id-ID.rc
index 9ae48324433..eeda00200d3 100644
--- a/base/applications/mspaint/lang/id-ID.rc
+++ b/base/applications/mspaint/lang/id-ID.rc
@@ -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
diff --git a/base/applications/mspaint/lang/it-IT.rc 
b/base/applications/mspaint/lang/it-IT.rc
index d55a546848e..63ad7624367 100644
--- a/base/applications/mspaint/lang/it-IT.rc
+++ b/base/applications/mspaint/lang/it-IT.rc
@@ -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
diff --git a/base/applications/mspaint/lang/ja-JP.rc 
b/base/applications/mspaint/lang/ja-JP.rc
index b44eb8b4b74..a98a0f73bab 100644
--- a/base/applications/mspaint/lang/ja-JP.rc
+++ b/base/applications/mspaint/lang/ja-JP.rc
@@ -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
diff --git a/base/applications/mspaint/lang/nl-NL.rc 
b/base/applications/mspaint/lang/nl-NL.rc
index a08efcab887..29daec70fc7 100644
--- a/base/applications/mspaint/lang/nl-NL.rc
+++ b/base/applications/mspaint/lang/nl-NL.rc
@@ -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
diff --git a/base/applications/mspaint/lang/no-NO.rc 
b/base/applications/mspaint/lang/no-NO.rc
index 40290499bb0..7a16a4d668f 100644
--- a/base/applications/mspaint/lang/no-NO.rc
+++ b/base/applications/mspaint/lang/no-NO.rc
@@ -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
diff --git a/base/applications/mspaint/lang/pl-PL.rc 
b/base/applications/mspaint/lang/pl-PL.rc
index 9dbc184b3c1..b35b2691d2a 100644
--- a/base/applications/mspaint/lang/pl-PL.rc
+++ b/base/applications/mspaint/lang/pl-PL.rc
@@ -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
diff --git a/base/applications/mspaint/lang/pt-BR.rc 
b/base/applications/mspaint/lang/pt-BR.rc
index 9ae3d5de864..c551cd77671 100644
--- a/base/applications/mspaint/lang/pt-BR.rc
+++ b/base/applications/mspaint/lang/pt-BR.rc
@@ -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
diff --git a/base/applications/mspaint/lang/pt-PT.rc 
b/base/applications/mspaint/lang/pt-PT.rc
index 8f164db2991..7ff2ba98503 100644
--- a/base/applications/mspaint/lang/pt-PT.rc
+++ b/base/applications/mspaint/lang/pt-PT.rc
@@ -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
diff --git a/base/applications/mspaint/lang/ro-RO.rc 
b/base/applications/mspaint/lang/ro-RO.rc
index d6afd6a9a01..447e01c5337 100644
--- a/base/applications/mspaint/lang/ro-RO.rc
+++ b/base/applications/mspaint/lang/ro-RO.rc
@@ -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
diff --git a/base/applications/mspaint/lang/ru-RU.rc 
b/base/applications/mspaint/lang/ru-RU.rc
index 654ea538794..125eadbcfdf 100644
--- a/base/applications/mspaint/lang/ru-RU.rc
+++ b/base/applications/mspaint/lang/ru-RU.rc
@@ -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
diff --git a/base/applications/mspaint/lang/sk-SK.rc 
b/base/applications/mspaint/lang/sk-SK.rc
index de9943cb899..dd80ce12592 100644
--- a/base/applications/mspaint/lang/sk-SK.rc
+++ b/base/applications/mspaint/lang/sk-SK.rc
@@ -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
diff --git a/base/applications/mspaint/lang/sq-AL.rc 
b/base/applications/mspaint/lang/sq-AL.rc
index ca4fb20a5bc..a60ef9a2774 100644
--- a/base/applications/mspaint/lang/sq-AL.rc
+++ b/base/applications/mspaint/lang/sq-AL.rc
@@ -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
diff --git a/base/applications/mspaint/lang/sv-SE.rc 
b/base/applications/mspaint/lang/sv-SE.rc
index a944710d617..dfe72b9b0b9 100644
--- a/base/applications/mspaint/lang/sv-SE.rc
+++ b/base/applications/mspaint/lang/sv-SE.rc
@@ -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
diff --git a/base/applications/mspaint/lang/tr-TR.rc 
b/base/applications/mspaint/lang/tr-TR.rc
index 9026820d5d7..fab8c39fcc3 100644
--- a/base/applications/mspaint/lang/tr-TR.rc
+++ b/base/applications/mspaint/lang/tr-TR.rc
@@ -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
diff --git a/base/applications/mspaint/lang/uk-UA.rc 
b/base/applications/mspaint/lang/uk-UA.rc
index 2710a7e410a..f0e0676589a 100644
--- a/base/applications/mspaint/lang/uk-UA.rc
+++ b/base/applications/mspaint/lang/uk-UA.rc
@@ -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
diff --git a/base/applications/mspaint/lang/vi-VN.rc 
b/base/applications/mspaint/lang/vi-VN.rc
index 4cc725d213c..b1c7c2cc227 100644
--- a/base/applications/mspaint/lang/vi-VN.rc
+++ b/base/applications/mspaint/lang/vi-VN.rc
@@ -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
diff --git a/base/applications/mspaint/lang/zh-CN.rc 
b/base/applications/mspaint/lang/zh-CN.rc
index e2283e68e6f..43fa7f34582 100644
--- a/base/applications/mspaint/lang/zh-CN.rc
+++ b/base/applications/mspaint/lang/zh-CN.rc
@@ -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
diff --git a/base/applications/mspaint/lang/zh-HK.rc 
b/base/applications/mspaint/lang/zh-HK.rc
index c76ec7920aa..ff88459ddc6 100644
--- a/base/applications/mspaint/lang/zh-HK.rc
+++ b/base/applications/mspaint/lang/zh-HK.rc
@@ -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
diff --git a/base/applications/mspaint/lang/zh-TW.rc 
b/base/applications/mspaint/lang/zh-TW.rc
index 776a7e5d7e3..10401e53cb8 100644
--- a/base/applications/mspaint/lang/zh-TW.rc
+++ b/base/applications/mspaint/lang/zh-TW.rc
@@ -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
diff --git a/base/applications/mspaint/main.cpp 
b/base/applications/mspaint/main.cpp
index a4cbb54b5b0..ba7ad18c213 100644
--- a/base/applications/mspaint/main.cpp
+++ b/base/applications/mspaint/main.cpp
@@ -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;
 }
diff --git a/base/applications/mspaint/resource.h 
b/base/applications/mspaint/resource.h
index 1e34232d3c1..4ec9f9a0f98 100644
--- a/base/applications/mspaint/resource.h
+++ b/base/applications/mspaint/resource.h
@@ -221,3 +221,4 @@
 #define IDS_PRINTRES    939
 #define IDS_CANTPASTE   940
 #define IDS_SAVEERROR   941
+#define IDS_CANTSENDMAIL 942
diff --git a/base/applications/mspaint/winproc.cpp 
b/base/applications/mspaint/winproc.cpp
index f930174d45d..7aa25091766 100644
--- a/base/applications/mspaint/winproc.cpp
+++ b/base/applications/mspaint/winproc.cpp
@@ -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;

Reply via email to