ReactOS 0.4.15-dev-8419-g7f0e8a3
main.cpp File Reference
#include "precomp.h"
#include <dlgs.h>
#include <mapi.h>
#include <assert.h>
Include dependency graph for main.cpp:

Go to the source code of this file.

Macros

#define SPI_GETWHEELSCROLLCHARS   0x006C
 
#define MAX_RECENT_PATHNAME_DISPLAY   30
 

Typedefs

typedef HWND(WINAPIFN_HtmlHelpW) (HWND, LPCWSTR, UINT, DWORD_PTR)
 
typedef ULONG(WINAPIFN_MAPISendMail) (LHANDLE, ULONG_PTR, lpMapiMessage, FLAGS, ULONG)
 
typedef ULONG(WINAPIFN_MAPISendMailW) (LHANDLE, ULONG_PTR, lpMapiMessageW, FLAGS, ULONG)
 

Functions

void ShowOutOfMemory (void)
 
static BOOL FileExtFromFilter (LPWSTR pExt, OPENFILENAME *pOFN)
 
static UINT_PTR APIENTRY OFNHookProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
BOOL OpenMailer (HWND hWnd, LPCWSTR pszPathName)
 
static HWND DoHtmlHelpW (HWND hwndCaller, LPCWSTR pszFile, UINT uCommand, DWORD_PTR dwData)
 
INT WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nCmdShow)
 

Variables

BOOL g_askBeforeEnlarging = FALSE
 
HINSTANCE g_hinstExe = NULL
 
WCHAR 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
 
HWND g_hStatusBar = NULL
 
CMainWindow mainWindow
 
static HINSTANCE s_hHHCTRL_OCX = NULL
 
static FN_HtmlHelpW s_pHtmlHelpW = NULL
 

Macro Definition Documentation

◆ MAX_RECENT_PATHNAME_DISPLAY

#define MAX_RECENT_PATHNAME_DISPLAY   30

◆ SPI_GETWHEELSCROLLCHARS

#define SPI_GETWHEELSCROLLCHARS   0x006C

Typedef Documentation

◆ FN_HtmlHelpW

typedef HWND(WINAPI * FN_HtmlHelpW) (HWND, LPCWSTR, UINT, DWORD_PTR)

Definition at line 27 of file main.cpp.

◆ FN_MAPISendMail

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

Definition at line 96 of file main.cpp.

◆ FN_MAPISendMailW

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

Definition at line 97 of file main.cpp.

Function Documentation

◆ DoHtmlHelpW()

static HWND DoHtmlHelpW ( HWND  hwndCaller,
LPCWSTR  pszFile,
UINT  uCommand,
DWORD_PTR  dwData 
)
static

Definition at line 321 of file main.cpp.

322{
324
325 if (!s_hHHCTRL_OCX && (uCommand != HH_CLOSE_ALL))
326 {
327 // The function loads the system library, not local
329 StringCchCatW(szPath, _countof(szPath), L"\\hhctrl.ocx");
331 if (s_hHHCTRL_OCX)
333 }
334
335 if (!s_pHtmlHelpW)
336 return NULL;
337
338 return s_pHtmlHelpW(hwndCaller, pszFile, uCommand, dwData);
339}
HWND(WINAPI * FN_HtmlHelpW)(HWND, LPCWSTR, UINT, DWORD_PTR)
Definition: main.cpp:27
static HINSTANCE s_hHHCTRL_OCX
Definition: main.cpp:29
static FN_HtmlHelpW s_pHtmlHelpW
Definition: main.cpp:30
#define NULL
Definition: types.h:112
#define GetProcAddress(x, y)
Definition: compat.h:753
#define MAX_PATH
Definition: compat.h:34
#define LoadLibraryW(x)
Definition: compat.h:747
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313
#define HH_CLOSE_ALL
Definition: htmlhelp.h:41
LPCWSTR szPath
Definition: env.c:37
static HANDLE ULONG_PTR dwData
Definition: file.c:35
#define L(x)
Definition: ntvdm.h:50
#define _countof(array)
Definition: sndvol32.h:70
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CMainWindow::OnCommand(), and CMainWindow::OnDestroy().

◆ FileExtFromFilter()

