From e27556cc8ebf7a6213fc90afcfc4e4da72d7e33c Mon Sep 17 00:00:00 2001 From: gamosoft_cp Date: Mon, 1 Apr 2013 16:03:41 +0000 Subject: [PATCH] Initial check-in with email notification showing up for 5 seconds --- Outlook2013TodoAddIn.sln | 2 + Outlook2013TodoAddIn/AppointmentsControl.cs | 11 ++- Outlook2013TodoAddIn/NewMailAlert.Designer.cs | 72 +++++++------- Outlook2013TodoAddIn/NewMailAlert.cs | 97 ++++++++++++++++++- .../Outlook2013TodoAddIn.csproj | 8 +- Outlook2013TodoAddIn/ThisAddIn.cs | 16 +-- 6 files changed, 154 insertions(+), 52 deletions(-) diff --git a/Outlook2013TodoAddIn.sln b/Outlook2013TodoAddIn.sln index 2de37c0..0c4162d 100644 --- a/Outlook2013TodoAddIn.sln +++ b/Outlook2013TodoAddIn.sln @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Outlook2013TodoAddIn", "Outlook2013TodoAddIn\Outlook2013TodoAddIn.csproj", "{EF0CD4A2-56E1-4C98-BE40-ED2D969F16A8}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2FFBC2F9-1F58-40E6-8901-9853C61020E6}" +EndProject Global GlobalSection(TeamFoundationVersionControl) = preSolution SccNumberOfProjects = 2 diff --git a/Outlook2013TodoAddIn/AppointmentsControl.cs b/Outlook2013TodoAddIn/AppointmentsControl.cs index 1cbcf84..1d4f572 100644 --- a/Outlook2013TodoAddIn/AppointmentsControl.cs +++ b/Outlook2013TodoAddIn/AppointmentsControl.cs @@ -12,8 +12,7 @@ namespace Outlook2013TodoAddIn public partial class AppointmentsControl : UserControl { #region "Variables" - /// - + /// /// Used to retrieve the email address of a contact /// @@ -73,6 +72,14 @@ namespace Outlook2013TodoAddIn private void btnRefresh_Click(object sender, EventArgs e) { this.RetrieveAppointments(); + // Email alert tests + //string senderEmail = "pepe@hotmail.com"; + //string subject = "Subject of the email"; + //string body = "This is the body of the email"; + //NewMailAlert nm = new NewMailAlert(senderEmail, subject, body, 5000); + //nm.Email = null; + //// Show the popup without stealing focus + //nm.ShowPopup(); } /// diff --git a/Outlook2013TodoAddIn/NewMailAlert.Designer.cs b/Outlook2013TodoAddIn/NewMailAlert.Designer.cs index 9be16f2..a4f3c80 100644 --- a/Outlook2013TodoAddIn/NewMailAlert.Designer.cs +++ b/Outlook2013TodoAddIn/NewMailAlert.Designer.cs @@ -28,48 +28,29 @@ /// private void InitializeComponent() { - this.lblSender = new System.Windows.Forms.Label(); - this.lblSubject = new System.Windows.Forms.Label(); this.txtBody = new System.Windows.Forms.TextBox(); this.btnDelete = new System.Windows.Forms.Button(); this.btnFlag = new System.Windows.Forms.Button(); this.btnEnvelope = new System.Windows.Forms.Button(); this.btnClose = new System.Windows.Forms.Button(); + this.lnkSender = new System.Windows.Forms.LinkLabel(); + this.lnkSubject = new System.Windows.Forms.LinkLabel(); this.SuspendLayout(); // - // lblSender - // - this.lblSender.AutoSize = true; - this.lblSender.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lblSender.Location = new System.Drawing.Point(85, 11); - this.lblSender.Name = "lblSender"; - this.lblSender.Size = new System.Drawing.Size(52, 17); - this.lblSender.TabIndex = 0; - this.lblSender.Text = "label1"; - // - // lblSubject - // - this.lblSubject.AutoSize = true; - this.lblSubject.Location = new System.Drawing.Point(85, 28); - this.lblSubject.Name = "lblSubject"; - this.lblSubject.Size = new System.Drawing.Size(46, 17); - this.lblSubject.TabIndex = 1; - this.lblSubject.Text = "label1"; - // // txtBody // - this.txtBody.Location = new System.Drawing.Point(88, 49); + this.txtBody.Location = new System.Drawing.Point(88, 47); this.txtBody.Multiline = true; this.txtBody.Name = "txtBody"; this.txtBody.ReadOnly = true; - this.txtBody.Size = new System.Drawing.Size(214, 77); + this.txtBody.Size = new System.Drawing.Size(285, 51); this.txtBody.TabIndex = 2; // // btnDelete // this.btnDelete.BackgroundImage = global::Outlook2013TodoAddIn.Properties.Resources.Delete; this.btnDelete.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.btnDelete.Location = new System.Drawing.Point(50, 94); + this.btnDelete.Location = new System.Drawing.Point(50, 66); this.btnDelete.Name = "btnDelete"; this.btnDelete.Size = new System.Drawing.Size(32, 32); this.btnDelete.TabIndex = 6; @@ -80,7 +61,7 @@ // this.btnFlag.BackgroundImage = global::Outlook2013TodoAddIn.Properties.Resources.Flag; this.btnFlag.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.btnFlag.Location = new System.Drawing.Point(12, 94); + this.btnFlag.Location = new System.Drawing.Point(12, 66); this.btnFlag.Name = "btnFlag"; this.btnFlag.Size = new System.Drawing.Size(32, 32); this.btnFlag.TabIndex = 5; @@ -91,7 +72,7 @@ // this.btnEnvelope.BackgroundImage = global::Outlook2013TodoAddIn.Properties.Resources.Envelope; this.btnEnvelope.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.btnEnvelope.Location = new System.Drawing.Point(16, 17); + this.btnEnvelope.Location = new System.Drawing.Point(19, 5); this.btnEnvelope.Name = "btnEnvelope"; this.btnEnvelope.Size = new System.Drawing.Size(60, 60); this.btnEnvelope.TabIndex = 8; @@ -102,32 +83,57 @@ // this.btnClose.BackgroundImage = global::Outlook2013TodoAddIn.Properties.Resources.Delete; this.btnClose.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.btnClose.Location = new System.Drawing.Point(282, 8); + this.btnClose.Location = new System.Drawing.Point(353, 8); this.btnClose.Name = "btnClose"; this.btnClose.Size = new System.Drawing.Size(20, 20); this.btnClose.TabIndex = 9; this.btnClose.UseVisualStyleBackColor = true; this.btnClose.Click += new System.EventHandler(this.btnClose_Click); // + // lnkSender + // + this.lnkSender.AutoSize = true; + this.lnkSender.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lnkSender.Location = new System.Drawing.Point(85, 5); + this.lnkSender.Name = "lnkSender"; + this.lnkSender.Size = new System.Drawing.Size(82, 17); + this.lnkSender.TabIndex = 10; + this.lnkSender.TabStop = true; + this.lnkSender.Text = "linkLabel1"; + this.lnkSender.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkSender_LinkClicked); + // + // lnkSubject + // + this.lnkSubject.AutoSize = true; + this.lnkSubject.Location = new System.Drawing.Point(85, 27); + this.lnkSubject.Name = "lnkSubject"; + this.lnkSubject.Size = new System.Drawing.Size(72, 17); + this.lnkSubject.TabIndex = 11; + this.lnkSubject.TabStop = true; + this.lnkSubject.Text = "linkLabel2"; + this.lnkSubject.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkSubject_LinkClicked); + // // NewMailAlert // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(314, 140); + this.ClientSize = new System.Drawing.Size(385, 100); + this.Controls.Add(this.lnkSubject); + this.Controls.Add(this.lnkSender); this.Controls.Add(this.btnClose); this.Controls.Add(this.btnEnvelope); this.Controls.Add(this.btnDelete); this.Controls.Add(this.btnFlag); this.Controls.Add(this.txtBody); - this.Controls.Add(this.lblSubject); - this.Controls.Add(this.lblSender); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "NewMailAlert"; this.ShowIcon = false; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; this.Text = "NewMailAlert"; + this.TopMost = true; this.ResumeLayout(false); this.PerformLayout(); @@ -135,12 +141,12 @@ #endregion - private System.Windows.Forms.Label lblSender; - private System.Windows.Forms.Label lblSubject; private System.Windows.Forms.TextBox txtBody; private System.Windows.Forms.Button btnFlag; private System.Windows.Forms.Button btnDelete; private System.Windows.Forms.Button btnEnvelope; private System.Windows.Forms.Button btnClose; + private System.Windows.Forms.LinkLabel lnkSender; + private System.Windows.Forms.LinkLabel lnkSubject; } } \ No newline at end of file diff --git a/Outlook2013TodoAddIn/NewMailAlert.cs b/Outlook2013TodoAddIn/NewMailAlert.cs index e664393..88bd367 100644 --- a/Outlook2013TodoAddIn/NewMailAlert.cs +++ b/Outlook2013TodoAddIn/NewMailAlert.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -12,14 +13,45 @@ namespace Outlook2013TodoAddIn { public partial class NewMailAlert : Form { + private Timer timer; + private bool mouseIsOver = false; + public Microsoft.Office.Interop.Outlook.MailItem Email { get; set; } - public NewMailAlert(string sender, string subject, string body) + public NewMailAlert(string sender, string subject, string body, int interval) { InitializeComponent(); - this.lblSender.Text = sender; - this.lblSubject.Text = subject; + this.lnkSender.Text = sender; + this.lnkSubject.Text = subject; this.txtBody.Text = body; + this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width - 10; + this.Top = Screen.PrimaryScreen.WorkingArea.Height - this.Height - 10; + this.timer = new Timer(); + timer.Interval = interval; + timer.Tick += timer_Tick; + timer.Start(); + } + + [DllImport("user32.dll")] + private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); + + [DllImport("user32.dll")] + private static extern bool AnimateWindow(IntPtr hWnd, uint dwTime, uint dwFlags); + + private const int SW_SHOW = 5; + private const uint AW_BLEND = 0x00080000; + + public bool ShowPopup() + { + bool result = ShowWindow(this.Handle, SW_SHOW); + //bool result = AnimateWindow(this.Handle, 200, AW_BLEND); + this.BringToFront(); + return result; + } + + protected override bool ShowWithoutActivation + { + get { return true; } } private void btnDelete_Click(object sender, EventArgs e) @@ -38,13 +70,68 @@ namespace Outlook2013TodoAddIn private void btnEnvelope_Click(object sender, EventArgs e) { - this.Email.Display(); - this.Close(); + this.ShowEmail(); } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } + + private void ShowEmail() + { + this.Email.Display(); + this.Close(); + } + + private void lnkSender_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + this.ShowEmail(); + } + + private void lnkSubject_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + this.ShowEmail(); + } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + if (this.WindowState == FormWindowState.Minimized) + { + this.WindowState = FormWindowState.Normal; + } + this.Focus(); + this.BringToFront(); + } + + private void timer_Tick(object sender, EventArgs e) + { + if (!mouseIsOver) + { + timer.Stop(); + this.Close(); + } + } + + //protected override void OnMouseEnter(EventArgs ea) + //{ + // base.OnMouseEnter(ea); + // Point clientPos = PointToClient(Cursor.Position); + // if (!ClientRectangle.Contains(clientPos)) + // { + // mouseIsOver = true; + // } + //} + + //protected override void OnMouseLeave(EventArgs ea) + //{ + // base.OnMouseLeave(ea); + // Point clientPos = PointToClient(Cursor.Position); + // if (!ClientRectangle.Contains(clientPos)) + // { + // mouseIsOver = false; + // } + //} } } \ No newline at end of file diff --git a/Outlook2013TodoAddIn/Outlook2013TodoAddIn.csproj b/Outlook2013TodoAddIn/Outlook2013TodoAddIn.csproj index bf4795d..e76fcc7 100644 --- a/Outlook2013TodoAddIn/Outlook2013TodoAddIn.csproj +++ b/Outlook2013TodoAddIn/Outlook2013TodoAddIn.csproj @@ -45,6 +45,10 @@ Outlook2013TodoAddIn 3 + %24/outlook2013addin/Outlook2013TodoAddIn + . + https://tfs.codeplex.com/tfs/tfs04 + {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} @@ -178,7 +182,9 @@ can be found. --> - + + Component + Form diff --git a/Outlook2013TodoAddIn/ThisAddIn.cs b/Outlook2013TodoAddIn/ThisAddIn.cs index b123443..7568d3e 100644 --- a/Outlook2013TodoAddIn/ThisAddIn.cs +++ b/Outlook2013TodoAddIn/ThisAddIn.cs @@ -1,5 +1,6 @@ using Microsoft.Win32; using System; +using System.Drawing; using System.Linq; using System.Windows.Forms; using Office = Microsoft.Office.Core; @@ -62,18 +63,11 @@ namespace Outlook2013TodoAddIn string sender = newMail.Sender.Name; string subject = newMail.Subject; string body = newMail.Body; - NewMailAlert nm = new NewMailAlert(sender, subject, body); + NewMailAlert nm = new NewMailAlert(sender, subject, body, 5000); nm.Email = newMail; - nm.Top = 0; - nm.Left = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - nm.Width; - // this.Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height; - nm.Show(); - if (nm.WindowState == FormWindowState.Minimized) - { - nm.WindowState = FormWindowState.Normal; - } - nm.Focus(); - nm.BringToFront(); + // nm.Show(); + // Show the popup without stealing focus + nm.ShowPopup(); } }