• How to: Display a Dialog Box for Selecting Entries from the Contacts Folder


    Outlook Developer Reference

    This topic describes how to use the SelectNamesDialog object to display entries from the Contacts folder in a dialog box that resembles the Select Names dialog box in the Outlook user interface.

    1. Look for the address list that corresponds with the Contacts folder.

      The SelectNamesDialog object displays entires in a dialog box based on an AddressList. To display entries in the Contacts folder, look for the AddressList that corresponds with the Contacts folder. Iterate through all the address lists defined for the current session, and for each address list, use AddressList.GetContactsFolder to match the corresponding folder with the Contacts folder.

    2. Initialize the dialog box with the address list of the Contacts folder.
    3. Use SelectNamesDialog.Display to display the dialog box. If SelectNamesDialog.Display returns True, then selected entries will be available in SelectNamesDialog.Recipients.
    Sub ShowContactsInDialog()
        Dim oDialog As SelectNamesDialog
        Dim oAL As AddressList
        Dim oContacts As Folder
        
        Set oDialog = Application.Session.GetSelectNamesDialog
        Set oContacts = _
            Application.Session.GetDefaultFolder(olFolderContacts)
    
        'Look for the address list that corresponds with the Contacts folder
        For Each oAL In Application.Session.AddressLists
            If oAL.GetContactsFolder = oContacts Then
                Exit For
            End If
        Next
        With oDialog
            'Initialize the dialog box with the address list representing the Contacts folder
            .InitialAddressList = oAL
            .ShowOnlyInitialAddressList = True
            If .Display Then
                'Recipients Resolved
                'Access Recipients using oDialog.Recipients
            End If
        End With
    End Sub

    See Also

    下面是用C#的例子

    //取得这个类的实例
    Outlook.SelectNamesDialog dialog = Application.Session.GetSelectNamesDialog();
    //是否允许多选
    dialog.AllowMultipleSelection = true;

    //取得联系人文件夹
    Outlook.Folder contractFolder = Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts) as Outlook.Folder;

    Outlook.AddressList oal=null;
    //取得地址列表
    foreach (Outlook.AddressList al in Application.Session.AddressLists)
    {
        if (al.GetContactsFolder() == contractFolder)
        {
            oal = al;
            break;
        }
    }

    //初始化
    dialog.InitialAddressList = oal;
    dialog.ShowOnlyInitialAddressList = true;

    //如果用户选择了某些收件人
    if (dialog.Display())
    {
        foreach (Outlook.Recipient rpt in dialog.Recipients)
        {
            //这里对选取的收件人列表做处理
            MessageBox.Show(rpt.AddressEntry.Name+","+rpt.AddressEntry.Address);  
        }
    }

  • 相关阅读:
    GPIO推挽输出和开漏输出详解
    Linux驱动中completion接口浅析(wait_for_complete例子,很好)【转】
    当JAVA集合移除自身集合元素时发生的诸多问题
    Machine Learning #Lab1# Linear Regression
    Nth to Last Node in List
    Codeforces Round #272 (Div. 2)AK报告
    iOS 使用Block实现函数回调
    ios上禁止输入表情
    POJ 1287:Networking(最小生成树Kruskal)
    CSS实现强制换行-------Day 78
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1217094.html
Copyright © 2020-2023  润新知