disconnect on computer lock

git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@48 c66351dc-e62f-0410-b875-e3a5c0b9693f
This commit is contained in:
Evgeny Gryaznov 2008-03-27 21:30:36 +00:00
parent 24f73e4f7d
commit 8764348c51
7 changed files with 164 additions and 29 deletions

View File

@ -0,0 +1,98 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace webImTray {
/// <summary>
/// Base class for a form that wants to be notified of Windows
/// session lock / unlock events
/// </summary>
public abstract class LockNotificationForm : Form {
// from wtsapi32.h
private const int NotifyForThisSession = 0;
// from winuser.h
private const int SessionChangeMessage = 0x02B1;
private const int SessionLockParam = 0x7;
private const int SessionUnlockParam = 0x8;
[DllImport("wtsapi32.dll")]
private static extern bool WTSRegisterSessionNotification(IntPtr hWnd, int dwFlags);
[DllImport("wtsapi32.dll")]
private static extern bool WTSUnRegisterSessionNotification(IntPtr hWnd);
// flag to indicate if we've registered for notifications or not
private bool registered = false;
/// <summary>
/// Is this form receiving lock / unlock notifications
/// </summary>
protected bool ReceivingLockNotifications {
get { return registered; }
}
/// <summary>
/// Unregister for event notifications
/// </summary>
protected override void Dispose(bool disposing) {
if (registered) {
WTSUnRegisterSessionNotification(Handle);
registered = false;
}
base.Dispose(disposing);
return;
}
/// <summary>
/// Register for event notifications
/// </summary>
protected override void OnHandleCreated(EventArgs e) {
base.OnHandleCreated(e);
// WtsRegisterSessionNotification requires Windows XP or higher
bool haveXp = Environment.OSVersion.Platform == PlatformID.Win32NT &&
(Environment.OSVersion.Version.Major > 5 ||
(Environment.OSVersion.Version.Major == 5 &&
Environment.OSVersion.Version.Minor >= 1));
if (haveXp)
registered = WTSRegisterSessionNotification(Handle, NotifyForThisSession);
return;
}
/// <summary>
/// The windows session has been locked
/// </summary>
protected virtual void OnSessionLock() {
return;
}
/// <summary>
/// The windows session has been unlocked
/// </summary>
protected virtual void OnSessionUnlock() {
return;
}
/// <summary>
/// Process windows messages
/// </summary>
protected override void WndProc(ref Message m) {
// check for session change notifications
if (m.Msg == SessionChangeMessage) {
if (m.WParam.ToInt32() == SessionLockParam)
OnSessionLock();
else if (m.WParam.ToInt32() == SessionUnlockParam)
OnSessionUnlock();
}
base.WndProc(ref m);
return;
}
}
}

View File

