private void adxOutlookEvents_ExplorerSelectionChange(object sender, object explorer) { int selectedItemClass = -1; Outlook._Explorer activeExplorer = explorer as Outlook._Explorer; if (activeExplorer != null) { try { Outlook.Selection selection = activeExplorer.Selection; if (selection != null) { try { if (selection.Count > 0) { object selectedItem = selection.Item(1); if (selectedItem != null) { try { selectedItemClass = Convert.ToInt32(selectedItem.GetType().InvokeMember("Class", BindingFlags.GetProperty, null, selectedItem, null)); } finally { Marshal.ReleaseComObject(selectedItem); } } } } finally { Marshal.ReleaseComObject(selection); } } } catch { } btnMessage.Enabled = (selectedItemClass == (int)Outlook.OlObjectClass.olMail); } }
private void DoGetInfo() { if (btnMode.State == AddinExpress.MSO.ADXMsoButtonState.adxMsoButtonDown) { securityManager1.DisableOOMWarnings = true; } try { Outlook._Explorer activeExplorer = OutlookApp.ActiveExplorer(); if (activeExplorer != null) { try { object selectedItem = null; Outlook.Selection selection = null; try { selection = activeExplorer.Selection; if (selection != null) { try { if (selection.Count > 0) { selectedItem = selection.Item(1); } } finally { Marshal.ReleaseComObject(selection); } } } catch { } if (selectedItem != null) { try { if (selectedItem is Outlook.MailItem) { Outlook.MailItem mail = selectedItem as Outlook.MailItem; MessageForm frmMessage = new MessageForm(); frmMessage.lbFrom.Text = mail.SenderName; frmMessage.lbSentOn.Text = mail.SentOn.ToString(); frmMessage.lbTo.Text = mail.To; frmMessage.lbCC.Text = mail.CC; frmMessage.lbSubject.Text = mail.Subject; frmMessage.tbMessage.Text = mail.Body; frmMessage.ShowDialog(); frmMessage.Dispose(); } } finally { Marshal.ReleaseComObject(selectedItem); } } } finally { Marshal.ReleaseComObject(activeExplorer); } } } finally { if (btnMode.State == AddinExpress.MSO.ADXMsoButtonState.adxMsoButtonDown) { securityManager1.DisableOOMWarnings = false; } } }