Fixed topmost new email alert (hopefully)

This commit is contained in:
gamosoft_cp 2014-10-23 16:44:12 +00:00
parent 3d3e97dc4b
commit 2cf3f6fd93
3 changed files with 20 additions and 42 deletions

View File

@ -100,7 +100,7 @@
this.lnkSender.AutoSize = true;
this.lnkSender.Location = new System.Drawing.Point(85, 5);
this.lnkSender.Name = "lnkSender";
this.lnkSender.Size = new System.Drawing.Size(82, 17);
this.lnkSender.Size = new System.Drawing.Size(72, 17);
this.lnkSender.TabIndex = 10;
this.lnkSender.TabStop = true;
this.lnkSender.Text = "linkLabel1";
@ -137,7 +137,6 @@
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "NewMailAlert";
this.TopMost = true;
this.ResumeLayout(false);
this.PerformLayout();

View File

@ -12,7 +12,7 @@ using System.Windows.Forms;
namespace Outlook2013TodoAddIn.Forms
{
/// <summary>
/// New form to display new emai lnotifications
/// New form to display new email notifications
/// </summary>
public partial class NewMailAlert : Form
{
@ -29,14 +29,9 @@ namespace Outlook2013TodoAddIn.Forms
private bool mouseIsOver = false;
/// <summary>
/// Show form
/// Topmost value
/// </summary>
private const int SW_SHOW = 5;
/// <summary>
/// Fading effect
/// </summary>
private const uint AW_BLEND = 0x00080000;
private const int WS_EX_TOPMOST = 0x00000008;
#endregion "Variables"
@ -55,6 +50,21 @@ namespace Outlook2013TodoAddIn.Forms
get { return true; }
}
/// <summary>
/// This is used so we can show without activation and be the TopMost form
/// The TopMost property of the form MUST be set to false for this to work
/// https://connect.microsoft.com/VisualStudio/feedback/details/401311/showwithoutactivation-is-not-supported-with-topmost
/// </summary>
protected override CreateParams CreateParams
{
get
{
CreateParams value = base.CreateParams;
value.ExStyle |= WS_EX_TOPMOST;
return value;
}
}
#endregion "Properties"
#region "Methods"
@ -79,37 +89,6 @@ namespace Outlook2013TodoAddIn.Forms
timer.Start();
}
/// <summary>
/// Load and bring to fron
/// </summary>
/// <param name="e">EventArgs</param>
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (this.WindowState == FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Normal;
}
this.BringToFront();
}
[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);
/// <summary>
/// Method to display the form and make it topmost
/// </summary>
/// <returns>True or false</returns>
public bool ShowPopup()
{
bool result = ShowWindow(this.Handle, SW_SHOW);
//bool result = AnimateWindow(this.Handle, 200, AW_BLEND);
return result;
}
/// <summary>
/// Button delete clicked
/// </summary>

View File

@ -83,7 +83,7 @@ namespace Outlook2013TodoAddIn
NewMailAlert nm = new NewMailAlert(newMail, Properties.Settings.Default.DisplayTimeOut);
// Show the popup without stealing focus
SoundHelper.sndPlaySoundW(SoundHelper.MailBeep, SoundHelper.SND_NODEFAULT);
nm.ShowPopup();
nm.Show();
}
}
}