July 31, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

How to Add Pocket Outlook Features to Your Mobile Application

  • July 13, 2005
  • By Alex Gusev
  • Send Email »
  • More Articles »

What can you gain from these definitions? Well, first of all, you can always receive a pointer to an Application object from any POOM object. The next useful features are the Sort, Find, and Restrict methods of the IPOutlookItemCollection interface. They all take either a pwszRestriction or pwszProperty parameter to define operation criteria. The value of this parameter is a boolean expression that can be evaluated as TRUE or FALSE for any item in the collection:

L"[OfficeLocation] = \"Pittsburgh, PA\""
L"[Department] = \"Sales\" AND [CompanyName] <> \"SomeCompany\""

Property names are enclosed by brackets. You can combine the comparison operators <, <=, >, >=, =, or <> with the logical AND and OR, as in the following sample:

void CTasksDlg::OnButtonFind()
{
   if (SUCCEEDED(m_pTaskFolder->get_Items(&m_pItemCol)))
   {
      ITaskPtr pTask;
      CComBSTR bstrText;

      HRESULT hr = m_pItemCol->Find(L"[StartDate] = \"7/4/05\"
              AND [DueDate] < \"7/6/05\"",(IDispatch**)&pTask);

      if ( S_OK == hr )
      {
         m_TasksList.ResetContent();
         hr = pTask->get_Subject(&bstrText);
         m_TasksList.AddString(bstrText);
      }
   }
}
void CTasksDlg::OnButtonFindNext()
{
   ITaskPtr pTask;
   HRESULT hr = m_pItemCol->FindNext((IDispatch**)&pTask);
   CComBSTR bstrText;

   if ( S_OK == hr && pTask != NULL )
   {
      m_TasksList.ResetContent();
      hr = pTask->get_Subject(&bstrText);
      m_TasksList.AddString(bstrText);
   }
   else
   {
      AfxMessageBox(L"No more items");
   }
}

This sample manipulates with Tasks, but you can apply the same rules for either Contacts or Appointments. What you have to pay attention to is that all find/restict conditions are applied only to non-empty properties; in other words, that that have some values. Empty fields are left out of scope.

Creating Pocket Outlook Items

After playing with collections and folders, you can move on and learn how to create and set up different POOM items. This is really a simple step: Just call IPOutlookApp::CreateItem with the appropriate item type. Its output parameter will keep an instance of the requested object:

hr = m_pPOOMApp->CreateItem(olAppointmentItem, (IDispatch**)&pAppt);
hr = m_pPOOMApp->CreateItem(olContactItem, (IDispatch**)&pContact);
hr = m_pPOOMApp->CreateItem(olTaskItem, (IDispatch**)&pTask);

Now, you have at least two different ways to set it up. First, your application may simply call the Display method:

void CPOOMDlg::OnButtonaddContact()
{
   IFolderPtr pFolder;

   if ( GetPOOMFolder(olFolderContacts, pFolder) )
   {
      IContactPtr pContact;
      HRESULT hr = 0;

      if ( SUCCEEDED(m_pPOOMApp->CreateItem(olContactItem,
                    (IDispatch**)&pContact)) )
      {
         hr = pContact->Display();
         if ( S_OK == hr )
            pContact->Save();
      }
   }
}

Another way to set up the newly created Task, Contact, or Appointment is to assign all desired values manually to its properties. The following sample illustrates it on Task and Appointment creation:

void CTasksDlg::OnButtonAddTask()
{
   static int nImportanceCnt = 0;

   int arrImportance[] = { olImportanceLow,
                           olImportanceNormal,
                           olImportanceHigh };

   ITaskPtr pTask;
   HRESULT hr = 0;

   if ( SUCCEEDED(m_pPOOMApp->CreateItem(olTaskItem,
                  (IDispatch**)&pTask)) )
   {
      hr = pTask->put_Subject(L"TEST TASK");
      hr = pTask->put_Importance(arrImportance[nImportanceCnt%3]);

      COleDateTime dtStart = COleDateTime::GetCurrentTime();
      hr = pTask->put_StartDate(dtStart);
      hr = pTask->put_DueDate(dtStart+COleDateTimeSpan(2,12,0,0));
      hr = pTask->put_ReminderSet(VARIANT_TRUE);
      hr = pTask->put_ReminderTime(dtStart+COleDateTimeSpan(1,6,0,0));
      hr = pTask->put_ReminderOptions(olSound);
      hr = pTask->put_Body(L"Here is a task body");
      hr = pTask->Save();

      pTask.Release();

      nImportanceCnt++;

      RefreshTasks();
   }
}
...

