⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 windows mobile短信收件夹、发件夹数据读取.txt

📁 这段代码用于读取Windows Mobile系统手机上的短信收件夹、发件夹数据
💻 TXT
📖 第 1 页 / 共 2 页
字号:
        /// <param name="dt">DateTime submitted</param>
        /// <returns>true on success</returns>
        public bool GetSubmitTime(out DateTime dt)
        {
            int nYear, nMonth, nDay, nHour, nMinute, nSecond;
            bool bResult = MessageGetSubmitTime(pMessage, out nYear, out nMonth, out nDay, out nHour, out nMinute, out nSecond);
            dt = new DateTime(nYear, nMonth, nDay, nHour, nMinute, nSecond);
            return bResult;
        }

        /// <summary>
        /// Gets the submit time using the default format (MM/dd/yyyy hh:mm:ss tt)
        /// </summary>
        /// <param name="strSubmitTime">buffer to receive</param>
        /// <returns>true on success</returns>
        public bool GetSubmitTime(StringBuilder strSubmitTime)
        {
            return MessageGetSubmitTimeString(pMessage, strSubmitTime, strSubmitTime.Capacity, "");
        }

        /// <summary>
        /// Gets the submit time
        /// </summary>
        /// <param name="strSubmitTime">buffer to receive</param>
        /// <param name="strFormat">format string for date (empty for default)</param>
        /// <returns>true on success</returns>
        public bool GetSubmitTime(StringBuilder strSubmitTime, string strFormat)
        {
            return MessageGetSubmitTimeString(pMessage, strSubmitTime, strSubmitTime.Capacity, strFormat);
        }
        /// <summary>
        /// Get the recipients table, call this before calling GetNextRecipient
        /// </summary>
        /// <returns>true on success</returns>
        public bool GetRecipients()
        {
            return MessageGetRecipients(pMessage);
        }

        /// <summary>
        /// Gets the next recipient
        /// </summary>
        /// <param name="strName">Name of recipient</param>
        /// <param name="strEmail">Email of recipient</param>
        /// <param name="nType">RecipientType (TO, CC, BCC)</param>
        /// <returns>true on success</returns>
        public bool GetNextRecipient(StringBuilder strName, StringBuilder strEmail, out RecipientType nType)
        {
            int nRecipientType;
            nType = RecipientType.UNKNOWN;
            if (MessageGetNextRecipient(pMessage, strName, strName.Capacity, strEmail, strEmail.Capacity, out nRecipientType))
            {
                nType = (RecipientType)nRecipientType;
                return true;
            }
            return false;
        }
        [DllImport("ReadSMS.dll")]
        protected static extern void MessageClose(IntPtr pMessage);
        [DllImport("ReadSMS.dll")]
        protected static extern void MessageGetSenderName(IntPtr pMessage, StringBuilder strSenderName, int nMaxLength);

        [DllImport("ReadSMS.dll")]
        protected static extern void MessageGetSenderEmail(IntPtr pMessage, StringBuilder strSenderEmail, int nMaxLength);

        [DllImport("ReadSMS.dll")]
        protected static extern void MessageGetSubject(IntPtr pMessage, StringBuilder strSubject, int nMaxLength);

        [DllImport("ReadSMS.dll")]
        protected static extern bool MessageGetReceivedTime(IntPtr pMessage, out int nYear, out int nMonth, out int nDay, out int nHour, out int nMinute, out int nSecond);

        [DllImport("ReadSMS.dll")]
        protected static extern bool MessageGetReceivedTimeString(IntPtr pMessage, StringBuilder strReceivedTime, int nMaxLength, string szFormat);

        [DllImport("ReadSMS.dll")]
        protected static extern bool MessageGetSubmitTime(IntPtr pMessage, out int nYear, out int nMonth, out int nDay, out int nHour, out int nMinute, out int nSecond);

        [DllImport("ReadSMS.dll")]
        protected static extern bool MessageGetSubmitTimeString(IntPtr pMessage, StringBuilder strSubmitTime, int nMaxLength, string szFormat);

        [DllImport("ReadSMS.dll")]
        protected static extern bool MessageGetRecipients(IntPtr pMessage);

        [DllImport("ReadSMS.dll")]
        protected static extern bool MessageGetNextRecipient(IntPtr pMessage, StringBuilder strName, int nMaxLenName, StringBuilder strEmail, int nMaxLenEmail, out int nType);

    }


