Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

NPP Sample: Demonstrates the Windows Messaging API (MAPI) 

Download sample

The NPP sample is a single-document interface (SDI) application similar to Notepad that allows you to edit text messages and send them to other users or other systems through the Windows messaging API, or MAPI.

If you are running Windows NT 4.0, make sure that MAPI is installed on your machine before running the sample.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

Building and Running the Sample

To build and run the NPP sample

  1. Open the solution NPP.sln.

  2. On the Build menu, click Build.

  3. On the Debug menu, click Start Without Debugging.

The File menu has a Send command that can attach the content of the edit window to a MAPI message. Selecting Send will prompt you for a user name and password to start your MAPI session if you are not already logged on.

The two important lines of code that enable this feature (aside from adding the menu choice itself to the resource file) are entries in the message map for the CNotepadDoc instance, which the application maintains. The entries are:

ON_COMMAND(ID_FILE_SEND_MAIL, OnFileSendMail)
ON_UPDATE_COMMAND_UI(ID_FILE_SEND_MAIL, OnUpdateFileSendMail)

CDocument::OnFileSendMail and CDocument::OnUpdateFileSendMail are built into MFC; nothing extra is needed to gain this level of MAPI support in your applications.

Keywords

This sample demonstrates the following keywords:

AfxGetMainWnd; AfxMessageBox; CComboBox::Copy; CComboBox::Create; CComboBox::GetDroppedState; CComboBox::Paste; CComboBox::SetEditSel; CComboBox::ShowDropDown; CDC::GetTextExtent; CDC::GetTextMetrics; CDC::SelectObject; CDialog::DoModal; CDialog::OnCancel; CDialog::OnInitDialog; CDocument::OnNewDocument; CEdit::GetLineCount; CEdit::LineFromChar; CEdit::LineIndex; CEdit::LineScroll; CEdit::SetSel; CEditView::GetEditCtrl; CEditView::GetSelectedText; CEditView::OnFindNext; CFrameWnd::Create; CFrameWnd::DockControlBar; CFrameWnd::EnableDocking; CFrameWnd::GetActiveView; CFrameWnd::RecalcLayout; CObject::AssertValid; CObject::Dump; CObject::Serialize; CRect::Height; CStatusBar::CommandToIndex; CStatusBar::SetPaneText; CString::Format; CString::GetLength; CString::LoadString; CToolBar::GetItemRect; CToolBar::SetButtonInfo; CView::GetDocument; CView::OnBeginPrinting; CView::OnDraw; CView::OnEndPrinting; CView::OnPreparePrinting; CWinApp::AddDocTemplate; CWinApp::InitInstance; CWinApp::LoadStdProfileSettings; CWinApp::OnFileNew; CWinApp::OnIdle; CWinApp::OpenDocumentFile; CWnd::Create; CWnd::DoDataExchange; CWnd::FromHandle; CWnd::GetDescendantWindow; CWnd::GetDlgItem; CWnd::GetFocus; CWnd::GetStyle; CWnd::GetWindowRect; CWnd::GetWindowText; CWnd::GetWindowTextLength; CWnd::KillTimer; CWnd::OnClose; CWnd::OnCreate; CWnd::PostMessage; CWnd::PreTranslateMessage; CWnd::ScreenToClient; CWnd::SendMessage; CWnd::SetFocus; CWnd::SetFont; CWnd::SetTimer; CWnd::SetWindowPos; CWnd::SetWindowText; CWnd::ShowWindow; CreateFontIndirect; DragAcceptFiles; EndDialog; EnumFontFamilies; GetDlgItem; GetKeyState; GetLocalTime; GetStockObject; LoadBitmap; MessageBeep; SendMessage; SetWindowText; memcpy

NoteNote

Some samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.

See Also

Other Resources

MFC Samples

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2015 Microsoft