ReactOS 0.4.15-dev-6656-gbbb33a6
main.cpp File Reference
#include "precomp.h"
#include <mapi.h>
#include <mapicode.h>
Include dependency graph for main.cpp:

Go to the source code of this file.

Typedefs

typedef ULONG(WINAPIFN_MAPISendMail) (LHANDLE, ULONG_PTR, lpMapiMessage, FLAGS, ULONG)
 
typedef ULONG(WINAPIFN_MAPISendMailW) (LHANDLE, ULONG_PTR, lpMapiMessageW, FLAGS, ULONG)
 

Functions

static BOOL FileExtFromFilter (LPTSTR pExt, OPENFILENAME *pOFN)
 
static UINT_PTR APIENTRY OFNHookProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
BOOL OpenMailer (HWND hWnd, LPCWSTR pszPathName)
 
INT WINAPI _tWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, INT nCmdShow)
 

Variables

POINT g_ptStart
 
POINT g_ptEnd
 
BOOL g_askBeforeEnlarging = FALSE
 
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
 
CMainWindow mainWindow
 

Typedef Documentation

◆ FN_MAPISendMail

typedef ULONG(WINAPI * FN_MAPISendMail) (LHANDLE, ULONG_PTR, lpMapiMessage, FLAGS, ULONG)

Definition at line 76 of file main.cpp.

◆ FN_MAPISendMailW

typedef ULONG(WINAPI * FN_MAPISendMailW) (LHANDLE, ULONG_PTR, lpMapiMessageW, FLAGS, ULONG)

Definition at line 77 of file main.cpp.

Function Documentation

◆ _tWinMain()

INT WINAPI _tWinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPTSTR  lpCmdLine,
INT  nCmdShow 
)

Definition at line 300 of file main.cpp.

301{
302#ifdef _DEBUG
303 // Report any memory leaks on exit
305#endif
306
308
309 // Initialize common controls library
311 iccx.dwSize = sizeof(iccx);
314
315 // Load settings from registry
316 registrySettings.Load(nCmdShow);
317
318 // Create the main window
319 if (!mainWindow.DoCreate())
320 {
321 MessageBox(NULL, TEXT("Failed to create main window."), NULL, MB_ICONERROR);
322 return 1;
323 }
324
325 // Initialize imageModel
326 if (__argc < 2 || !DoLoadImageFile(mainWindow, __targv[1], TRUE))
328
329 // Make the window visible on the screen
331
332 // Load the access keys
334
335 // The message loop
336 MSG msg;
337 while (::GetMessage(&msg, NULL, 0, 0))
338 {
339 if (fontsDialog.IsWindow() && fontsDialog.IsDialogMessage(&msg))
340 continue;
341
343 continue;
344
347 }
348
349 // Unload the access keys
351
352 // Write back settings to registry
354
355 if (g_szMailTempFile[0])
357
358 // Return the value that PostQuitMessage() gave
359 return (INT)msg.wParam;
360}
#define msg(x)
Definition: auth_time.c:54
CFontsDialog fontsDialog
Definition: dialogs.cpp:21
WCHAR g_szMailTempFile[MAX_LONG_PATH]
Definition: main.cpp:17
CMainWindow mainWindow
Definition: main.cpp:22
HINSTANCE g_hinstExe
Definition: main.cpp:15
HINSTANCE hInstance
Definition: charmap.c:19
BOOL ShowWindow(int nCmdShow)
Definition: atlwin.h:1333
HWND DoCreate()
Definition: main.cpp:287
WINDOWPLACEMENT WindowPlacement
Definition: registry.h:29
void Load(INT nCmdShow)
Definition: registry.cpp:92
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:893
#define _CRTDBG_LEAK_CHECK_DF
Definition: crtdbg.h:52
#define _CrtSetDbgFlag(f)
Definition: crtdbg.h:241
#define _CRTDBG_ALLOC_MEM_DF
Definition: crtdbg.h:47
HBITMAP InitializeImage(LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isFile)
Definition: dib.cpp:227
HBITMAP DoLoadImageFile(HWND hwnd, LPCWSTR name, BOOL fIsMainFile)
Definition: dib.cpp:253
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
RegistrySettings registrySettings
Definition: registry.cpp:14
_CRTIMP int __argc
Definition: getargs.c:21
#define __targv
Definition: tchar.h:504
#define TEXT(s)
Definition: k32.h:26
HACCEL hAccel
Definition: main.c:47
#define ICC_USEREX_CLASSES
Definition: commctrl.h:68
#define ICC_STANDARD_CLASSES
Definition: commctrl.h:73
#define ICC_BAR_CLASSES
Definition: commctrl.h:60
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
int32_t INT
Definition: typedefs.h:58
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define MB_ICONERROR
Definition: winuser.h:781
#define GetMessage
Definition: winuser.h:5780
#define MessageBox
Definition: winuser.h:5812
#define DispatchMessage
Definition: winuser.h:5755
BOOL WINAPI DestroyAcceleratorTable(_In_ HACCEL)
#define TranslateAccelerator
Definition: winuser.h:5850
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define LoadAccelerators
Definition: winuser.h:5800