获取收件夹数据

        /// <summary>
        /// 读取收件夹用户数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonEX1_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                this.listViewEX1.Columns[0].Text = "发件人";
                if (!NetMAPI.MAPIInit())
                {
                    MessageBox.Show("打开发件夹失败", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                }
                else
                {
                    if (this.rDs == null)
                    {
                        rDs = new DataSet();
                        DataTable dt = new DataTable();
                        dt.Columns.Add("Num");
                        dt.Columns.Add("Content");
                        rDs.Tables.Add(dt);
                        NetMAPI tmapi = new NetMAPI();
                        if (tmapi.Login())
                        {
                            if ((tmapi.OpenMessageStore() && tmapi.OpenInbox()) && tmapi.GetContents())
                            {
                                SmsMessage message;
                                StringBuilder strSenderName = new StringBuilder(1024);
                                int num = 0;


                                while (tmapi.GetNextMessage(out message, false))
                                {
                                    DataRow dr = rDs.Tables[0].NewRow();

                                    num++;
                                    CF.Forms.ListViewItem it = new CF.Forms.ListViewItem();
                                    message.GetSenderName(strSenderName);
                                    dr["Num"] = strSenderName.ToString().Replace("+86", "");

                                    message.GetSubject(strSenderName);
                                    dr["Content"] = strSenderName.ToString();

                                    message.Dispose();
                                    this.rDs.Tables[0].Rows.Add(dr);
                                    if (num > 0xed)
                                    {
                                        break;
                                    }
                                }
                            }
                            tmapi.Logout();
                        }
                    }
                    NetMAPI.Term();
                   
                }
                //绑定数据集合
                this.listViewEX1.ListDataSet = rDs;
                this.listViewNavigateEX1.RowsTotalCount = rDs.Tables[0].Rows.Count; ;
                this.listViewNavigateEX1.ShowPageIndex();
            }
            catch (Exception ep)
            {
#if DEBUG
                MessageBox.Show(ep.Message);
#endif
                MessageBox.Show("读取收件夹短信数据时发生错误!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

获取已发送短信数据

private void buttonEX2_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                this.listViewEX1.Columns[0].Text = "收件人";

                if (this.sDs == null)
                {
                    sDs = new DataSet();
                    DataTable dt = new DataTable();
                    dt.Columns.Add("Num");
                    dt.Columns.Add("Content");
                    sDs.Tables.Add(dt);
                    if (NetMAPI.MAPIInit())
                    {
                        NetMAPI tmapi = new NetMAPI();
                        if (tmapi.Login())
                        {
                            if ((tmapi.OpenMessageStore() && tmapi.OpenSentItems()) && tmapi.GetContents())
                            {
                                SmsMessage message;
                                StringBuilder strSubject = new StringBuilder(1024);
                                StringBuilder strName = new StringBuilder(0x19);
                                StringBuilder strEmail = new StringBuilder(0x19);
                                int num = 0;
                                while (tmapi.GetNextMessage(out message, false))
                                {
                                    DataRow dr = sDs.Tables[0].NewRow();
                                    SmsMessage.RecipientType type;
                                    num++;
                                    CF.Forms.ListViewItem it = new CF.Forms.ListViewItem();
                                    message.GetRecipients();
                                    message.GetNextRecipient(strName, strEmail, out type);
                                     dr["Num"] = strName.ToString().Replace("+86", "");
                                    message.GetSubject(strSubject);
                                    dr["Content"] = strSubject.ToString();
                                    message.Dispose();
                                    this.sDs.Tables[0].Rows.Add(dr);
                                }
                            }
                            tmapi.Logout();
                        }
                    }
                    else
                    {
                        MessageBox.Show("读取发件夹短息数据失败!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                    }
                    NetMAPI.Term();
                }
                //绑定数据
                this.listViewEX1.ListDataSet = sDs;
                this.listViewNavigateEX1.RowsTotalCount = sDs.Tables[0].Rows.Count; ;
                this.listViewNavigateEX1.ShowPageIndex();
            }
            catch (Exception ep)
            {
#if DEBUG
                MessageBox.Show(ep.Message);
#endif
                MessageBox.Show("读取发件夹短信数据时发生错误!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

OK,到此为止,一切都搞定。

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -