2009-12-22 66 views
3

我是程序員新手,我必須創建Outlook 2007加載項。我應該在功能區或任務欄上創建一個按鈕,但在收件箱中的單個郵件的窗口上創建一個按鈕。您知道,當您雙擊收件箱中的郵件時,會出現新窗口。在那個窗口中,我需要一個按鈕,用一些樹視圖打開一個新窗體。對我來說主要問題是如何創建該按鈕。這對我來說都是新的,所以我會非常感謝幫助。如何在Outlook窗口中爲收件箱中的郵件創建按鈕(雙擊郵件)?

+0

「Outlook收件箱中的郵件的Outlook窗口(雙擊郵件)」在Outlook中被稱爲「Inspector」。使用該術語時應該更容易找到好的信息。 – 2009-12-23 08:40:47

回答

4

好吧,我已經做了一些研究,下面的代碼有點工作:)但我會很感激,如果有經驗的人可以看到這一點,並告訴我是否可以,以及如何改變它。這只是更大項目的開始。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Xml.Linq; 
using Outlook = Microsoft.Office.Interop.Outlook; 
using Office = Microsoft.Office.Core; 
using System.Windows.Forms; 

namespace OutlookAddInMishko 
{ 
    public partial class ThisAddIn 
    { 
     private void ThisAddIn_Startup(object sender, System.EventArgs e) 
     { 

      Inspectors = this.Application.Inspectors; 
      Inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector); 
     } 

     private void ThisAddIn_Shutdown(object sender, System.EventArgs e) 
     { 
     } 

     #region VSTO generated code 


     private void InternalStartup() 
     { 
      this.Startup += new System.EventHandler(ThisAddIn_Startup); 
      this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); 
     } 

     #endregion 


      private Office.CommandBarButton buttonOne; 

     private Outlook.Inspectors Inspectors; 
     public static Microsoft.Office.Interop.Outlook.Inspector InsMail; 

     void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector) 
     { 
      Outlook.MailItem tmpMailItem = (Outlook.MailItem)Inspector.CurrentItem; 

      if (Inspector.CurrentItem is Outlook.MailItem) 
      { 
       tmpMailItem = (Outlook.MailItem)Inspector.CurrentItem; 
       bool exists = false; 
       foreach (Office.CommandBar cmd in Inspector.CommandBars) 
       { 
        if (cmd.Name == "EAD") 
        { 
         //exists = true; 
         cmd.Delete(); 
        } 
       } 

       Office.CommandBar newMenuBar = Inspector.CommandBars.Add("EAD", Office.MsoBarPosition.msoBarTop, false, true); 
       buttonOne = (Office.CommandBarButton)newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, 1, missing, missing, true); 

       if (!exists) 
       { 
        buttonOne.Caption = "Scan this mail"; 
        buttonOne.Style = Office.MsoButtonStyle.msoButtonCaption; 
        buttonOne.FaceId = 1983; 

        //Register send event handler 
        buttonOne.Click += new Office._CommandBarButtonEvents_ClickEventHandler(buttonOne_Click); 
        newMenuBar.Visible = true; 
       } 
      } 


     } 


     private void buttonOne_Click(Office.CommandBarButton ctrl, ref bool cancel) 
     { 
      ProcessMessages(); 
     } 

     private Form1 form1 = null; 

     private void ProcessMessages() 
     { 
      if (form1 == null) 
      { 
       form1 = new Form1(this.Application); 
      } 
      form1.ShowDialog(); 
     } 


    } 
} 


namespace OutlookAddInMishko 
{ 
    public partial class Form1 : Form 
    { 
     protected Outlook.Application App; 
     public Form1() 
     { 
      InitializeComponent(); 
     } 
     public Form1(Outlook.Application _app) 
     { 
      App = _app; 
      InitializeComponent(); 
     } 

     private void Form1_Shown(object sender, EventArgs e) 
     { 
      label1.Text = "Total number of mails in inbox: " + App.ActiveExplorer().CurrentFolder.Items.Count.ToString(); 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      Outlook.MailItem item = (Outlook.MailItem)App.ActiveInspector().CurrentItem; 
      textBox1.Text += "From: " + item.SenderName + "\r\n\n"; 
      textBox1.Text += "Subject: " + item.Subject + "\r\n\n"; 
      textBox1.Text += "Body: \r\n\n" + item.Body + "\r\n"; 
      textBox1.Text += "Mail contains: " + item.Attachments.Count + " attachment(s).\r\n\n"; 
     } 
    } 
} 
0

如果打開顯示窗體頂部的郵件消息的窗口,應該在功能區上有幾個按鈕(保存,撤消,重做等)。一直到右邊是一個倒三角形,上面有一條線,工具提示說:自定義快速訪問工具欄。點擊它,然後選擇「更多命令」。在該屏幕中選擇「自定義」選項卡。我認爲這是你添加一個按鈕來調出你的表單的地方。我沒有任何自定義表格,所以我無法驗證,希望這可以工作。

+0

好吧,但我已經在VS2008中創建了一些表單,它應該讀取郵件和附件的正文,並將其存儲在服務器上的某個位置。我能像你說過的那樣做嗎?我發現了一些代碼: http://blogs.devsource.com/msdev/content/visual_studio_2008/creating_add-ins_for_outlook_2007.html 但它創建的東西來自活動的資源管理器,而不是郵件窗口。任何幫助? – Cemsha 2009-12-22 17:35:16

相關問題