◆ FileExtFromFilter()

static BOOL FileExtFromFilter ( LPTSTR  pExt,
OPENFILENAME pOFN 
)
static

Definition at line 28 of file main.cpp.

29{
30 LPTSTR pchExt = pExt;
31 *pchExt = 0;
32
33 DWORD nIndex = 1;
34 for (LPCTSTR pch = pOFN->lpstrFilter; *pch; ++nIndex)
35 {
36 pch += lstrlen(pch) + 1;
37 if (pOFN->nFilterIndex == nIndex)
38 {
39 for (++pch; *pch && *pch != _T(';'); ++pch)
40 {
41 *pchExt++ = *pch;
42 }
43 *pchExt = 0;
44 CharLower(pExt);
45 return TRUE;
46 }
47 pch += lstrlen(pch) + 1;
48 }
49 return FALSE;
50}
unsigned long DWORD
Definition: ntddk_ex.h:95
#define pch(ap)
Definition: match.c:418
DWORD nFilterIndex
Definition: commdlg.h:335
LPCSTR lpstrFilter
Definition: commdlg.h:332
#define _T(x)
Definition: vfdio.h:22
#define lstrlen
Definition: winbase.h:3801
#define CharLower
Definition: winuser.h:5727
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
CHAR * LPTSTR
Definition: xmlstorage.h:192

Referenced by OFNHookProc().

◆ OFNHookProc()