@ -9,7 +9,7 @@ using System.Data;
namespace webImTray { namespace webImTray {
public partial class MainWindow : System.Windows.Forms.Form { public partial class MainWindow : LockNotificationForm {
public MainWindow() { public MainWindow() {
InitializeComponent(); InitializeComponent();
@ -46,6 +46,10 @@ namespace webImTray {
#endif #endif
} }
void navigateBlank() {
webBrowser1.Navigate("about:blank");
}
private void showWindow() { private void showWindow() {
this.Visible = true; this.Visible = true;
this.Activate(); this.Activate();
@ -146,5 +150,17 @@ namespace webImTray {
private void toolHideWindow_Click(object sender, EventArgs e) { private void toolHideWindow_Click(object sender, EventArgs e) {
hideWindow(); hideWindow();
} }
protected override void OnSessionLock() {
if (Options.DisconnectOnLock) {
navigateBlank();
}
}
protected override void OnSessionUnlock() {
if (Options.DisconnectOnLock) {
navigateThere();
}
}
} }
} }

View File

@ -127,10 +127,10 @@
<data name="optionsToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="optionsToolStripMenuItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAIVJREFUOE/dk0EO YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAASdAAA
gCAMBPlgv+l/DBcTH4O2WrLCFi56kaQJgXbYbUNKXy4RKSz2bT3PF4vwfS3MOdO4oAOAF48hN4BJ1Jdn EnQB3mYfeAAAAIVJREFUOE/dk0EOgCAMBPlgv+l/DBcTH4O2WrLCFi56kaQJgXbYbUNKXy4RKSz2bT3P
kKpAE321RRHkYcEBmKxABnO12rhOgV9WOQ3Eodh1mwJawGK0hftubDNAqygEoAU2GWbBYD9REH0adv76 F4vwfS3MOdO4oAOAF48hN4BJ1JdnkKpAE321RRHkYcEBmKxABnO12rhOgV9WOQ3Eodh1mwJawGK0hftu
5z0AIQLwRor4ZGsAAAAASUVORK5CYII= bDNAqygEoAU2GWbBYD9REH0adv765z0AIQLwRor4ZGsAAAAASUVORK5CYII=
</value> </value>
</data> </data>
<data name="notifyIcon.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="notifyIcon.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
@ -167,38 +167,40 @@
<data name="toolNavigate.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="toolNavigate.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAY9JREFUOE9jYBh0 YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAASdAAA
wHTS1/+mEz7/N+n/8B/mOOOeN/+Ne17/N+59AxfD6nCzqb//m035+d908r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==
</value> </value>
</data> </data>
<data name="toolOptions.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="toolOptions.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAIVJREFUOE/dk0EO YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAASdAAA
gCAMBPlgv+l/DBcTH4O2WrLCFi56kaQJgXbYbUNKXy4RKSz2bT3PF4vwfS3MOdO4oAOAF48hN4BJ1Jdn EnQB3mYfeAAAAIVJREFUOE/dk0EOgCAMBPlgv+l/DBcTH4O2WrLCFi56kaQJgXbYbUNKXy4RKSz2bT3P
kKpAE321RRHkYcEBmKxABnO12rhOgV9WOQ3Eodh1mwJawGK0hftubDNAqygEoAU2GWbBYD9REH0adv76 F4vwfS3MOdO4oAOAF48hN4BJ1JdnkKpAE321RRHkYcEBmKxABnO12rhOgV9WOQ3Eodh1mwJawGK0hftu
5z0AIQLwRor4ZGsAAAAASUVORK5CYII= bDNAqygEoAU2GWbBYD9REH0adv765z0AIQLwRor4ZGsAAAAASUVORK5CYII=
</value> </value>
</data> </data>
<data name="toolHideWindow.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="toolHideWindow.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf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
3HV/wuNXK6i/9x5Hc6wawDlTXHbLJ+LZUBQPRyKwdQdxutwl1h+NLXHh5Ht1ewBHsiwawCW57HyDAfWR EbAQiYmw/8lnuCeWkVzcgnZlnw1j3HV/wuNXK6i/9x5Hc6wawDlTXHbLJ+LZUBQPRyKwdQdxutwl1h+N
dvl0uhZQ1eqX8aVc7EKLqrum651ATLf9OJx5XQM4KmY0xPzZ0hFAiQJnXB0WwME0E3IsL5B17ZlADqWb LXHh5Ht1ewBHsiwawCW57HyDAfWRdvl0uhZQ1eqX8aVc7EKLqrum651ATLf9OJx5XQM4KmY0xPzZ0hFA
NYDrOepdlcysmTWWOrxqbceRWtaLk0VO1XW72D5Vckd2gMBfq8zdpmUG62NJvKM4+XyziDk24xmfWoGE iQJnXB0WwME0E3IsL5B17ZlADqWbNYDrOepdlcysmTWWOrxqbceRWtaLk0VO1XW72D5Vckd2gMBfq8zd
s1c0gHPmbrPTpHNJKOCo2G1mZs20zcwUJ5yp1AB5+8/zEwgF5GMVDxh4AAAAAElFTkSuQmCC pmUG62NJvKM4+XyziDk24xmfWoGEs1c0gHPmbrPTpHNJKOCo2G1mZs20zcwUJ5yp1AB5+8/zEwgF5GMV
Dxh4AAAAAElFTkSuQmCC
</value> </value>
</data> </data>
<metadata name="reloadPageTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="reloadPageTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">

View File

@ -38,6 +38,15 @@ namespace webImTray {
} }
} }
public static bool DisconnectOnLock {
get {
return Application.UserAppDataRegistry.GetValue("disconnectonlock", "true").ToString().ToLower().Equals("true");
}
set {
Application.UserAppDataRegistry.SetValue("disconnectonlock", value.ToString());
}
}
public static bool ShowInTaskBar { public static bool ShowInTaskBar {
get { get {
return Application.UserAppDataRegistry.GetValue("showintaskbar", "false").ToString().ToLower().Equals("true"); return Application.UserAppDataRegistry.GetValue("showintaskbar", "false").ToString().ToLower().Equals("true");

View File

@ -144,7 +144,6 @@ namespace webImTray {
// autoDisconnect // autoDisconnect
// //
this.autoDisconnect.AutoSize = true; this.autoDisconnect.AutoSize = true;
this.autoDisconnect.Enabled = false;
this.autoDisconnect.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.autoDisconnect.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.autoDisconnect.Location = new System.Drawing.Point(23, 96); this.autoDisconnect.Location = new System.Drawing.Point(23, 96);
this.autoDisconnect.Margin = new System.Windows.Forms.Padding(4); this.autoDisconnect.Margin = new System.Windows.Forms.Padding(4);
@ -153,6 +152,7 @@ namespace webImTray {
this.autoDisconnect.TabIndex = 3; this.autoDisconnect.TabIndex = 3;
this.autoDisconnect.Text = "Become idle if the computer is locked"; this.autoDisconnect.Text = "Become idle if the computer is locked";
this.autoDisconnect.UseVisualStyleBackColor = true; this.autoDisconnect.UseVisualStyleBackColor = true;
this.autoDisconnect.CheckedChanged += new System.EventHandler(this.autoDisconnect_CheckedChanged);
// //
// groupBox2 // groupBox2
// //

View File

@ -17,6 +17,7 @@ namespace webImTray {
void OptionsPanel.apply() { void OptionsPanel.apply() {
if (modified) { if (modified) {
Options.WebIMServer = webimServer.Text; Options.WebIMServer = webimServer.Text;
Options.DisconnectOnLock = autoDisconnect.Checked;
if (forceRefresh.Checked) { if (forceRefresh.Checked) {
Options.ForceRefreshTime = forceRefreshTime.Value; Options.ForceRefreshTime = forceRefreshTime.Value;
} else { } else {
@ -27,6 +28,7 @@ namespace webImTray {
void OptionsPanel.initialize() { void OptionsPanel.initialize() {
webimServer.Text = Options.WebIMServer; webimServer.Text = Options.WebIMServer;
autoDisconnect.Checked = Options.DisconnectOnLock;
decimal refreshTime = Options.ForceRefreshTime; decimal refreshTime = Options.ForceRefreshTime;
forceRefreshTime.Enabled = forceRefresh.Checked = refreshTime != 0; forceRefreshTime.Enabled = forceRefresh.Checked = refreshTime != 0;
@ -60,5 +62,10 @@ namespace webImTray {
private void showUserPropertiesOnline(object sender, LinkLabelLinkClickedEventArgs e) { private void showUserPropertiesOnline(object sender, LinkLabelLinkClickedEventArgs e) {
System.Diagnostics.Process.Start(Options.WebIMServer + Options.SETTINGS_PAGE); System.Diagnostics.Process.Start(Options.WebIMServer + Options.SETTINGS_PAGE);
} }
private void autoDisconnect_CheckedChanged(object sender, EventArgs e) {
modified = true;
PanelModified.Invoke();
}
} }
} }

View File

@ -91,6 +91,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="App.ico" /> <Content Include="App.ico" />
<Compile Include="LockNotificationForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Options.cs" /> <Compile Include="Options.cs" />
<Compile Include="options\About.cs"> <Compile Include="options\About.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>