Share via


NPP Sample: Demonstrates the Windows Messaging API (MAPI)

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.

Security noteSecurity Note

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To get samples and instructions for installing them:

To access samples from Visual Studio

  • On the Help menu, click Samples.

    By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.

  • For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.

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 CNotepadDocinstance, 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

Note

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