static UINT_PTR APIENTRY OFNHookProc ( HWND  hwnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 54 of file main.cpp.

55{
56 HWND hParent;
57 OFNOTIFY *pon;
58 switch (uMsg)
59 {
60 case WM_NOTIFY:
61 pon = (OFNOTIFY *)lParam;
62 if (pon->hdr.code == CDN_TYPECHANGE)
63 {
64 hParent = GetParent(hwnd);
70 }
71 break;
72 }
73 return 0;
74}
PRTL_UNICODE_STRING_BUFFER Path
static BOOL FileExtFromFilter(LPTSTR pExt, OPENFILENAME *pOFN)
Definition: main.cpp:28
LPARAM lParam
Definition: combotst.c:139
#define CDM_SETCONTROLTEXT
Definition: commdlg.h:47
#define CDM_GETFILEPATH
Definition: commdlg.h:44
#define CDN_TYPECHANGE
Definition: commdlg.h:39
#define MAX_PATH
Definition: compat.h:34
#define WM_NOTIFY
Definition: richedit.h:61
#define PathFindExtension
Definition: shlwapi.h:907
#define PathFindFileName
Definition: shlwapi.h:911
#define _countof(array)
Definition: sndvol32.h:68
NMHDR hdr
Definition: commdlg.h:406
LPOPENFILENAMEA lpOFN
Definition: commdlg.h:407
UINT code
Definition: winuser.h:3149
LPSTR lpstrFile
Definition: commdlg.h:336
DWORD nMaxFile
Definition: commdlg.h:337
#define lstrcpyn
Definition: winbase.h:3800
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
#define SendMessage
Definition: winuser.h:5833
HWND WINAPI GetParent(_In_ HWND)
char TCHAR
Definition: xmlstorage.h:189

Referenced by CMainWindow::GetSaveFileName().

◆ OpenMailer()

BOOL OpenMailer ( HWND  hWnd,
LPCWSTR  pszPathName 
)

Definition at line 79 of file main.cpp.

80{
81 // Delete the temporary file if any
82 if (g_szMailTempFile[0])
83 {
86 }
87
88 CStringW strFileTitle;
89 if (PathFileExistsW(pszPathName) && imageModel.IsImageSaved())
90 {
91 strFileTitle = PathFindFileNameW(pszPathName);
92 }
93 else // Not existing or not saved
94 {
95 // Get the name of a temporary file
96 WCHAR szTempDir[MAX_PATH];
97 ::GetTempPathW(_countof(szTempDir), szTempDir);
98 if (!::GetTempFileNameW(szTempDir, L"afx", 0, g_szMailTempFile))
99 return FALSE; // Failure
100
102 {
103 // Set file title
104 strFileTitle = PathFindFileNameW(g_szFileName);
105
106 // Copy to the temporary file
108 {
110 return FALSE; // Failure
111 }
112 }
113 else
114 {
115 // Set file title
116 strFileTitle.LoadString(IDS_DEFAULTFILENAME);
117 strFileTitle += L".png";
118
119 // Save it to the temporary file
120 HBITMAP hbmLocked = imageModel.LockBitmap();
121 BOOL ret = SaveDIBToFile(hbmLocked, g_szMailTempFile, FALSE, Gdiplus::ImageFormatPNG);
122 imageModel.UnlockBitmap(hbmLocked);
123 if (!ret)
124 {
126 return FALSE; // Failure
127 }
128 }
129
130 // Use the temporary file
131 pszPathName = g_szMailTempFile;
132 }
133
134 // Load "mapi32.dll"
135 HINSTANCE hMAPI = LoadLibraryW(L"mapi32.dll");
136 if (!hMAPI)
137 return FALSE; // Failure
138
139 // Attachment
140 MapiFileDescW attachmentW = { 0 };
141 attachmentW.nPosition = (ULONG)-1;
142 attachmentW.lpszPathName = (LPWSTR)pszPathName;
143 attachmentW.lpszFileName = (LPWSTR)(LPCWSTR)strFileTitle;
144
145 // Message with attachment
146 MapiMessageW messageW = { 0 };
147 messageW.lpszSubject = NULL;
148 messageW.nFileCount = 1;
149 messageW.lpFiles = &attachmentW;
150
151 // First, try to open the mailer by the function of Unicode version
152 FN_MAPISendMailW pMAPISendMailW = (FN_MAPISendMailW)::GetProcAddress(hMAPI, "MAPISendMailW");
153 if (pMAPISendMailW)
154 {
155 pMAPISendMailW(0, (ULONG_PTR)hWnd, &messageW, MAPI_DIALOG | MAPI_LOGON_UI, 0);
156 ::FreeLibrary(hMAPI);
157 return TRUE; // MAPISendMailW will show an error message on failure
158 }
159
160 // Convert to ANSI strings
161 CStringA szPathNameA(pszPathName), szFileTitleA(strFileTitle);
162
163 MapiFileDesc attachment = { 0 };
165 attachment.lpszPathName = (LPSTR)(LPCSTR)szPathNameA;
166 attachment.lpszFileName = (LPSTR)(LPCSTR)szFileTitleA;
167
168 MapiMessage message = { 0 };
169 message.lpszSubject = NULL;
170 message.nFileCount = 1;
171 message.lpFiles = &attachment;
172
173 // Try again but in ANSI version
174 FN_MAPISendMail pMAPISendMail = (FN_MAPISendMail)::GetProcAddress(hMAPI, "MAPISendMail");
175 if (pMAPISendMail)
176 {
177 pMAPISendMail(0, (ULONG_PTR)hWnd, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0);
178 ::FreeLibrary(hMAPI);
179 return TRUE; // MAPISendMail will show an error message on failure
180 }
181
182 ::FreeLibrary(hMAPI);
183 return FALSE; // Failure
184}
HWND hWnd
Definition: settings.c:17
ULONG(WINAPI * FN_MAPISendMail)(LHANDLE, ULONG_PTR, lpMapiMessage, FLAGS, ULONG)
Definition: main.cpp:76
TCHAR g_szFileName[MAX_LONG_PATH]
Definition: main.cpp:16
ULONG(WINAPI * FN_MAPISendMailW)(LHANDLE, ULONG_PTR, lpMapiMessageW, FLAGS, ULONG)
Definition: main.cpp:77
#define IDS_DEFAULTFILENAME
Definition: resource.h:186
BOOL LoadString(_In_ UINT nID)
Definition: cstringt.h:639
HBITMAP LockBitmap()
Definition: history.cpp:288
BOOL IsImageSaved() const
Definition: history.cpp:165
void UnlockBitmap(HBITMAP hbmLocked)
Definition: history.cpp:297
BOOL SaveDIBToFile(HBITMAP hBitmap, LPCWSTR FileName, BOOL fIsMainFile, REFGUID guidFileType)
Definition: dib.cpp:152
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define LoadLibraryW(x)
Definition: compat.h:747
static const WCHAR messageW[]
Definition: error.c:33
BOOL WINAPI CopyFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName, IN BOOL bFailIfExists)
Definition: copy.c:439
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2080
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:394
BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
Definition: path.c:1777
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
unsigned int BOOL
Definition: ntddk_ex.h:94
GLenum attachment
Definition: glext.h:6295
ImageModel imageModel
Definition: history.cpp:11
#define MAPI_DIALOG
Definition: mapi.h:177
#define MAPI_LOGON_UI
Definition: mapi.h:159
static HBITMAP
Definition: button.c:44
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
ULONG nPosition
Definition: mapi.h:54
PWSTR lpszPathName
Definition: mapi.h:55
PWSTR lpszFileName
Definition: mapi.h:56
ULONG nPosition
Definition: mapi.h:44
Definition: tftpd.h:60
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
int ret
const char * LPCSTR
Definition: xmlstorage.h:183
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by CMainWindow::OnCommand().

Variable Documentation

◆ g_askBeforeEnlarging

BOOL g_askBeforeEnlarging = FALSE

Definition at line 14 of file main.cpp.

Referenced by CMainWindow::InsertSelectionFromHBITMAP().

◆ g_hinstExe

◆ g_imageSaved

◆ g_isAFile

◆ g_ptEnd

POINT g_ptEnd

Definition at line 13 of file main.cpp.

◆ g_ptStart

◆ g_showGrid

BOOL g_showGrid = FALSE

◆ g_szFileName

◆ g_szMailTempFile

WCHAR g_szMailTempFile[MAX_LONG_PATH] = { 0 }

Definition at line 17 of file main.cpp.

Referenced by _tWinMain(), and OpenMailer().

◆ mainWindow