static BOOL FileExtFromFilter ( LPWSTR  pExt,
OPENFILENAME pOFN 
)
static

Definition at line 48 of file main.cpp.

49{
50 LPWSTR pchExt = pExt;
51 *pchExt = 0;
52
53 DWORD nIndex = 1;
54 for (LPCWSTR pch = pOFN->lpstrFilter; *pch; ++nIndex)
55 {
56 pch += lstrlen(pch) + 1;
57 if (pOFN->nFilterIndex == nIndex)
58 {
59 for (++pch; *pch && *pch != L';'; ++pch)
60 {
61 *pchExt++ = *pch;
62 }
63 *pchExt = 0;
64 CharLower(pExt);
65 return TRUE;
66 }
67 pch += wcslen(pch) + 1;
68 }
69 return FALSE;
70}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define pch(ap)
Definition: match.c:418
DWORD nFilterIndex
Definition: commdlg.h:335
LPCSTR lpstrFilter
Definition: commdlg.h:332
#define lstrlen
Definition: winbase.h:3876
#define CharLower
Definition: winuser.h:5746
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by OFNHookProc().

◆ OFNHookProc()

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

Definition at line 74 of file main.cpp.

75{
76 HWND hParent;
77 OFNOTIFYW *pon;
79 switch (uMsg)
80 {
81 case WM_NOTIFY:
82 pon = (OFNOTIFYW *)lParam;
83 if (pon->hdr.code == CDN_TYPECHANGE)
84 {
85 hParent = GetParent(hwnd);
90 }
91 break;
92 }
93 return 0;
94}
PRTL_UNICODE_STRING_BUFFER Path
static BOOL FileExtFromFilter(LPWSTR pExt, OPENFILENAME *pOFN)
Definition: main.cpp:48
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 cmb13
Definition: dlgs.h:60
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:394
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
#define WM_NOTIFY
Definition: richedit.h:61
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
NMHDR hdr
Definition: commdlg.h:411
LPOPENFILENAMEW lpOFN
Definition: commdlg.h:412
UINT code
Definition: winuser.h:3159
LPWSTR lpstrFile
Definition: commdlg.h:367
DWORD nMaxFile
Definition: commdlg.h:368
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
HWND WINAPI GetParent(_In_ HWND)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by CMainWindow::GetSaveFileName().

◆ OpenMailer()

BOOL OpenMailer ( HWND  hWnd,
LPCWSTR  pszPathName 
)

Definition at line 99 of file main.cpp.

