Microsoft KB Archive/175044

From BetaArchive Wiki
Knowledge Base

How To Implement a MessageFilter in VFP Using Active Messaging

Article ID: 175044

Article Last Modified on 8/18/2005


  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft Visual FoxPro 3.0b Standard Edition
  • Microsoft Visual FoxPro 5.0 Standard Edition
  • Microsoft Visual FoxPro 5.0a
  • Microsoft Visual FoxPro 6.0 Professional Edition
  • Microsoft Messaging Application Programming Interface

This article was previously published under Q175044


Many FoxPro developers may not be aware that the Active Messaging library exists for them to use as an extremely robust alternative to canned MAPI controls. This article is designed as part of a short (non-interdependent) series intended to provide FoxPro developers with information, development tips, and useful snippets about the Microsoft Active Messaging Library.

This article provides an introductory overview of working with the Session's MessageFilter object by providing a short code snippet demonstrating how to implement a MessageFilter and setting a few of the filtering attributes available.

For additional information, on where to acquire the Active Messaging library, please see the following article in the Microsoft Knowledge Base:

171440 Where to Acquire the Collaboration Data Objects Library


Being a database developer, you are most likely aware of both the concept and benefits of applying filters to tables in order to process only a set of records that meet a certain criteria. The same concept applies equally well to Messages (for example: I want to see only unread messages, or only messages from a certain person, ...). The following code sample demonstrates how to implement this functionality in Visual FoxPro using the Active Messaging library:

   * AM_MessageFilter.PRG
   * --------------------
   *Create a MAPI Session object then Logon. The Logon dialog can be
   *bypassed by providing a valid ProfileName as the first parameter
   *(as a string) to the Logon Method as seen below.
   objSession = CREATEOBJECT("mapi.session")
   objSession.Logon    &&objSession.Logon("YourProfileName")

   *Instantiate a MessageFilter Object on the Inbox's Messages collection
   objMsgColl = objSession.Inbox.Messages
   objMsgFilter = objMsgColl.Filter

   *Setup the criteria for the MessageFilter
   objMsgFilter.Text = "test test"
   objMsgFilter.Unread = .T.  && Filter for unread messages

   *By default the two conditions noted above are logically ANDed, this
   *can be changed however to a logical OR instead by uncommenting the
   *next line
   *objMsgFilter.Or = .T.

   *Message filter is now specified; ready for display loop
   FOR EACH objMess IN objMsgColl && Operates only on messages post filter
      MESSAGEBOX("Message not read: " + objMess.Subject)

   *Clean up then bail
   RELEASE objMessage, objMsgFilter, objMsgColl, objSession

NOTE: If you intend to apply the MessageFilter for only a specific task then continue processing as normal with the full Messages Collection available, you MUST be careful and release both the MessageFilter and refresh the Messages Collection. While this sounds obvious enough when reading it in print, it is a common mistake when using MessageFilters.


Generic information on Active Messaging can be found on the MSDN, or in the Olemsg.hlp file, which can be found by following the directions in the Microsoft Knowledge Base Article 171440, referenced earlier in this article.

Additional query words: Active Messaging

Keywords: kbhowto kbmsg kbfaq kbcode KB175044