Click here to Skip to main content
16,005,389 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: XOR logical operator Pin
Rohit  Sinha5-Mar-02 15:19
Rohit  Sinha5-Mar-02 15:19 
GeneralRe: XOR logical operator Pin
Tim Smith5-Mar-02 8:31
Tim Smith5-Mar-02 8:31 
GeneralAccessing the main dialog from other dialogs in a Dialog based App. Pin
Joan M5-Mar-02 5:14
professionalJoan M5-Mar-02 5:14 
GeneralRe: Accessing the main dialog from other dialogs in a Dialog based App. Pin
Mazdak5-Mar-02 5:28
Mazdak5-Mar-02 5:28 
GeneralRe: Accessing the main dialog from other dialogs in a Dialog based App. Pin
Joaquín M López Muñoz5-Mar-02 5:37
Joaquín M López Muñoz5-Mar-02 5:37 
Questionsend mail by using MFC? Pin
5-Mar-02 4:34
suss5-Mar-02 4:34 
AnswerRe: send mail by using MFC? Pin
Chris Losinger5-Mar-02 4:40
professionalChris Losinger5-Mar-02 4:40 
AnswerRe: send mail by using MFC? Pin
Roger Allen5-Mar-02 5:02
Roger Allen5-Mar-02 5:02 
All MFC apps have this built in (for sedning the active document), although it doesnt tend to work the way you want. For a quick test add a menu item with the id of ID_FILE_SEND_MAIL. The problems I found with the standard implementation is that if your document is modified then it gets saved as a temporary file (with a .tmp extension) and then sent attached to the e-mail at that point. I re-wrote the function based on the default CDocument::OnFileSendMail as follows. Its a bit tricky as it handles multiple attachments etc, but if you need to use it, it will get you going a lot quicker.

[edit]
If you want the example code, mail me, I removed it to keep the forum speed up
Alctuall, I tried to remove it several times. If its still here, its a forum bug
[/edit]

Roger Allen
Sonork 100.10016RemoveTemp = TRUE;
m_sending_as_attachment = FALSE ;
// restore the original filename
if (DatasetType == TYPE_DATASET)
{
pntr->m_Filename = old_filename ;
pntr->m_Path = old_path ;
}
else
{
mpntr->m_Filename = old_filename ;
mpntr->m_Path = old_path ;
}
SetPathName(old_path + "\\" + old_filename, FALSE) ;
}
else
{
// use actual file since it isn't modified
lstrcpyn(szTempName, m_strPathName, _countof(szTempName));
}
#ifdef _UNICODE
char szTempNameA[_MAX_PATH];
_wcstombsz(szTempNameA, szTempName, _countof(szTempNameA));
#endif

// build an appropriate title for the attachment
TCHAR szTitle[_MAX_PATH];
if (!m_strPathName.IsEmpty())
AfxGetFileName(m_strPathName, szTitle, _countof(szTitle));
else
{
lstrcpyn(szTitle, m_strTitle, _countof(szTitle));
if (m_strTitle.Find('.') == -1) // no extension
{
// append the default suffix if there is one
CString strExt;
CDocTemplate* pTemplate = GetDocTemplate();
if (pTemplate != NULL &&
pTemplate->GetDocString(strExt, CDocTemplate::filterExt))
{
lstrcat(szTitle, strExt);
}
}
}

#ifdef _UNICODE
char szTitleA[_MAX_PATH];
_wcstombsz(szTitleA, szTitle, _countof(szTitleA));
#endif

// prepare the file description (for the attachment)
MapiFileDesc *fileDesc;
int num_attachments = 1 ;
if (DatasetType == TYPE_DATASET)
{
// single atatchment
fileDesc = new MapiFileDesc ;
}
else
{
// MultiSets need to also attach each of th sets in the m_ultiSet
fileDesc = new MapiFileDesc[1 + mpntr->no_in_use] ;
num_attachments = 1 + mpntr->no_in_use ;;
}
memset(fileDesc, 0, sizeof(MapiFileDesc) * num_attachments);
fileDesc[0].nPosition = (ULONG)-1;
char szPathAM[MAX_DATASETS_PER_MULTI][_MAX_PATH];
char szTitleAM[MAX_DATASETS_PER_MULTI][_MAX_PATH];
#ifdef _UNICODE
fileDesc[0].lpszPathName = szTempNameA;
fileDesc[0].lpszFileName = szTitleA;
#else
fileDesc[0].lpszPathName = szTempName;
fileDesc[0].lpszFileName = szTitle;
#endif

