|
I think the better way is to use Doc/View architechture support,so if you use FormView then you can access it easily from every where.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
There's a myriad of ways to achieve that. For one, create a member variable m_pMainDlg in CMyApp of type CMyMainDialog * . Set this member appropriately in CMyApp::OnInitInstance . Now these two little helpers get you that pointer from anywhere:
CMyApp * GetMyApp()
{
return static_cast<CMyApp *>(AfxGetApp());
}
CMyMainDialog * CMyApp::GetMyMainDialog() const
{
return m_pMainDlg;
} To access the main dialog, use GetMyApp()->GetMyMainDialog() .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
dear all,
is any one know send a mail by using MFC programme?
thanks in advance..
|
|
|
|
|
did you try searching this site???
try searching for MAPI or SMTP
-c
Smaller Animals Software, Inc.
You're the icing - on the cake - on the table - at my wake. Modest Mouse
|
|
|
|
|
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?
|
|
|
|
|
Check out function CDocument::OnFileSendMail in MFC source code.
|
|
|
|
|
Check this
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Add the follow stuff and you can send the current document.
Add the following ON_COMMAND and ON_UPDATE_COMMAND_UI commands to the doc.cpp
BEGIN_MESSAGE_MAP(CReportDoc, CDocument)
ON_COMMAND(ID_FILE_SEND_MAIL, OnFileSendMail)
ON_UPDATE_COMMAND_UI(ID_FILE_SEND_MAIL, OnUpdateFileSendMail)
END_MESSAGE_MAP() Add this menu item to the File menu:
ID: ID_FILE_SEND_MAIL
Caption: Sen&d...
Prompt: Send the active document through electronic mail\nSend Mail
Run your application, open a document, and select Send from the File menu.
Hope this helps.
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
I know that atoi converts a string to an integer, but what about char to integer -- is there a function out that that does
intDay = atoi(strTime[1]);
correctly
(where strTime is of type std::string)
thanks,
tim
---------------------------------------
Tim Booher
|
|
|
|
|
|
int day = strTime[1] - (int) '0'; /ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Arrrrgh.
J
|
|
|
|
|
How about:
intDay = strTime[1] - '0';
J
|
|
|
|
|
Hello all,
Here's the deal I'm trying to set the font of all the controls on a CFormView to a larger font. I don't want to have to create an ID for each control and manually do a SetFont() on each. Is there an easier way to this?
Thanks.
Marcus
Make no little plans; they have no magic to stir your blood to action. Make big plans, aim high in work and hope
-- Daniel Burnham
|
|
|
|
|
Click on your form in your resources.then in the property of your form change the font then all your control have the same new font.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Thanks Mazy.
Marcus
Make no little plans; they have no magic to stir your blood to action. Make big plans, aim high in work and hope
-- Daniel Burnham
|
|
|
|
|
I have a form view and there are some controls,I need something like "Anchor" property.I mean when I change the size of forms my controls always have the same distance from left or right.
How can I gain this?
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
|
Thanks Joaquin
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
|
Thanks,I check it now
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Anyone have a code snippet that returns a string of the current NT Domain where the user authenticated? I know there's a utility in the NT/Win2K Resource Kit that returns something like:
MYDOMAIN\myuser
in the output...but I'm not sure where they're getting that info from (where "MYDOMAIN" is the name of the domain the user logged-in to, and "myuser" is the username that they used).
Also, if anyone knows how this translates when moving to AD, I'd appreciate any info.
Thanks in advance!
--AJ
|
|
|
|
|
GetUserName() return the user name
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
That's the easy part. Now how do you determine where the user authenticated? (i.e. local host, NT Domain, etc.)
I need the "context" of the user's authentication.
Thanks for the reply...good quote...
--AJ
PS: I see a "GetUserNameEx" for Win2K and later...it would do what I need (I think), but I need some kind of compat. with NT4 and probably Win98 as well.
|
|
|
|
|
The follwing KB articles may be helpful:
Q111544 HOWTO: Retrieve Current User and Domain Names on Windows NT
Q155698 HOWTO: Retrieve Current User and Domain Names on Windows 95 and Windows 98
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|