100{
101 // Delete the temporary file if any
102 if (g_szMailTempFile[0])
103 {
106 }
107
108 CStringW strFileTitle;
109 if (PathFileExistsW(pszPathName) && imageModel.IsImageSaved())
110 {
111 strFileTitle = PathFindFileNameW(pszPathName);
112 }
113 else // Not existing or not saved
114 {
115 // Get the name of a temporary file
116 WCHAR szTempDir[MAX_PATH];
117 ::GetTempPathW(_countof(szTempDir), szTempDir);
118 if (!::GetTempFileNameW(szTempDir, L"afx", 0, g_szMailTempFile))
119 return FALSE; // Failure
120
122 {
123 // Set file title
124 strFileTitle = PathFindFileNameW(g_szFileName);
125
126 // Copy to the temporary file
128 {
130 return FALSE; // Failure
131 }
132 }
133 else
134 {
135 // Set file title
136 strFileTitle.LoadString(IDS_DEFAULTFILENAME);
137 strFileTitle += L".png";
138
139 // Save it to the temporary file
140 HBITMAP hbmLocked = imageModel.LockBitmap();
141 BOOL ret = SaveDIBToFile(hbmLocked, g_szMailTempFile, FALSE, Gdiplus::ImageFormatPNG);
142 imageModel.UnlockBitmap(hbmLocked);
143 if (!ret)
144 {
146 return FALSE; // Failure
147 }
148 }
149
150 // Use the temporary file
151 pszPathName = g_szMailTempFile;
152 }
153
154 // Load "mapi32.dll"
155 HINSTANCE hMAPI = LoadLibraryW(L"mapi32.dll");
156 if (!hMAPI)
157 return FALSE; // Failure
158
159 // Attachment
160 MapiFileDescW attachmentW = { 0 };
161 attachmentW.nPosition = (ULONG)-1;
162 attachmentW.lpszPathName = (LPWSTR)pszPathName;
163 attachmentW.lpszFileName = (LPWSTR)(LPCWSTR)strFileTitle;
164
165 // Message with attachment
166 MapiMessageW messageW = { 0 };
167 messageW.lpszSubject = NULL;
168 messageW.nFileCount = 1;
169 messageW.lpFiles = &attachmentW;
170
171 // First, try to open the mailer by the function of Unicode version
172 FN_MAPISendMailW pMAPISendMailW = (FN_MAPISendMailW)::GetProcAddress(hMAPI, "MAPISendMailW");
173 if (pMAPISendMailW)
174 {
175 pMAPISendMailW(0, (ULONG_PTR)hWnd, &messageW, MAPI_DIALOG | MAPI_LOGON_UI, 0);
176 ::FreeLibrary(hMAPI);
177 return TRUE; // MAPISendMailW will show an error message on failure
178 }
179
180 // Convert to ANSI strings
181 CStringA szPathNameA(pszPathName), szFileTitleA(strFileTitle);
182
183 MapiFileDesc attachment = { 0 };
185 attachment.lpszPathName = (LPSTR)(LPCSTR)szPathNameA;
186 attachment.lpszFileName = (LPSTR)(LPCSTR)szFileTitleA;
187
188 MapiMessage message = { 0 };
189 message.lpszSubject = NULL;
190 message.nFileCount = 1;
191 message.lpFiles = &attachment;
192
193 // Try again but in ANSI version
194 FN_MAPISendMail pMAPISendMail = (FN_MAPISendMail)::GetProcAddress(hMAPI, "MAPISendMail");
195 if (pMAPISendMail)
196 {
197 pMAPISendMail(0, (ULONG_PTR)hWnd, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0);
198 ::FreeLibrary(hMAPI);
199 return TRUE; // MAPISendMail will show an error message on failure
200 }
201
202 ::FreeLibrary(hMAPI);
203 return FALSE; // Failure
204}
HWND hWnd
Definition: settings.c:17
ULONG(WINAPI * FN_MAPISendMail)(LHANDLE, ULONG_PTR, lpMapiMessage, FLAGS, ULONG)
Definition: main.cpp:96
WCHAR g_szMailTempFile[MAX_LONG_PATH]
Definition: main.cpp:19
WCHAR g_szFileName[MAX_LONG_PATH]
Definition: main.cpp:18
ULONG(WINAPI * FN_MAPISendMailW)(LHANDLE, ULONG_PTR, lpMapiMessageW, FLAGS, ULONG)
Definition: main.cpp:97
#define IDS_DEFAULTFILENAME
Definition: resource.h:192
BOOL LoadString(_In_ UINT nID)
Definition: cstringt.h:639
HBITMAP LockBitmap()
Definition: history.cpp:345
BOOL IsImageSaved() const
Definition: history.cpp:224
void UnlockBitmap(HBITMAP hbmLocked)
Definition: history.cpp:354
BOOL SaveDIBToFile(HBITMAP hBitmap, LPCWSTR FileName, BOOL fIsMainFile, REFGUID guidFileType)
Definition: dib.cpp:151
#define FreeLibrary(x)
Definition: compat.h:748
static const WCHAR messageW[]
Definition: error.c:33
BOOL WINAPI CopyFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName, IN BOOL bFailIfExists)
Definition: copy.c:439
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2080
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
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

Referenced by CMainWindow::OnCommand().

◆ ShowOutOfMemory()

void ShowOutOfMemory ( void  )

Definition at line 34 of file main.cpp.

35{
36 WCHAR szText[256];
38 NULL,
40 0,
41 szText, _countof(szText),
42 NULL);
44}
CMainWindow mainWindow
Definition: main.cpp:25
int MessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption=NULL, UINT nType=MB_OK)
Definition: atlwin.h:1002
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:420
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423
#define MB_ICONERROR
Definition: winuser.h:787

Referenced by ImageModel::Crop(), InitializeImage(), CMainWindow::OnCommand(), and ImageModel::PushImageForUndo().

◆ wWinMain()

INT WINAPI wWinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPWSTR  lpCmdLine,
INT  nCmdShow 
)

Definition at line 1333 of file main.cpp.

1334{
1336
1337 // Initialize common controls library
1339 iccx.dwSize = sizeof(iccx);
1341 InitCommonControlsEx(&iccx);
1342
1343 // Load settings from registry
1344 registrySettings.Load(nCmdShow);
1345
1346 // Create the main window
1347 if (!mainWindow.DoCreate())
1348 {
1349 MessageBox(NULL, L"Failed to create main window.", NULL, MB_ICONERROR);
1350 return 1;
1351 }
1352
1353 // Initialize imageModel
1354 if (__argc < 2 || !DoLoadImageFile(mainWindow, __targv[1], TRUE))
1356
1357 // Make the window visible on the screen
1359
1360 // Load the access keys
1362
1363 // The message loop
1364 MSG msg;
1365 while (::GetMessage(&msg, NULL, 0, 0))
1366 {
1367 if (fontsDialog.IsWindow() && fontsDialog.IsDialogMessage(&msg))
1368 continue;
1369
1371 continue;
1372
1375 }
1376
1377 // Unload the access keys
1379
1380 // Write back settings to registry
1382
1383 if (g_szMailTempFile[0])
1385
1386 // Return the value that PostQuitMessage() gave
1387 return (INT)msg.wParam;
1388}
#define msg(x)
Definition: auth_time.c:54
CFontsDialog fontsDialog
Definition: dialogs.cpp:16
HINSTANCE g_hinstExe
Definition: main.cpp:17
RegistrySettings registrySettings
Definition: registry.cpp:14
HINSTANCE hInstance
Definition: charmap.c:19
BOOL ShowWindow(int nCmdShow)
Definition: atlwin.h:1333
HWND DoCreate()
Definition: main.cpp:309
WINDOWPLACEMENT WindowPlacement
Definition: registry.h:29
void Load(INT nCmdShow)
Definition: registry.cpp:115
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:893
HBITMAP InitializeImage(LPCWSTR name, LPWIN32_FIND_DATAW pFound, BOOL isFile)
Definition: dib.cpp:226
HBITMAP DoLoadImageFile(HWND hwnd, LPCWSTR name, BOOL fIsMainFile)
Definition: dib.cpp:256
_CRTIMP int __argc
Definition: getargs.c:21
#define __targv
Definition: tchar.h:504
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 GetMessage
Definition: winuser.h:5799
HACCEL WINAPI LoadAcceleratorsW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
#define MessageBox
Definition: winuser.h:5831
int WINAPI TranslateAcceleratorW(_In_ HWND, _In_ HACCEL, _In_ LPMSG)
#define DispatchMessage
Definition: winuser.h:5774
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
BOOL WINAPI DestroyAcceleratorTable(_In_ HACCEL)

Variable Documentation

◆ g_askBeforeEnlarging

BOOL g_askBeforeEnlarging = FALSE

Definition at line 16 of file main.cpp.

Referenced by CMainWindow::InsertSelectionFromHBITMAP().

◆ g_hinstExe

◆ g_hStatusBar

◆ g_imageSaved

◆ g_isAFile

BOOL g_isAFile = FALSE

Definition at line 20 of file main.cpp.

Referenced by CAttributesDialog::OnInitDialog(), CMainWindow::saveImage(), and SetFileInfo().

◆ g_showGrid

BOOL g_showGrid = FALSE

◆ g_szFileName

◆ g_szMailTempFile

WCHAR g_szMailTempFile[MAX_LONG_PATH] = { 0 }

Definition at line 19 of file main.cpp.

Referenced by OpenMailer(), and wWinMain().

◆ mainWindow

◆ s_hHHCTRL_OCX

HINSTANCE s_hHHCTRL_OCX = NULL
static

Definition at line 29 of file main.cpp.

Referenced by DoHtmlHelpW(), and CMainWindow::OnDestroy().

◆ s_pHtmlHelpW

FN_HtmlHelpW s_pHtmlHelpW = NULL
static

Definition at line 30 of file main.cpp.

Referenced by DoHtmlHelpW(), and CMainWindow::OnDestroy().