// setup the multiset bits in the fileDesc structure
if (DatasetType == TYPE_MULTISET)
{
for (int i = 0 ; i < mpntr->no_in_use ; i++)
{
fileDesc[i + 1].nPosition = (ULONG)-1 ;
#ifdef _UNICODE
CString temp_string ;
temp_string = mpntr->pntr[i]->m_Path + "\\" + mpntr->pntr[i]->m_Filename ;
_wcstombsz(szPathAM[i], temp_string, _countof(temp_string));
_wcstombsz(szTitleAM[i], mpntr->pntr[i]->m_Filename, _countof(mpntr->pntr[i]->m_Filename));
fileDesc[i + 1].lpszPathName = szPathAM[i] ;
fileDesc[i + 1].lpszFileName = szTitleAM[i] ;
#else
sprintf(szPathAM[i], "%s\\%s", mpntr->pntr[i]->m_Path, mpntr->pntr[i]->m_Filename) ;
sprintf(szTitleAM[i], "%s", mpntr->pntr[i]->m_Filename) ;
fileDesc[i + 1].lpszPathName = szPathAM[i] ;
fileDesc[i + 1].lpszFileName =szTitleAM[i] ;
#endif
}
}

// prepare the message (empty with 1 attachment)
MapiMessage message;
memset(&message, 0, sizeof(message));
message.nFileCount = num_attachments;
message.lpFiles = fileDesc;

// prepare for modal dialog box
AfxGetApp()->EnableModeless(FALSE);
HWND hWndTop;
CWnd* pParentWnd = CWnd::GetSafeOwner(NULL, &hWndTop);

// some extra precautions are required to use MAPISendMail as it
// tends to enable the parent window in between dialogs (after
// the login dialog, but before the send note dialog).
pParentWnd->SetCapture();
::SetFocus(NULL);
pParentWnd->m_nFlags |= WF_STAYDISABLED;

int nError = lpfnSendMail(0, (ULONG)pParentWnd->GetSafeHwnd(),
&message, MAPI_LOGON_UI|MAPI_DIALOG, 0);

// after returning from the MAPISendMail call, the window must
// be re-enabled and focus returned to the frame to undo the workaround
// done before the MAPI call.
::ReleaseCapture();
pParentWnd->m_nFlags &= ~WF_STAYDISABLED;

pParentWnd->EnableWindow(TRUE);
::SetActiveWindow(NULL);
pParentWnd->SetActiveWindow();
pParentWnd->SetFocus();
if (hWndTop != NULL)
::EnableWindow(hWndTop, TRUE);
AfxGetApp()->EnableModeless(TRUE);

if (nError != SUCCESS_SUCCESS &&
nError != MAPI_USER_ABORT && nError != MAPI_E_LOGIN_FAILURE)
{
AfxMessageBox(AFX_IDP_FAILED_MAPI_SEND);
}
delete []fileDesc ;

// remove temporary file, if temporary file was used
if (bRemoveTemp)
CFile::Remove(szTempName);

// TODO: Add your command handler code here
//CDocument::OnFileSendMail() ;
}



Roger Allen
Sonork 100.10016

If I'm not breathing, I'm either dead or holding my breath.
A fool jabbers, while a wise man listens. But is he so wise to listen to the fool?
AnswerRe: send mail by using MFC? Pin
56789012345-Mar-02 5:01
56789012345-Mar-02 5:01 
AnswerRe: send mail by using MFC? Pin
Mazdak5-Mar-02 5:06
Mazdak5-Mar-02 5:06 
AnswerRe: send mail by using MFC? Pin
Jonathan Craig5-Mar-02 5:29
Jonathan Craig5-Mar-02 5:29 
Generalconvert char to int Pin
tbbooher5-Mar-02 4:33
tbbooher5-Mar-02 4:33 
GeneralRe: convert char to int Pin
56789012345-Mar-02 5:03
56789012345-Mar-02 5:03 
GeneralRe: convert char to int Pin
Ravi Bhavnani5-Mar-02 5:20
professionalRavi Bhavnani5-Mar-02 5:20 
GeneralRe: convert char to int Pin
Jamie Hale5-Mar-02 5:21
Jamie Hale5-Mar-02 5:21 
GeneralRe: convert char to int Pin
Jamie Hale5-Mar-02 5:21
Jamie Hale5-Mar-02 5:21 
GeneralSetting the fonts of all controls on a CFormView Pin
Mark Donkers5-Mar-02 4:28
Mark Donkers5-Mar-02 4:28 
GeneralRe: Setting the fonts of all controls on a CFormView Pin
Mazdak5-Mar-02 4:34
Mazdak5-Mar-02 4:34 
GeneralRe: Setting the fonts of all controls on a CFormView Pin
Mark Donkers5-Mar-02 4:47
Mark Donkers5-Mar-02 4:47 
GeneralAnchor property Pin
Mazdak5-Mar-02 3:28
Mazdak5-Mar-02 3:28 
GeneralRe: Anchor property Pin
Joaquín M López Muñoz5-Mar-02 3:29
Joaquín M López Muñoz5-Mar-02 3:29 
GeneralRe: Anchor property Pin
Mazdak5-Mar-02 4:10
Mazdak5-Mar-02 4:10 
GeneralRe: Anchor property Pin
Paolo Messina5-Mar-02 11:36
professionalPaolo Messina5-Mar-02 11:36 
GeneralRe: Anchor property Pin
Mazdak6-Mar-02 0:28
Mazdak6-Mar-02 0:28 
Questionhow to determine current authentication? Pin
AJ Weber5-Mar-02 2:39
AJ Weber5-Mar-02 2:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.