BOOL AddAppointment(IPOutlookAppPtr pApp,
                    CString& sSubject,
                    COleDateTime& dtStart,
                    CString& sBody)
{
   BOOL bRes = TRUE;

   IAppointmentPtr pAppointment;

   if ( FAILED(pApp->CreateItem(olAppointmentItem,
       (IDispatch**)&pAppointment)) )
      return FALSE;

   CComBSTR bstrSubject(sSubject);

   pAppointment->put_Subject(bstrSubject);
   pAppointment->put_Start(dtStart);
   pAppointment->put_End(dtStart + COleDateTimeSpan(0,2,0,0));
   pAppointment->put_ReminderSet(VARIANT_TRUE);

   long nMinutes = 60 * 24;

   pAppointment->put_ReminderMinutesBeforeStart(nMinutes);

   CComBSTR bstrBody(sBody);

   pAppointment->put_Body(bstrBody);
   pAppointment->Save();

   return bRes;
}

As you see, a programmer's life is relatively easy in this case. If you have set, for example, the Appointment parameters incorrectly, the Save method will return an error. Except for this, there is nothing to be confused about here. I'm leaving untouched all topics about adding, removing, and copying POOM items via their own methods or via collection objects due to its simplicity.

Beaming POOM Objects

Finally, I'll briefly overview sending or receiving POOM items through IR communications. With Pocket Outlook, it is quite an easy operation. Actually, you don't need to bother about any IR stuff; Pocket Outlook will do all 'black jobs' for you. Thus, you may call IPOutlookApp::ReceiveFromInfrared or IFolder::ReceiveFromInfrared to receive all or only a specific item type. IFolder::AddItemToInfraredFolder and IFolder::SendToInfrared beam marked items to the recipient:

void CTasksDlg::OnButtonBeamTask()
{
   int nSel = m_TasksList.GetCurSel();

   if ( nSel != LB_ERR )
   {
      IPOutlookItemCollectionPtr pItemCol;

      if (SUCCEEDED(m_pTaskFolder->get_Items(&pItemCol)))
      {
         ITaskPtr pTask;

         HRESULT hr = pItemCol->Item(nSel+1,(IDispatch**)&pTask);

         IFolderPtr pFolderIR;

         m_pPOOMApp->GetDefaultFolder (olFolderInfrared, &pFolderIR);

         pFolderIR->AddItemToInfraredFolder(olTaskItem,
                                            (IDispatch*)pTask);
      }
   }
}

void CTasksDlg::OnButtonBeamTasks()
{
   IPOutlookItemCollectionPtr pItemsFromIR;

   m_pTaskFolder->ReceiveFromInfrared(&pItemsFromIR);

   // do whatever you want with newly received tasks...

   ///...

   RefreshTasks();
}
...

void CPOOMDlg::OnButtonBeam()
{
   IFolderPtr pFolderIR;

   m_pPOOMApp->GetDefaultFolder (olFolderInfrared, &pFolderIR);

   pFolderIR->SendToInfrared();

}

void CPOOMDlg::OnButtonRecv()
{
   m_pPOOMApp->ReceiveFromInfrared();

}

These methods are supported only for the special olFolderInfrared folder type. Pocket Outlook uses standard Windows CE components for beaming and places all transmitted items to their default folders on its own; you don't need to worry about it at all.

Conclusion

In the current article, you have learned about the main features Pocket Outlook offers you as a developer. With the help of POOM, you now can implement sophisticated and customized mobile applications with rich functionality. The next article will talk about components that may be intergrated into the Pocket Outlook menu.

Download

Download the accompanying code's zip file here.

About the Author

Alex Gusev started to play with mainframes at the end of the 1980s, using Pascal and REXX, but soon switched to C/C++ and Java on different platforms. When mobile PDAs seriously rose their heads in the IT market, Alex did it too. Now, he works at an international retail software company as a team leader of the Mobile R department, making programmers' lives in the mobile jungles a little bit simpler.





Page 2 of 2



Comment and Contribute

 


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

 

 


Sitemap | Contact Us

Rocket Fuel