Warning: This file has been marked up for HTML
/* QuickCase:W KNB Version 1.00 */
#include "mapiapp.h"
#include <string.h>
#include <stdio.h>
#include "mapi.h"
#define MAIN 1
#include "mapinit.h"
HANDLE hLibrary;
LHANDLE hMAPISession;
MapiMessage mmMapiMessage;
lpMapiMessage FAR *lppMessage;
lpMapiMessage lpMessage;
char szSeedMessageID[512];
char szMessageID[512];
char szSubject[512];
char szNoteText[4096];
LPSTR lpszSeedMessageID = &szSeedMessageID[0];
LPSTR lpszMessageID = &szMessageID[0];
LPSTR pszSubject = &szSubject[0];
LPSTR pszNoteText = &szNoteText[0];
LPSTR pszDateReceived = "1991/03/23 12:00";
MapiRecipDesc rdOriginator = { 0L,MAPI_ORIG,(LPSTR)"ONE",NULL};
int iFindFirst= TRUE;
/****************************************************************************
FUNCTION: OutOfMemory(void)
PURPOSE: Displays warning message
****************************************************************************/
void OutOfMemory(void)
{
MessageBox(
GetFocus(),
"Out of Memory",
NULL,
MB_ICONHAND | MB_SYSTEMMODAL);
return;
}
void mycpystr(char * npszStrg, LPSTR lpszStrg)
{
if (lpszStrg != NULL)
strcpy(npszStrg, lpszStrg);
else
*npszStrg = '\0';
}
/************************************************************************/
/* Main Program Body */
/************************************************************************/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
/***********************************************************************/
/* HANDLE hInstance; handle for this instance */
/* HANDLE hPrevInstance; handle for possible previous instances */
/* LPSTR lpszCmdLine; long pointer to exec command line */
/* int nCmdShow; Show code for main window display */
/***********************************************************************/
MSG msg; /* MSG structure to store your messages */
int nRc; /* return value from Register Classes */
long nWndunits; /* window units for size and location */
int nWndx; /* the x axis multiplier */
int nWndy; /* the y axis multiplier */
int nX; /* the resulting starting point (x, y) */
int nY;
int nWidth; /* the resulting width and height for this */
int nHeight; /* window */
strcpy(szAppName, "MAPIAPP");
hInst = hInstance;
if(!hPrevInstance)
{
/* register window classes if first instance of application */
if ((nRc = nCwRegisterClasses()) == -1)
{
/* registering one of the windows failed */
LoadString(hInst, IDS_ERR_REGISTER_CLASS, szString, sizeof(szString));
MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION);
return nRc;
}
}
/* Create a device independant size and location */
nWndunits = GetDialogBaseUnits();
nWndx = LOWORD(nWndunits);
nWndy = HIWORD(nWndunits);
nX = ((60 * nWndx) / 4);
nY = ((60 * nWndy) / 8);
nWidth = ((197 * nWndx) / 4);
nHeight = ((138 * nWndy) / 8);
/* create application's Main window */
hWndMain = CreateWindow(
szAppName, /* Window class name */
"MAPI Sample App", /* Window's title */
WS_CAPTION | /* Title and Min/Max */
WS_SYSMENU | /* Add system menu box */
WS_MINIMIZEBOX | /* Add minimize box */
WS_MAXIMIZEBOX | /* Add maximize box */
WS_BORDER | /* thin frame */
WS_CLIPCHILDREN | /* don't draw in child windows areas */
WS_OVERLAPPED,
nX, nY, /* X, Y */
nWidth, nHeight, /* Width, Height of window */
NULL, /* Parent window's handle */
NULL, /* Default to Class Menu */
hInst, /* Instance of window */
NULL); /* Create struct for WM_CREATE */
if (InitMAPI() != 0)
return ERR_LOAD_LIB;
if(hWndMain == NULL)
{
LoadString(hInst, IDS_ERR_CREATE_WINDOW, szString, sizeof(szString));
MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION);
return IDS_ERR_CREATE_WINDOW;
}
EnableMenuItem(GetMenu(hWndMain), IDM_A_LOGOFF, MF_DISABLED | MF_GRAYED);
ShowWindow(hWndMain, nCmdShow); /* display main window */
while(GetMessage(&msg, NULL, 0, 0)) /* Until WM_QUIT message */
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
DeInitMAPI();
/* Do clean up before exiting from the application */
CwUnRegisterClasses();
return msg.wParam;
} /* End of WinMain */
/************************************************************************/
/* */
/* Main Window Procedure */
/************************************************************************/
LONG FAR PASCAL WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
HMENU hMenu=0; /* handle for the menu */
HBITMAP hBitmap=0; /* handle for bitmaps */
HDC hDC; /* handle for the display device */
PAINTSTRUCT ps; /* holds PAINT information */
int nRc=0; /* return code */
FLAGS flFlag = 0L;
ULONG ulResult;
char szBuf[100];
MapiFileDesc sFiles;
lpMapiRecipDesc lpRecip = NULL;
switch (Message)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDM_A_LOGON:
/*********************************/
/* THIS IS THE SAMPLE MAPI CODE! */
/*********************************/
/* set flags to indicate we want a new mapi session and to prompt */
/* for the profile to use. */
flFlag =MAPI_NEW_SESSION | MAPI_LOGON_UI;
/* login to mapi to get a mapi session handle */
ulResult = (*lpfnMAPILogon)(hWnd, NULL, NULL, flFlag, 0L, (LPLHANDLE)&hMAPISession);
if (ulResult == 0L)
{
EnableMenuItem(GetMenu(hWndMain), IDM_A_LOGOFF, MF_ENABLED);
/* initialize the mapi message structure */
mmMapiMessage.ulReserved = 0;
mmMapiMessage.lpszSubject = "The subject";
mmMapiMessage.lpszNoteText = "The note text";
mmMapiMessage.lpszMessageType = NULL;
mmMapiMessage.lpszDateReceived = NULL;
mmMapiMessage.lpszConversationID = NULL;
mmMapiMessage.flFlags = 0;
mmMapiMessage.lpOriginator = NULL;
mmMapiMessage.nRecipCount = 0;
mmMapiMessage.lpRecips = NULL;
mmMapiMessage.nFileCount = 0;
mmMapiMessage.lpFiles = NULL;
/* Bring up the standard mapi address book dialog */
ulResult = (*lpfnMAPIAddress)(
(LHANDLE)hMAPISession,
0L,
NULL,
1L,
NULL,
0L,
NULL,
0L,
0L,
&mmMapiMessage.nRecipCount,
&mmMapiMessage.lpRecips );
if((ulResult == SUCCESS_SUCCESS) && (mmMapiMessage.lpRecips))
{
#if 0
/* If you want to add an attachment to the message, */
/* then use this code */
sFiles.ulReserved = 0;
sFiles.flFlags = 0;
sFiles.nPosition = 0xFFFFFFFF;
sFiles.lpszPathName = "c:\\filename.txt";
sFiles.lpszFileName = NULL;
sFiles.lpFileType = NULL;
mmMapiMessage.nFileCount = 1;
mmMapiMessage.lpFiles = &sFiles;
#endif
/* Okay, now send the message */
/* Use the MAPI_DIALOG flag if you want the registered Form Server */
/* to bring up a send screen. Otherwise, no UI will occur on this call */
ulResult = (*lpfnMAPISendMail)((LHANDLE)hMAPISession
,0L
,&mmMapiMessage
,0L /*MAPI_DIALOG | MAPI_LOGON_UI*/
,0L);
/* done with the memory allocated by the MAPIAddress call */
(*lpfnMAPIFreeBuffer)(mmMapiMessage.lpRecips);
if (ulResult != SUCCESS_SUCCESS)
{
sprintf(szBuf,"MAPISendmail failed. error= %d",ulResult);
MessageBox(hWnd,szBuf,"Message",MB_OK);
}
}
}
switch(ulResult)
{
case SUCCESS_SUCCESS:
sprintf(szBuf,"Success");
MessageBox(hWnd,szBuf,"Message",MB_OK);
ulResult = lpfnMAPIFreeBuffer((LPVOID)lpMessage);
break;
case MAPI_E_FAILURE:
sprintf(szBuf,"ReadMail : Email failure");
MessageBox(hWnd,szBuf,"Message",MB_OK);
break;
case MAPI_E_INSUFFICIENT_MEMORY:
sprintf(szBuf,"ReadMail :Insufficient memory");
MessageBox(hWnd,szBuf,"Message",MB_OK);
break;
case MAPI_E_INVALID_MESSAGE:
sprintf(szBuf,"ReadMail :Invalid message");
MessageBox(hWnd,szBuf,"Message",MB_OK);
break;
case MAPI_E_ATTACHMENT_WRITE_FAILURE:
sprintf(szBuf,"ReadMail :Attachment write failure");
MessageBox(hWnd,szBuf,"Message",MB_OK);
break;
case MAPI_E_NOT_SUPPORTED:
sprintf(szBuf,"ReadMail :Operation not supported");
MessageBox(hWnd,szBuf,"Message",MB_OK);
break;
}
break;
case IDM_A_LOGOFF:
/* logoff from the mapi session */
ulResult = (*lpfnMAPILogoff)(hMAPISession, hWnd, 0L, 0L);
if (ulResult == 0L) {
EnableMenuItem(GetMenu(hWndMain), IDM_A_LOGOFF, MF_DISABLED | MF_GRAYED);
EnableMenuItem(GetMenu(hWndMain), IDM_S_MAIL, MF_DISABLED | MF_GRAYED);
EnableMenuItem(GetMenu(hWndMain), IDM_S_DOCUMENT, MF_DISABLED | MF_GRAYED);
EnableMenuItem(GetMenu(hWndMain), IDM_M_FINDFIRST, MF_DISABLED | MF_GRAYED);
EnableMenuItem(GetMenu(hWndMain), IDM_M_FINDNEXT, MF_DISABLED | MF_GRAYED);
EnableMenuItem(GetMenu(hWndMain), IDM_M_READ, MF_DISABLED | MF_GRAYED);
EnableMenuItem(GetMenu(hWndMain), IDM_M_DELETE, MF_DISABLED | MF_GRAYED);
}
break;
default:
return DefWindowProc(hWnd, Message, wParam, lParam);
}
if (ulResult != 0L)
{
/** oops **/
sprintf(szBuf,"Error Returned = %lu",ulResult);
MessageBox(hWnd,szBuf,"FAILED",MB_OK);
}
else
{
sprintf(szBuf,"Good Job");
MessageBox(hWnd,szBuf,"SUCCESS",MB_OK);
}
break; /* End of WM_COMMAND */
case WM_PAINT: /* code for the window's client area */
memset(&ps, 0x00, sizeof(PAINTSTRUCT));
hDC = BeginPaint(hWnd, &ps);
/* Included in case the background is not a pure color */
SetBkMode(hDC, TRANSPARENT);
EndPaint(hWnd, &ps);
break; /* End of WM_PAINT */
case WM_CLOSE: /* close the window */
/* Destroy child windows, modeless dialogs, then, this window */
DestroyWindow(hWnd);
if (hWnd == hWndMain)
PostQuitMessage(0); /* Quit the application */
break;
default:
return DefWindowProc(hWnd, Message, wParam, lParam);
}
return 0L;
} /* End of WndProc */
/************************************************************************/
/* */
/* nCwRegisterClasses Function */
/************************************************************************/
int nCwRegisterClasses(void)
{
WNDCLASS wndclass; /* struct to define a window class */
memset(&wndclass, 0x00, sizeof(WNDCLASS));
/* load WNDCLASS with window's characteristics */
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW;
wndclass.lpfnWndProc = WndProc;
/* Extra storage for Class and Window objects */
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInst;
wndclass.hIcon = LoadIcon(hInst, "MAPIAPP");
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
/* Create brush for erasing background */
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wndclass.lpszMenuName = szAppName; /* Menu Name is App Name */
wndclass.lpszClassName = szAppName; /* Class Name is App Name */
if(!RegisterClass(&wndclass))
return -1;
return(0);
} /* End of nCwRegisterClasses */
/************************************************************************/
/* CwUnRegisterClasses Function */
/************************************************************************/
void CwUnRegisterClasses(void)
{
WNDCLASS wndclass; /* struct to define a window class */
memset(&wndclass, 0x00, sizeof(WNDCLASS));
UnregisterClass(szAppName, hInst);
} /* End of CwUnRegisterClasses */