日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

WM中的OutLook开发和操作

發布時間:2023/12/4 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WM中的OutLook开发和操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

  昨天閑來無視,學習了一下WM的基本開發。看WM有約的那套教程心里癢癢,于是下載了SDK,看看DEMO,在Sample中的示例進行加工。小有一點心得。其實總的來說難度也不是很大,以前沒有做過FORM的程序,都是WEB上面的開發,上手來看不是那么特別的困難也。

  • 如果大家不明白安裝了SDK之后,如何簡歷新的項目,如何做調整屬性和模擬器的使用。可以參考我的文章下面的,講的非常的清楚。這里我就不過多的浪費時間做些重復的事情了。
  • 還是先看看效果好了,功能是比較簡單的。建立自己的OutLook聯系人,對其進行信息的發送和詳細信息的管理。
  • 以上是功能的初始界面。沒什么多說的。聯系人的管理。ADD功能可以跳轉到手機的電話簿進行添加。
  • 選中了聯系人之后。進行編輯。或者是新建聯系人界面也是如此的。OK保存,也就是Update。
  • ADD之后的界面。
  • Code
    using?System;
    using?System.Linq;
    using?System.Collections.Generic;
    using?System.ComponentModel;
    using?System.Data;
    using?System.Drawing;
    using?System.Text;
    using?System.Windows.Forms;
    using?Microsoft.WindowsMobile.PocketOutlook;
    using?Microsoft.WindowsMobile.Forms;
    using?Microsoft.WindowsMobile.PocketOutlook.MessageInterception;

    namespace?SmsDefence
    {
    ????
    public?partial?class?Form1?:?Form
    ????{
    ????????
    private?Contact?contactSelect;
    ????????
    private?OutlookSession?outLookSession;
    ????????
    public?Form1()
    ????????{
    ????????????
    this.outLookSession?=?new?OutlookSession();
    ????????????InitializeComponent();
    ????????????
    this.InitializeListBox();
    ????????}

    ????????
    public?Contact?Select()
    ????????{
    ????????????
    this.ShowDialog();
    ????????????
    return?this.contactSelect;
    ????????}
    ????????
    private?void?InitializeListBox()
    ????????{
    ????????????
    this.listBox1.DataSource?=?null;
    ????????????
    this.listBox1.DataSource?=?this.outLookSession.Contacts.Items;
    ????????????
    this.listBox1.DisplayMember?=?"FileAs";
    ????????????
    this.listBox1.ValueMember?=?"ItemId";
    ????????}
    ????????
    private?void?button1_Click(object?sender,?EventArgs?e)
    ????????{
    ????????????MessageBox.Show(
    "AlexLiu?Software?Development",?"Warning",?MessageBoxButtons.OK,
       MessageBoxIcon.Hand,?MessageBoxDefaultButton.Button1);
    ????????}

    ????????
    private?void?menuItem1_Click(object?sender,?EventArgs?e)
    ????????{
    ????????????CreateNewConversation();
    ????????}

    ????????
    private?void?menuItem2_Click(object?sender,?EventArgs?e)
    ????????{
    ????????????
    this.Close();
    ????????}

    ????????
    private?class?Conversation
    ????????{
    ????????????
    private?Contact?contact;
    ????????????
    private?string?transcript;
    ????????????
    private?string?phoneNumber;

    ????????????
    public?Conversation(Contact?c)
    ????????????{
    ????????????????contact?
    =?c;
    ????????????????phoneNumber?
    =?c.MobileTelephoneNumber;
    ????????????}

    ????????????
    public?Contact?Contact
    ????????????{
    ????????????????
    get?{?return?contact;?}
    ????????????}
    ????????????
    public?string?Transcript
    ????????????{
    ????????????????
    get?{?return?transcript;?}
    ????????????}
    ????????????
    public?void?AddToTranscript(string?sender,?string?msg)
    ????????????{
    ????????????????transcript?
    =?sender?+?":"?+?msg?+?"\r\n"?+?transcript;
    ????????????}
    ????????????
    public?string?PhoneNumber
    ????????????{
    ????????????????
    get?{?return?phoneNumber;?}
    ????????????}
    ????????????
    public?override?string?ToString()
    ????????????{
    ????????????????
    return?contact.ToString();
    ????????????}
    ????????}
    ????????
    private?void?CreateNewConversation()
    ????????{
    ????????????Conversation?currentConv?
    =?null;
    ????????????ChooseContactDialog?dlg?
    =?new?ChooseContactDialog();
    ????????????dlg.RequiredProperties?
    =?new?ContactProperty[]?{?ContactProperty.AllTextMessaging?};
    ????????????
    if?(dlg.ShowDialog()?==?DialogResult.OK)
    ????????????{
    ????????????????
    foreach?(Conversation?conv?in?listBox1.Items)
    ????????????????{
    ????????????????????
    if?(conv.Contact.ItemId?==?dlg.SelectedContact.ItemId)
    ????????????????????{
    ????????????????????????currentConv?
    =?conv;
    ????????????????????????
    break;
    ????????????????????}
    ????????????????}
    ????????????}
    ????????????
    if?(currentConv?==?null)
    ????????????{
    ????????????????currentConv?
    =?new?Conversation(dlg.SelectedContact);
    ????????????????listBox1.Items.Add(currentConv);
    ????????????}
    ????????????SwitchToConversation(currentConv);
    ????????}
    ????????
    private?void?SwitchToConversation(Conversation?conversion)
    ????????{
    ????????????listBox1.SelectedItem?
    =?conversion;
    ????????????txtMsg.Focus();
    ????????????
    ????????}

    ????????
    private?void?button5_Click(object?sender,?EventArgs?e)
    ????????{
    ????????????
    this.Close();
    ????????}

    ????????
    private?void?btnNew_Click(object?sender,?EventArgs?e)
    ????????{
    ????????????
    this.contactSelect?=?new?Contact();
    ????????????
    this.outLookSession.Contacts.Items.Add(contactSelect);
    ????????????ContactEdit?contactDialog?
    =?new?ContactEdit();
    ????????????contactDialog.Edit(
    ref?contactSelect);
    ????????????
    this.InitializeListBox();
    ????????}

    ????????
    private?void?btnEdit_Click(object?sender,?EventArgs?e)
    ????????{
    ????????????
    if?(this.listBox1.SelectedItem?!=?null)
    ????????????{
    ????????????????contactSelect?
    =?this.listBox1.SelectedItem?as?Contact;
    ????????????????ContactEdit?contactDialog?
    =?new?ContactEdit();
    ????????????????contactDialog.Edit(
    ref?contactSelect);
    ????????????}
    ????????????
    else?{?MessageBox.Show("you?must?select?one?contact");?}
    ????????}

    ????????
    private?void?btnSend_Click(object?sender,?EventArgs?e)
    ????????{
    ????????????
    try
    ????????????{
    ????????????????contactSelect?
    =?this.listBox1.SelectedItem?as?Contact;
    ????????????????
    if?(null?==?this.outLookSession.SmsAccount)
    ????????????????{
    ????????????????????
    throw?new?ArgumentException("this?account?is?not?i");
    ????????????????}
    ????????????????SmsMessage?s?
    =?new?SmsMessage(contactSelect.MobileTelephoneNumber,?this.txtMsg.Text);
    ????????????????s.Body?
    =?this.txtMsg.Text;
    ????????????????s.Send();
    ????????????????MessageBox.Show(
    "Message?Sent");
    ????????????}
    ????????????
    catch?(NullReferenceException?ex)
    ????????????{
    ????????????????MessageBox.Show(ex.ToString());
    ????????????}
    ????????}
    ????}
    }
  • 簡要說明下:首先是Send方法,如果聯系人的手機號碼,不為空的話就可以進行信息的發送了。如果不為空,SDK中為我們提供了一個SmsMessage也是就是短信的發送類。新建一個對象s,初始化要指定發送的信息的內容的收件人的手機號碼。s的body屬性也就是信息體,是要發送的內容。對象的實例s調用Send()方法即可發送了。在Mobile中常用的也是對話框的彈出了。MessageBox.Show方法有幾個重載的使用,其中最簡單的就是指定彈出對話框所要顯示的內容了。新建和編輯函數中的內容大體上面來說也是差不多的,新建的話就是把選中的聯系人加入到OutLookSession聯系中去。CreateNewConversation()函數,也就是點擊ADD之后觸發這個函數了,把聯系人中的不重復加入進來。ChooseContactDialog這個類,建立一個對象之后,通過對象調用了ShowDialog方法即可進入到手機電話簿中聯系人的選取中去。
  • Code
    using?System;
    using?System.Linq;
    using?System.Collections.Generic;
    using?System.ComponentModel;
    using?System.Data;
    using?System.Drawing;
    using?System.Text;
    using?System.Windows.Forms;
    using?Microsoft.WindowsMobile.Forms;
    using?Microsoft.WindowsMobile.PocketOutlook;

    namespace?SmsDefence
    {
    ????
    public?partial?class?ContactEdit?:?Form
    ????{
    ????????
    private?Contact?contactCreate;
    ????????
    public?ContactEdit()
    ????????{
    ????????????InitializeComponent();
    ????????}

    ????????
    private?void?menuItem2_Click(object?sender,?EventArgs?e)
    ????????{
    ????????????
    this.Close();
    ????????}

    ????????
    private?void?menuItem1_Click(object?sender,?EventArgs?e)
    ????????{
    ????????????
    this.Close();
    ????????}

    ????????
    public?void?Edit(ref?Contact?contact)
    ????????{
    ????????????contactCreate?
    =?contact;
    ????????????
    this.ShowDialog();
    ????????}

    ????????
    private?void?ContactEdit_Load(object?sender,?EventArgs?e)
    ????????{
    ????????????
    this.txtFirstName.DataBindings.Add("text",?this.contactCreate,?"FirstName");
    ????????????
    this.txtLastName.DataBindings.Add("text",?this.contactCreate,?"LastName");
    ????????????
    this.txtCompany.DataBindings.Add("text",?this.contactCreate,?"CompanyName");
    ????????????
    this.txtEmail.DataBindings.Add("text",?this.contactCreate,?"Email1Address");
    ????????????
    this.txtWorkPhone.DataBindings.Add("text",?this.contactCreate,?"BusinessTelephoneNumber");
    ????????????
    this.txtMobile.DataBindings.Add("text",?this.contactCreate,?"MobileTelephoneNumber");
    ????????}

    ????????
    private?void?btnOK_Click(object?sender,?EventArgs?e)
    ????????{
    ????????????
    this.contactCreate.FileAs?=?this.contactCreate.LastName?+?","?+?this.contactCreate.FirstName;
    ????????????
    this.contactCreate.Update();
    ????????????
    this.Close();
    ????????}
    ????}
    }
  • 以上的代碼是另一個FORM的內容。其主要功能就是對聯系人進行編輯或者是新建:當點擊OK的時候觸發的也就是BTNOK這個onclick時間了,重要的一個方法就是Update()對所做的操作進行更新。Close()我想不必說了。FORM的關閉。Edit方法中無非就是數據的綁定。
  • 參考文章 WM有約:http://www.cnblogs.com/allenlooplee/archive/2009/01/14/1375941.html?CommentID=1440147#Post

總結

以上是生活随笔為你收集整理的WM中的OutLook开发和操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。