December 20, 2014
Hot Topics:

Windows Mobile Development with MFC

  • December 10, 2007
  • By Nick Wienholt
  • Send Email »
  • More Articles »

For the sample application, two controls are required—a date picker to allow the user to select the date for which Outlook information will be retrieved, and a button to begin the search. Once the results have been retrieved, a message box to show the total number of appointments on the nominated day will be displayed.

The actual code to retrieve data from Pocket Outlook is relatively straightforward. The first task is to initialise COM and create the root Outlook COM object (error handling has been stripped for readability, but is present in the sample code that accompanies the article):

#include <initguid.h>
#include <pimstore.h>

//inside button click handler
CoInitializeEx(NULL, 0);
IPOutlookApp * polApp;
CoCreateInstance(CLSID_Application, NULL,
   CLSCTX_INPROC_SERVER, IID_IPOutlookApp, (LPVOID*)&polApp)
polApp->Logon(NULL);

Once Outlook has been logged in, the items in the calendar folder can be retrieved and searched:

IPOutlookItemCollection* pItems;
IFolder* pFolder;
polApp->GetDefaultFolder(olFolderCalendar, &pFolder);
pFolder->get_Items(&pItems);

IAppointment* pAppt;
CComBSTR query;
//populate query using date selected by user –- see sample for
//this code
//Sample query string:
//[Start] >=11/30/2007 00:00 AND [End] < 12/ 1/2007 00:00
pItems->Find(query, (IDispatch**)&pAppt);

The Find function is a general-purpose PIM querying tool, and works across all the different folder types such as Calendar, Contacts, and Tasks. If Find brings back any appointments for the selected date, the code simply loops through them and keeps a count of the total of minutes in appointments for display to the user:

long totalApptLength = 0;
long apptLength      = 0;

if (pAppt){
   pAppt->get_Duration(&apptLength);
   totalApptLength += apptLength;
   while(S_OK == pItems->FindNext((IDispatch**)&pAppt)){
      pAppt->get_Duration(&apptLength);
      totalApptLength += apptLength;
   }
}

Figure 2 shows the end form of the sample, with a Message Box displaying the total booked minutes for a particular day.

Figure 2: Final version of the sample running in PocketPC 2003 Emulator

Although displaying the total number of minutes booked for a particular day isn't overly useful, it is easy to imagine the sample application extended to a more graphical presentation that could display some type of heat-map of the busyness of a particular day or week within the calendar to allow end-users to identify when they are heavily booked.

Conclusion

The developer experience in C++ with Windows Mobile is excellent, and moving from the desktop to the mobile device doesn't involve giving up a heap of functionality. The debug experience for an application is excellent—hitting F5 launches the emulator, copies the application across, and starts the application ready to debug. All the normal debug features work—breakpoints, tracing, and variable inspection all work fine. As the sample application shows, the MFC features such as the WYSIWYG editor and DDX that make development much quicker compared to the tedious construction of Win32 GUI apps are all present. C++ has the added advantage over its managed contemporaries with the richness of the libraries available for mobile development. Although C# and VB.NET rely heavily on the .NET Framework libraries to provide the helper classes needed to build an application, C++ developers have the freedom to bring in header and source code files from any location and compile them as part of their application.

Next month, you'll round out the tour of Windows Mobile with a look at ATL and COM development in the embedded world.

Download the Code

You can download the code that accompanies this article here.

About the Author

Nick Wienholt is a Windows and .NET consultant based in Sydney, Australia. He has worked on a variety of IT projects over the last decade and continues to stay involved in the developer community. Nick is the co-founder and president of the Sydney Deep .NET User group, writes technical articles for Pinnacle Publishing and the Microsoft Developer Network, and is a participant in many .NET-related newsgroups. Nick's most recent book is Maximizing .NET Performance.





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel