First contrib.
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/App.config Sat Jun 14 12:51:25 2014 +0200
1.3 @@ -0,0 +1,6 @@
1.4 +<?xml version="1.0" encoding="utf-8" ?>
1.5 +<configuration>
1.6 + <startup>
1.7 + <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
1.8 + </startup>
1.9 +</configuration>
1.10 \ No newline at end of file
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/CbtHook.cs Sat Jun 14 12:51:25 2014 +0200
2.3 @@ -0,0 +1,171 @@
2.4 +//=============================================================================
2.5 +// COPYRIGHT: Prosoft-Lanz
2.6 +//=============================================================================
2.7 +//
2.8 +// $Workfile: CbtHook.cs $
2.9 +//
2.10 +// PROJECT : CodeProject Components
2.11 +// VERSION : 1.00
2.12 +// CREATION : 19.02.2003
2.13 +// AUTHOR : JCL
2.14 +//
2.15 +// DETAILS : This class implement the WH_CBT Windows hook mechanism.
2.16 +// From MSDN, Dino Esposito.
2.17 +// WindowCreate, WindowDestroy and WindowActivate user events.
2.18 +//
2.19 +//-----------------------------------------------------------------------------
2.20 +using System;
2.21 +using System.Text;
2.22 +using System.Runtime.InteropServices;
2.23 +
2.24 +namespace CodeProject.Win32API.Hook
2.25 +{
2.26 + ///////////////////////////////////////////////////////////////////////
2.27 + #region Enum CbtHookAction
2.28 +
2.29 + /// <summary>
2.30 + /// CBT hook actions.
2.31 + /// </summary>
2.32 + internal enum CbtHookAction : int
2.33 + {
2.34 + HCBT_MOVESIZE = 0,
2.35 + HCBT_MINMAX = 1,
2.36 + HCBT_QS = 2,
2.37 + HCBT_CREATEWND = 3,
2.38 + HCBT_DESTROYWND = 4,
2.39 + HCBT_ACTIVATE = 5,
2.40 + HCBT_CLICKSKIPPED = 6,
2.41 + HCBT_KEYSKIPPED = 7,
2.42 + HCBT_SYSCOMMAND = 8,
2.43 + HCBT_SETFOCUS = 9
2.44 + }
2.45 +
2.46 + #endregion
2.47 +
2.48 + ///////////////////////////////////////////////////////////////////////
2.49 + #region Class CbtEventArgs
2.50 +
2.51 + /// <summary>
2.52 + /// Class used for WH_CBT hook event arguments.
2.53 + /// </summary>
2.54 + public class CbtEventArgs : EventArgs
2.55 + {
2.56 + /// wParam parameter.
2.57 + public IntPtr wParam;
2.58 + /// lParam parameter.
2.59 + public IntPtr lParam;
2.60 + /// Window class name.
2.61 + public string className;
2.62 + /// True if it is a dialog window.
2.63 + public bool IsDialog;
2.64 +
2.65 + internal CbtEventArgs(IntPtr wParam, IntPtr lParam)
2.66 + {
2.67 + // cache the parameters
2.68 + this.wParam = wParam;
2.69 + this.lParam = lParam;
2.70 +
2.71 + // cache the window's class name
2.72 + StringBuilder sb = new StringBuilder();
2.73 + sb.Capacity = 256;
2.74 + USER32.GetClassName(wParam, sb, 256);
2.75 + className = sb.ToString();
2.76 + IsDialog = (className == "#32770");
2.77 + }
2.78 + }
2.79 +
2.80 + #endregion
2.81 +
2.82 + ///////////////////////////////////////////////////////////////////////
2.83 + #region Class CbtHook
2.84 +
2.85 + /// <summary>
2.86 + /// Class to expose the windows WH_CBT hook mechanism.
2.87 + /// </summary>
2.88 + public class CbtHook : WindowsHook
2.89 + {
2.90 + /// <summary>
2.91 + /// WH_CBT hook delegate method.
2.92 + /// </summary>
2.93 + public delegate void CbtEventHandler(object sender, CbtEventArgs e);
2.94 +
2.95 + /// <summary>
2.96 + /// WH_CBT create event.
2.97 + /// </summary>
2.98 + public event CbtEventHandler WindowCreate;
2.99 + /// <summary>
2.100 + /// WH_CBT destroy event.
2.101 + /// </summary>
2.102 + public event CbtEventHandler WindowDestroye;
2.103 + /// <summary>
2.104 + /// WH_CBT activate event.
2.105 + /// </summary>
2.106 + public event CbtEventHandler WindowActivate;
2.107 +
2.108 + /// <summary>
2.109 + /// Construct a WH_CBT hook.
2.110 + /// </summary>
2.111 + public CbtHook() : base(HookType.WH_CBT)
2.112 + {
2.113 + this.HookInvoke += new HookEventHandler(CbtHookInvoked);
2.114 + }
2.115 + /// <summary>
2.116 + /// Construct a WH_CBT hook giving a hook filter delegate method.
2.117 + /// </summary>
2.118 + /// <param name="func">Hook filter event.</param>
2.119 + public CbtHook(HookProc func) : base(HookType.WH_CBT, func)
2.120 + {
2.121 + this.HookInvoke += new HookEventHandler(CbtHookInvoked);
2.122 + }
2.123 +
2.124 + // handles the hook event
2.125 + private void CbtHookInvoked(object sender, HookEventArgs e)
2.126 + {
2.127 + // handle hook events (only a few of available actions)
2.128 + switch ((CbtHookAction)e.code)
2.129 + {
2.130 + case CbtHookAction.HCBT_CREATEWND:
2.131 + HandleCreateWndEvent(e.wParam, e.lParam);
2.132 + break;
2.133 + case CbtHookAction.HCBT_DESTROYWND:
2.134 + HandleDestroyWndEvent(e.wParam, e.lParam);
2.135 + break;
2.136 + case CbtHookAction.HCBT_ACTIVATE:
2.137 + HandleActivateEvent(e.wParam, e.lParam);
2.138 + break;
2.139 + }
2.140 + return;
2.141 + }
2.142 +
2.143 + // handle the CREATEWND hook event
2.144 + private void HandleCreateWndEvent(IntPtr wParam, IntPtr lParam)
2.145 + {
2.146 + if (WindowCreate != null)
2.147 + {
2.148 + CbtEventArgs e = new CbtEventArgs(wParam, lParam);
2.149 + WindowCreate(this, e);
2.150 + }
2.151 + }
2.152 +
2.153 + // handle the DESTROYWND hook event
2.154 + private void HandleDestroyWndEvent(IntPtr wParam, IntPtr lParam)
2.155 + {
2.156 + if (WindowDestroye != null)
2.157 + {
2.158 + CbtEventArgs e = new CbtEventArgs(wParam, lParam);
2.159 + WindowDestroye(this, e);
2.160 + }
2.161 + }
2.162 +
2.163 + // handle the ACTIVATE hook event
2.164 + private void HandleActivateEvent(IntPtr wParam, IntPtr lParam)
2.165 + {
2.166 + if (WindowActivate != null)
2.167 + {
2.168 + CbtEventArgs e = new CbtEventArgs(wParam, lParam);
2.169 + WindowActivate(this, e);
2.170 + }
2.171 + }
2.172 + }
2.173 + #endregion
2.174 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/DialogBox.cs Sat Jun 14 12:51:25 2014 +0200
3.3 @@ -0,0 +1,630 @@
3.4 +//=============================================================================
3.5 +// COPYRIGHT: Prosoft-Lanz
3.6 +//=============================================================================
3.7 +//
3.8 +// $Workfile: DialogBox.cs $
3.9 +//
3.10 +// PROJECT : CodeProject Components
3.11 +// VERSION : 1.00
3.12 +// CREATION : 19.02.2003
3.13 +// AUTHOR : JCL
3.14 +//
3.15 +// DETAILS : DialogBoxes centered into the parent owner.
3.16 +// This class implement the following objects:
3.17 +//
3.18 +// DlgBox.ShowDialog(...) for CommonDialog and Form
3.19 +// MsgBox.Show(...) for standard MessageBox
3.20 +// AppBox.Show(...) for standard MessageBox with ProductName as caption
3.21 +// ErrBox.Show(...) for standard error MessageBox
3.22 +//
3.23 +//-----------------------------------------------------------------------------
3.24 +using System;
3.25 +using System.Drawing;
3.26 +using System.Windows.Forms;
3.27 +using System.Runtime.InteropServices;
3.28 +using System.Diagnostics;
3.29 +
3.30 +using CodeProject.Win32API;
3.31 +using CodeProject.Win32API.Hook;
3.32 +
3.33 +namespace CodeProject.Dialog
3.34 +{
3.35 + ///////////////////////////////////////////////////////////////////////
3.36 + #region DlgBox
3.37 +
3.38 + /// <summary>
3.39 + /// Class to display a CommonDialog or modal Form centered on the owner.
3.40 + /// </summary>
3.41 + /// <example>
3.42 + /// This example display the default print dialog box in the center of the parent.
3.43 + /// <code>
3.44 + /// PrintDialog printDlg = new PrintDialog();
3.45 + /// if (DlgBox.ShowDialog(printDlg, parent) == DialogResult.OK)
3.46 + /// printDocument.Print();
3.47 + /// </code>
3.48 + /// </example>
3.49 + public sealed class DlgBox
3.50 + {
3.51 + private DlgBox() {} // To remove the constructor from the documentation!
3.52 +
3.53 + ///////////////////////////////////////////////////////////////////////
3.54 + // CommonDialog
3.55 +
3.56 + /// <summary>
3.57 + /// Show a command dialog box at the center of the active window.
3.58 + /// </summary>
3.59 + public static DialogResult ShowDialog(CommonDialog dlg)
3.60 + {
3.61 + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero);
3.62 + DialogResult dlgResult = dlg.ShowDialog();
3.63 + centerWindow.Dispose();
3.64 + return dlgResult;
3.65 + }
3.66 +
3.67 + /// <summary>
3.68 + /// Show a command dialog box at the center of the owner window.
3.69 + /// </summary>
3.70 + public static DialogResult ShowDialog(CommonDialog dlg, IWin32Window owner)
3.71 + {
3.72 + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle;
3.73 + CenterWindow centerWindow = new CenterWindow(handle);
3.74 + DialogResult dlgResult = dlg.ShowDialog();
3.75 + centerWindow.Dispose();
3.76 + return dlgResult;
3.77 + }
3.78 +
3.79 + ///////////////////////////////////////////////////////////////////////
3.80 + // Form
3.81 +
3.82 + /// <summary>
3.83 + /// Show a form dialog box at the center of the active window.
3.84 + /// </summary>
3.85 + public static DialogResult ShowDialog(Form form)
3.86 + {
3.87 + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero);
3.88 + DialogResult dlgResult = form.ShowDialog();
3.89 + centerWindow.Dispose();
3.90 + return dlgResult;
3.91 + }
3.92 +
3.93 + /// <summary>
3.94 + /// Show a form dialog box at the center of the owner window.
3.95 + /// </summary>
3.96 + public static DialogResult ShowDialog(Form form, IWin32Window owner)
3.97 + {
3.98 + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle;
3.99 + CenterWindow centerWindow = new CenterWindow(handle);
3.100 + DialogResult dlgResult = form.ShowDialog();
3.101 + centerWindow.Dispose();
3.102 + return dlgResult;
3.103 + }
3.104 + }
3.105 +
3.106 + #endregion
3.107 +
3.108 + ///////////////////////////////////////////////////////////////////////
3.109 + #region MsgBox
3.110 +
3.111 + /// <summary>
3.112 + /// Class to display a MessageBox centered on the owner.
3.113 + /// </summary>
3.114 + /// <remarks>
3.115 + /// Same methods as the standard MessageBox.
3.116 + /// </remarks>
3.117 + /// <example>
3.118 + /// This example display a "Hello" message box centered on the owner.
3.119 + /// <code>
3.120 + /// MsgBox.Show("Hello");
3.121 + /// </code>
3.122 + /// </example>
3.123 + public sealed class MsgBox
3.124 + {
3.125 + private MsgBox() {} // To remove the constructor from the documentation!
3.126 +
3.127 + ///////////////////////////////////////////////////////////////////////
3.128 + // text
3.129 +
3.130 + /// <summary>
3.131 + /// See MSDN MessageBox() method.
3.132 + /// </summary>
3.133 + public static DialogResult Show(string text)
3.134 + {
3.135 + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero);
3.136 + string caption = Application.ProductName;
3.137 + DialogResult dlgResult = MessageBox.Show(text, caption);
3.138 + centerWindow.Dispose();
3.139 + return dlgResult;
3.140 + }
3.141 +
3.142 + /// <summary>
3.143 + /// See MSDN MessageBox() method.
3.144 + /// </summary>
3.145 + public static DialogResult Show(IWin32Window owner, string text)
3.146 + {
3.147 + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle;
3.148 + CenterWindow centerWindow = new CenterWindow(handle);
3.149 + string caption = Application.ProductName;
3.150 + DialogResult dlgResult = MessageBox.Show(owner, text, caption);
3.151 + centerWindow.Dispose();
3.152 + return dlgResult;
3.153 + }
3.154 +
3.155 + ///////////////////////////////////////////////////////////////////////
3.156 + // text, caption
3.157 +
3.158 + /// <summary>
3.159 + /// See MSDN MessageBox() method.
3.160 + /// </summary>
3.161 + public static DialogResult Show(string text, string caption)
3.162 + {
3.163 + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero);
3.164 + DialogResult dlgResult = MessageBox.Show(text, caption);
3.165 + centerWindow.Dispose();
3.166 + return dlgResult;
3.167 + }
3.168 +
3.169 + /// <summary>
3.170 + /// See MSDN MessageBox() method.
3.171 + /// </summary>
3.172 + public static DialogResult Show(IWin32Window owner, string text, string caption)
3.173 + {
3.174 + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle;
3.175 + CenterWindow centerWindow = new CenterWindow(handle);
3.176 + DialogResult dlgResult = MessageBox.Show(owner, text, caption);
3.177 + centerWindow.Dispose();
3.178 + return dlgResult;
3.179 + }
3.180 +
3.181 + ///////////////////////////////////////////////////////////////////////
3.182 + // text, caption, buttons
3.183 +
3.184 + /// <summary>
3.185 + /// See MSDN MessageBox() method.
3.186 + /// </summary>
3.187 + public static DialogResult Show(string text, string caption, MessageBoxButtons buttons)
3.188 + {
3.189 + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero);
3.190 + DialogResult dlgResult = MessageBox.Show(text, caption, buttons);
3.191 + centerWindow.Dispose();
3.192 + return dlgResult;
3.193 + }
3.194 +
3.195 + /// <summary>
3.196 + /// See MSDN MessageBox() method.
3.197 + /// </summary>
3.198 + public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons)
3.199 + {
3.200 + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle;
3.201 + CenterWindow centerWindow = new CenterWindow(handle);
3.202 + DialogResult dlgResult = MessageBox.Show(owner, text, caption, buttons);
3.203 + centerWindow.Dispose();
3.204 + return dlgResult;
3.205 + }
3.206 +
3.207 + ///////////////////////////////////////////////////////////////////////
3.208 + // text, caption, buttons, defaultButton
3.209 +
3.210 + /// <summary>
3.211 + /// See MSDN MessageBox() method.
3.212 + /// </summary>
3.213 + public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
3.214 + {
3.215 + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero);
3.216 + DialogResult dlgResult = MessageBox.Show(text, caption, buttons, icon);
3.217 + centerWindow.Dispose();
3.218 + return dlgResult;
3.219 + }
3.220 +
3.221 + /// <summary>
3.222 + /// See MSDN MessageBox() method.
3.223 + /// </summary>
3.224 + public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
3.225 + {
3.226 + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle;
3.227 + CenterWindow centerWindow = new CenterWindow(handle);
3.228 + DialogResult dlgResult = MessageBox.Show(owner, text, caption, buttons, icon);
3.229 + centerWindow.Dispose();
3.230 + return dlgResult;
3.231 + }
3.232 +
3.233 + ///////////////////////////////////////////////////////////////////////
3.234 + // text, caption, buttons, defaultButton, icon
3.235 +
3.236 + /// <summary>
3.237 + /// See MSDN MessageBox() method.
3.238 + /// </summary>
3.239 + public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
3.240 + {
3.241 + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero);
3.242 + DialogResult dlgResult = MessageBox.Show(text, caption, buttons, icon, defaultButton);
3.243 + centerWindow.Dispose();
3.244 + return dlgResult;
3.245 + }
3.246 +
3.247 + /// <summary>
3.248 + /// See MSDN MessageBox() method.
3.249 + /// </summary>
3.250 + public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
3.251 + {
3.252 + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle;
3.253 + CenterWindow centerWindow = new CenterWindow(handle);
3.254 + DialogResult dlgResult = MessageBox.Show(owner, text, caption, buttons, icon, defaultButton);
3.255 + centerWindow.Dispose();
3.256 + return dlgResult;
3.257 + }
3.258 +
3.259 + ///////////////////////////////////////////////////////////////////////
3.260 + // text, caption, buttons, defaultButton, icon, options
3.261 +
3.262 + /// <summary>
3.263 + /// See MSDN MessageBox() method.
3.264 + /// </summary>
3.265 + public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options)
3.266 + {
3.267 + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero);
3.268 + DialogResult dlgResult = MessageBox.Show(text, caption, buttons, icon, defaultButton, options);
3.269 + centerWindow.Dispose();
3.270 + return dlgResult;
3.271 + }
3.272 +
3.273 + /// <summary>
3.274 + /// See MSDN MessageBox() method.
3.275 + /// </summary>
3.276 + public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options)
3.277 + {
3.278 + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle;
3.279 + CenterWindow centerWindow = new CenterWindow(handle);
3.280 + DialogResult dlgResult = MessageBox.Show(owner, text, caption, buttons, icon, defaultButton, options);
3.281 + centerWindow.Dispose();
3.282 + return dlgResult;
3.283 + }
3.284 + }
3.285 +
3.286 + #endregion
3.287 +
3.288 + ///////////////////////////////////////////////////////////////////////
3.289 + #region AppBox
3.290 +
3.291 + /// <summary>
3.292 + /// Class to display a MessageBox centered on the owner.
3.293 + /// The MessageBox caption is always Application.ProductName.
3.294 + /// </summary>
3.295 + /// <remarks>
3.296 + /// Same methods as the standard MessageBox without caption.
3.297 + /// </remarks>
3.298 + /// <example>
3.299 + /// This example display an application message box centered on the owner.
3.300 + /// <code>
3.301 + /// AppBox.Show("Hello");
3.302 + /// </code>
3.303 + /// </example>
3.304 + public sealed class AppBox
3.305 + {
3.306 + private AppBox() {} // To remove the constructor from the documentation!
3.307 +
3.308 + ///////////////////////////////////////////////////////////////////////
3.309 + // text
3.310 +
3.311 + /// <summary>
3.312 + /// See MSDN MessageBox() method. Caption is Application.ProductName.
3.313 + /// </summary>
3.314 + public static DialogResult Show(string text)
3.315 + {
3.316 + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero);
3.317 + string caption = Application.ProductName;
3.318 + DialogResult dlgResult = MessageBox.Show(text, caption);
3.319 + centerWindow.Dispose();
3.320 + return dlgResult;
3.321 + }
3.322 +
3.323 + /// <summary>
3.324 + /// See MSDN MessageBox() method. Caption is Application.ProductName.
3.325 + /// </summary>
3.326 + public static DialogResult Show(IWin32Window owner, string text)
3.327 + {
3.328 + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle;
3.329 + CenterWindow centerWindow = new CenterWindow(handle);
3.330 + string caption = Application.ProductName;
3.331 + DialogResult dlgResult = MessageBox.Show(owner, text, caption);
3.332 + centerWindow.Dispose();
3.333 + return dlgResult;
3.334 + }
3.335 +
3.336 + ///////////////////////////////////////////////////////////////////////
3.337 + // text, buttons
3.338 +
3.339 + /// <summary>
3.340 + /// See MSDN MessageBox() method. Caption is Application.ProductName.
3.341 + /// </summary>
3.342 + public static DialogResult Show(string text, MessageBoxButtons buttons)
3.343 + {
3.344 + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero);
3.345 + string caption = Application.ProductName;
3.346 + DialogResult dlgResult = MessageBox.Show(text, caption, buttons);
3.347 + centerWindow.Dispose();
3.348 + return dlgResult;
3.349 + }
3.350 +
3.351 + /// <summary>
3.352 + /// See MSDN MessageBox() method. Caption is Application.ProductName.
3.353 + /// </summary>
3.354 + public static DialogResult Show(IWin32Window owner, string text, MessageBoxButtons buttons)
3.355 + {
3.356 + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle;
3.357 + CenterWindow centerWindow = new CenterWindow(handle);
3.358 + string caption = Application.ProductName;
3.359 + DialogResult dlgResult = MessageBox.Show(owner, text, caption, buttons);
3.360 + centerWindow.Dispose();
3.361 + return dlgResult;
3.362 + }
3.363 +
3.364 + ///////////////////////////////////////////////////////////////////////
3.365 + // text, buttons, defaultButton
3.366 +
3.367 + /// <summary>
3.368 + /// See MSDN MessageBox() method. Caption is Application.ProductName.
3.369 + /// </summary>
3.370 + public static DialogResult Show(string text, MessageBoxButtons buttons, MessageBoxIcon icon)
3.371 + {
3.372 + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero);
3.373 + string caption = Application.ProductName;
3.374 + DialogResult dlgResult = MessageBox.Show(text, caption, buttons, icon);
3.375 + centerWindow.Dispose();
3.376 + return dlgResult;
3.377 + }
3.378 +
3.379 + /// <summary>
3.380 + /// See MSDN MessageBox() method. Caption is Application.ProductName.
3.381 + /// </summary>
3.382 + public static DialogResult Show(IWin32Window owner, string text, MessageBoxButtons buttons, MessageBoxIcon icon)
3.383 + {
3.384 + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle;
3.385 + CenterWindow centerWindow = new CenterWindow(handle);
3.386 + string caption = Application.ProductName;
3.387 + DialogResult dlgResult = MessageBox.Show(owner, text, caption, buttons, icon);
3.388 + centerWindow.Dispose();
3.389 + return dlgResult;
3.390 + }
3.391 +
3.392 + ///////////////////////////////////////////////////////////////////////
3.393 + // text, buttons, defaultButton, icon
3.394 +
3.395 + /// <summary>
3.396 + /// See MSDN MessageBox() method. Caption is Application.ProductName.
3.397 + /// </summary>
3.398 + public static DialogResult Show(string text, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
3.399 + {
3.400 + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero);
3.401 + string caption = Application.ProductName;
3.402 + DialogResult dlgResult = MessageBox.Show(text, caption, buttons, icon, defaultButton);
3.403 + centerWindow.Dispose();
3.404 + return dlgResult;
3.405 + }
3.406 +
3.407 + /// <summary>
3.408 + /// See MSDN MessageBox() method. Caption is Application.ProductName.
3.409 + /// </summary>
3.410 + public static DialogResult Show(IWin32Window owner, string text, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
3.411 + {
3.412 + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle;
3.413 + CenterWindow centerWindow = new CenterWindow(handle);
3.414 + string caption = Application.ProductName;
3.415 + DialogResult dlgResult = MessageBox.Show(owner, text, caption, buttons, icon, defaultButton);
3.416 + centerWindow.Dispose();
3.417 + return dlgResult;
3.418 + }
3.419 +
3.420 + ///////////////////////////////////////////////////////////////////////
3.421 + // text, buttons, defaultButton, icon, options
3.422 +
3.423 + /// <summary>
3.424 + /// See MSDN MessageBox() method. Caption is Application.ProductName.
3.425 + /// </summary>
3.426 + public static DialogResult Show(string text, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options)
3.427 + {
3.428 + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero);
3.429 + string caption = Application.ProductName;
3.430 + DialogResult dlgResult = MessageBox.Show(text, caption, buttons, icon, defaultButton, options);
3.431 + centerWindow.Dispose();
3.432 + return dlgResult;
3.433 + }
3.434 +
3.435 + /// <summary>
3.436 + /// See MSDN MessageBox() method. Caption is Application.ProductName.
3.437 + /// </summary>
3.438 + public static DialogResult Show(IWin32Window owner, string text, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options)
3.439 + {
3.440 + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle;
3.441 + CenterWindow centerWindow = new CenterWindow(handle);
3.442 + string caption = Application.ProductName;
3.443 + DialogResult dlgResult = MessageBox.Show(owner, text, caption, buttons, icon, defaultButton, options);
3.444 + centerWindow.Dispose();
3.445 + return dlgResult;
3.446 + }
3.447 + }
3.448 +
3.449 + #endregion
3.450 +
3.451 + ///////////////////////////////////////////////////////////////////////
3.452 + #region ErrBox
3.453 +
3.454 + /// <summary>
3.455 + /// Class to display application error MessageBox centered on the owner.
3.456 + /// The caption of the MessageBox is Application.ProductName.
3.457 + /// </summary>
3.458 + /// <example>
3.459 + /// This example display an error message box centered on the owner.
3.460 + /// <code>
3.461 + /// ErrBox.Show(ex);
3.462 + /// </code>
3.463 + /// </example>
3.464 + public sealed class ErrBox
3.465 + {
3.466 + private ErrBox() {} // To remove the constructor from the documentation!
3.467 +
3.468 + /// <summary>
3.469 + /// Show an error MessageBox with an icon error and an OK button.
3.470 + /// </summary>
3.471 + /// <param name="err">The error message.</param>
3.472 + /// <param name="owner">The owner of the error MessageBox.</param>
3.473 + /// <returns>Dialog result of the MessageBox.</returns>
3.474 + public static DialogResult Show(IWin32Window owner, string err)
3.475 + {
3.476 + string caption = Application.ProductName;
3.477 + return MsgBox.Show(owner, err, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
3.478 + }
3.479 +
3.480 + /// <summary>
3.481 + /// Show an error MessageBox with an icon error and an OK button.
3.482 + /// </summary>
3.483 + /// <param name="err">The error message.</param>
3.484 + /// <returns>Dialog result of the MessageBox.</returns>
3.485 + public static DialogResult Show(string err)
3.486 + {
3.487 + string caption = Application.ProductName;
3.488 + return MsgBox.Show(err, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
3.489 + }
3.490 +
3.491 + /// <summary>
3.492 + /// Show an error MessageBox with exception message, an icon error and an OK button.
3.493 + /// </summary>
3.494 + /// <param name="ex">Exception to be displayed.</param>
3.495 + /// <returns>Dialog result of the MessageBox.</returns>
3.496 + public static DialogResult Show(Exception ex)
3.497 + {
3.498 + string err = ex.Message;
3.499 + while (ex.InnerException != null)
3.500 + {
3.501 + ex = ex.InnerException;
3.502 + err += Environment.NewLine;
3.503 + err += ex.Message;
3.504 + }
3.505 + string caption = Application.ProductName;
3.506 + return MsgBox.Show(err, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
3.507 + }
3.508 +
3.509 + /// <summary>
3.510 + /// Show a specialized error MessageBox centered into the parent owner.
3.511 + /// </summary>
3.512 + /// <param name="ex">Exception to be displayed.</param>
3.513 + /// <param name="debugMode">true to display the full informations else false.</param>
3.514 + /// <returns>Dialog result of the MessageBox.</returns>
3.515 + public static DialogResult Show(Exception ex, bool debugMode)
3.516 + {
3.517 + if (debugMode)
3.518 + return Show(ex);
3.519 + else
3.520 + return Show(ex.Message);
3.521 + }
3.522 + }
3.523 +
3.524 + #endregion
3.525 +
3.526 + ///////////////////////////////////////////////////////////////////////
3.527 + #region CenterWindow class
3.528 +
3.529 + internal sealed class CenterWindow
3.530 + {
3.531 + public IntPtr hOwner = IntPtr.Zero;
3.532 + private Rectangle rect;
3.533 +
3.534 + public CbtHook cbtHook = null;
3.535 + public WndProcRetHook wndProcRetHook = null;
3.536 +
3.537 + public CenterWindow(IntPtr hOwner)
3.538 + {
3.539 + this.hOwner = hOwner;
3.540 + this.cbtHook = new CbtHook();
3.541 + cbtHook.WindowActivate += new CbtHook.CbtEventHandler(WndActivate);
3.542 + cbtHook.Install();
3.543 + }
3.544 +
3.545 + public void Dispose()
3.546 + {
3.547 + if (wndProcRetHook != null)
3.548 + {
3.549 + wndProcRetHook.Uninstall();
3.550 + wndProcRetHook = null;
3.551 + }
3.552 + if (cbtHook != null)
3.553 + {
3.554 + cbtHook.Uninstall();
3.555 + cbtHook = null;
3.556 + }
3.557 + }
3.558 +
3.559 + public void WndActivate(object sender, CbtEventArgs e)
3.560 + {
3.561 + IntPtr hMsgBox = e.wParam;
3.562 +
3.563 + // try to find a howner for this message box
3.564 + if (hOwner == IntPtr.Zero)
3.565 + hOwner = USER32.GetActiveWindow();
3.566 +
3.567 + // get the MessageBox window rect
3.568 + RECT rectDlg = new RECT();
3.569 + USER32.GetWindowRect(hMsgBox, ref rectDlg);
3.570 +
3.571 + // get the owner window rect
3.572 + RECT rectForm = new RECT();
3.573 + USER32.GetWindowRect(hOwner, ref rectForm);
3.574 +
3.575 + // get the biggest screen area
3.576 + Rectangle rectScreen = API.TrueScreenRect;
3.577 +
3.578 + // if no parent window, center on the primary screen
3.579 + if (rectForm.right == rectForm.left)
3.580 + rectForm.right = rectForm.left = Screen.PrimaryScreen.WorkingArea.Width / 2;
3.581 + if (rectForm.bottom == rectForm.top)
3.582 + rectForm.bottom = rectForm.top = Screen.PrimaryScreen.WorkingArea.Height / 2;
3.583 +
3.584 + // center on parent
3.585 + int dx = ((rectDlg.left + rectDlg.right) - (rectForm.left + rectForm.right)) / 2;
3.586 + int dy = ((rectDlg.top + rectDlg.bottom) - (rectForm.top + rectForm.bottom)) / 2;
3.587 +
3.588 + rect = new Rectangle(
3.589 + rectDlg.left - dx,
3.590 + rectDlg.top - dy,
3.591 + rectDlg.right - rectDlg.left,
3.592 + rectDlg.bottom - rectDlg.top);
3.593 +
3.594 + // place in the screen
3.595 + if (rect.Right > rectScreen.Right) rect.Offset(rectScreen.Right - rect.Right, 0);
3.596 + if (rect.Bottom > rectScreen.Bottom) rect.Offset(0, rectScreen.Bottom - rect.Bottom);
3.597 + if (rect.Left < rectScreen.Left) rect.Offset(rectScreen.Left - rect.Left, 0);
3.598 + if (rect.Top < rectScreen.Top) rect.Offset(0, rectScreen.Top - rect.Top);
3.599 +
3.600 + if (e.IsDialog)
3.601 + {
3.602 + // do the job when the WM_INITDIALOG message returns
3.603 + wndProcRetHook = new WndProcRetHook(hMsgBox);
3.604 + wndProcRetHook.WndProcRet += new WndProcRetHook.WndProcEventHandler(WndProcRet);
3.605 + wndProcRetHook.Install();
3.606 + }
3.607 + else
3.608 + USER32.MoveWindow(hMsgBox, rect.Left, rect.Top, rect.Width, rect.Height, 1);
3.609 +
3.610 + // uninstall this hook
3.611 + WindowsHook wndHook = (WindowsHook)sender;
3.612 + Debug.Assert(cbtHook == wndHook);
3.613 + cbtHook.Uninstall();
3.614 + cbtHook = null;
3.615 + }
3.616 +
3.617 + public void WndProcRet(object sender, WndProcRetEventArgs e)
3.618 + {
3.619 + if (e.cw.message == WndMessage.WM_INITDIALOG ||
3.620 + e.cw.message == WndMessage.WM_UNKNOWINIT)
3.621 + {
3.622 + USER32.MoveWindow(e.cw.hwnd, rect.Left, rect.Top, rect.Width, rect.Height, 1);
3.623 +
3.624 + // uninstall this hook
3.625 + WindowsHook wndHook = (WindowsHook)sender;
3.626 + Debug.Assert(wndProcRetHook == wndHook);
3.627 + wndProcRetHook.Uninstall();
3.628 + wndProcRetHook = null;
3.629 + }
3.630 + }
3.631 + }
3.632 + #endregion
3.633 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/MainForm.Designer.cs Sat Jun 14 12:51:25 2014 +0200
4.3 @@ -0,0 +1,178 @@
4.4 +namespace SharpDisplayManager
4.5 +{
4.6 + partial class MainForm
4.7 + {
4.8 + /// <summary>
4.9 + /// Required designer variable.
4.10 + /// </summary>
4.11 + private System.ComponentModel.IContainer components = null;
4.12 +
4.13 + /// <summary>
4.14 + /// Clean up any resources being used.
4.15 + /// </summary>
4.16 + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
4.17 + protected override void Dispose(bool disposing)
4.18 + {
4.19 + if (disposing && (components != null))
4.20 + {
4.21 + components.Dispose();
4.22 + }
4.23 + base.Dispose(disposing);
4.24 + }
4.25 +
4.26 + #region Windows Form Designer generated code
4.27 +
4.28 + /// <summary>
4.29 + /// Required method for Designer support - do not modify
4.30 + /// the contents of this method with the code editor.
4.31 + /// </summary>
4.32 + private void InitializeComponent()
4.33 + {
4.34 + this.tabControl = new System.Windows.Forms.TabControl();
4.35 + this.tabPageDisplay = new System.Windows.Forms.TabPage();
4.36 + this.buttonCapture = new System.Windows.Forms.Button();
4.37 + this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
4.38 + this.marqueeLabel1 = new SharpDisplayManager.MarqueeLabel();
4.39 + this.marqueeLabel2 = new SharpDisplayManager.MarqueeLabel();
4.40 + this.buttonFont = new System.Windows.Forms.Button();
4.41 + this.tabPageTests = new System.Windows.Forms.TabPage();
4.42 + this.fontDialog = new System.Windows.Forms.FontDialog();
4.43 + this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
4.44 + this.tabControl.SuspendLayout();
4.45 + this.tabPageDisplay.SuspendLayout();
4.46 + this.tableLayoutPanel.SuspendLayout();
4.47 + this.SuspendLayout();
4.48 + //
4.49 + // tabControl
4.50 + //
4.51 + this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
4.52 + | System.Windows.Forms.AnchorStyles.Left)
4.53 + | System.Windows.Forms.AnchorStyles.Right)));
4.54 + this.tabControl.Controls.Add(this.tabPageDisplay);
4.55 + this.tabControl.Controls.Add(this.tabPageTests);
4.56 + this.tabControl.Location = new System.Drawing.Point(12, 12);
4.57 + this.tabControl.Name = "tabControl";
4.58 + this.tabControl.SelectedIndex = 0;
4.59 + this.tabControl.Size = new System.Drawing.Size(529, 362);
4.60 + this.tabControl.TabIndex = 0;
4.61 + //
4.62 + // tabPageDisplay
4.63 + //
4.64 + this.tabPageDisplay.Controls.Add(this.buttonCapture);
4.65 + this.tabPageDisplay.Controls.Add(this.tableLayoutPanel);
4.66 + this.tabPageDisplay.Controls.Add(this.buttonFont);
4.67 + this.tabPageDisplay.Location = new System.Drawing.Point(4, 22);
4.68 + this.tabPageDisplay.Name = "tabPageDisplay";
4.69 + this.tabPageDisplay.Padding = new System.Windows.Forms.Padding(3);
4.70 + this.tabPageDisplay.Size = new System.Drawing.Size(521, 336);
4.71 + this.tabPageDisplay.TabIndex = 0;
4.72 + this.tabPageDisplay.Text = "Display";
4.73 + this.tabPageDisplay.UseVisualStyleBackColor = true;
4.74 + //
4.75 + // buttonCapture
4.76 + //
4.77 + this.buttonCapture.Location = new System.Drawing.Point(6, 278);
4.78 + this.buttonCapture.Name = "buttonCapture";
4.79 + this.buttonCapture.Size = new System.Drawing.Size(75, 23);
4.80 + this.buttonCapture.TabIndex = 5;
4.81 + this.buttonCapture.Text = "Capture";
4.82 + this.buttonCapture.UseVisualStyleBackColor = true;
4.83 + this.buttonCapture.Click += new System.EventHandler(this.buttonCapture_Click);
4.84 + //
4.85 + // tableLayoutPanel
4.86 + //
4.87 + this.tableLayoutPanel.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single;
4.88 + this.tableLayoutPanel.ColumnCount = 1;
4.89 + this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
4.90 + this.tableLayoutPanel.Controls.Add(this.marqueeLabel1, 0, 0);
4.91 + this.tableLayoutPanel.Controls.Add(this.marqueeLabel2, 0, 1);
4.92 + this.tableLayoutPanel.Location = new System.Drawing.Point(215, 165);
4.93 + this.tableLayoutPanel.Margin = new System.Windows.Forms.Padding(0);
4.94 + this.tableLayoutPanel.Name = "tableLayoutPanel";
4.95 + this.tableLayoutPanel.RowCount = 2;
4.96 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
4.97 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
4.98 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
4.99 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
4.100 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
4.101 + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
4.102 + this.tableLayoutPanel.Size = new System.Drawing.Size(256, 64);
4.103 + this.tableLayoutPanel.TabIndex = 4;
4.104 + //
4.105 + // marqueeLabel1
4.106 + //
4.107 + this.marqueeLabel1.BackColor = System.Drawing.Color.Transparent;
4.108 + this.marqueeLabel1.Dock = System.Windows.Forms.DockStyle.Fill;
4.109 + this.marqueeLabel1.Location = new System.Drawing.Point(1, 1);
4.110 + this.marqueeLabel1.Margin = new System.Windows.Forms.Padding(0);
4.111 + this.marqueeLabel1.Name = "marqueeLabel1";
4.112 + this.marqueeLabel1.PixelsPerSecond = 128;
4.113 + this.marqueeLabel1.Size = new System.Drawing.Size(254, 30);
4.114 + this.marqueeLabel1.TabIndex = 2;
4.115 + this.marqueeLabel1.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
4.116 + this.marqueeLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
4.117 + this.marqueeLabel1.UseCompatibleTextRendering = true;
4.118 + //
4.119 + // marqueeLabel2
4.120 + //
4.121 + this.marqueeLabel2.Dock = System.Windows.Forms.DockStyle.Fill;
4.122 + this.marqueeLabel2.Location = new System.Drawing.Point(1, 32);
4.123 + this.marqueeLabel2.Margin = new System.Windows.Forms.Padding(0);
4.124 + this.marqueeLabel2.Name = "marqueeLabel2";
4.125 + this.marqueeLabel2.PixelsPerSecond = 64;
4.126 + this.marqueeLabel2.Size = new System.Drawing.Size(254, 31);
4.127 + this.marqueeLabel2.TabIndex = 3;
4.128 + this.marqueeLabel2.Text = "abcdefghijklmnopqrst-0123456789";
4.129 + this.marqueeLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
4.130 + this.marqueeLabel2.UseCompatibleTextRendering = true;
4.131 + //
4.132 + // buttonFont
4.133 + //
4.134 + this.buttonFont.Location = new System.Drawing.Point(6, 307);
4.135 + this.buttonFont.Name = "buttonFont";
4.136 + this.buttonFont.Size = new System.Drawing.Size(75, 23);
4.137 + this.buttonFont.TabIndex = 0;
4.138 + this.buttonFont.Text = "Select Font";
4.139 + this.buttonFont.UseVisualStyleBackColor = true;
4.140 + this.buttonFont.Click += new System.EventHandler(this.buttonFont_Click);
4.141 + //
4.142 + // tabPageTests
4.143 + //
4.144 + this.tabPageTests.Location = new System.Drawing.Point(4, 22);
4.145 + this.tabPageTests.Name = "tabPageTests";
4.146 + this.tabPageTests.Padding = new System.Windows.Forms.Padding(3);
4.147 + this.tabPageTests.Size = new System.Drawing.Size(521, 336);
4.148 + this.tabPageTests.TabIndex = 1;
4.149 + this.tabPageTests.Text = "Test";
4.150 + this.tabPageTests.UseVisualStyleBackColor = true;
4.151 + //
4.152 + // MainForm
4.153 + //
4.154 + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
4.155 + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
4.156 + this.ClientSize = new System.Drawing.Size(553, 386);
4.157 + this.Controls.Add(this.tabControl);
4.158 + this.Name = "MainForm";
4.159 + this.Text = "Sharp Display Manager";
4.160 + this.tabControl.ResumeLayout(false);
4.161 + this.tabPageDisplay.ResumeLayout(false);
4.162 + this.tableLayoutPanel.ResumeLayout(false);
4.163 + this.ResumeLayout(false);
4.164 +
4.165 + }
4.166 +
4.167 + #endregion
4.168 +
4.169 + private System.Windows.Forms.TabControl tabControl;
4.170 + private System.Windows.Forms.TabPage tabPageDisplay;
4.171 + private System.Windows.Forms.TabPage tabPageTests;
4.172 + private System.Windows.Forms.Button buttonFont;
4.173 + private System.Windows.Forms.FontDialog fontDialog;
4.174 + private System.ComponentModel.BackgroundWorker backgroundWorker1;
4.175 + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel;
4.176 + private MarqueeLabel marqueeLabel1;
4.177 + private MarqueeLabel marqueeLabel2;
4.178 + private System.Windows.Forms.Button buttonCapture;
4.179 + }
4.180 +}
4.181 +
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/MainForm.cs Sat Jun 14 12:51:25 2014 +0200
5.3 @@ -0,0 +1,57 @@
5.4 +using System;
5.5 +using System.Collections.Generic;
5.6 +using System.ComponentModel;
5.7 +using System.Data;
5.8 +using System.Drawing;
5.9 +using System.Linq;
5.10 +using System.Text;
5.11 +using System.Threading.Tasks;
5.12 +using System.Windows.Forms;
5.13 +using CodeProject.Dialog;
5.14 +
5.15 +namespace SharpDisplayManager
5.16 +{
5.17 + public partial class MainForm : Form
5.18 + {
5.19 + public MainForm()
5.20 + {
5.21 + InitializeComponent();
5.22 + }
5.23 +
5.24 + private void buttonFont_Click(object sender, EventArgs e)
5.25 + {
5.26 + //fontDialog.ShowColor = true;
5.27 + //fontDialog.ShowApply = true;
5.28 + fontDialog.ShowEffects = true;
5.29 + //fontDialog.ShowHelp = true;
5.30 +
5.31 + //fontDlg.MaxSize = 40;
5.32 + //fontDlg.MinSize = 22;
5.33 +
5.34 + //fontDialog.Parent = this;
5.35 + //fontDialog.StartPosition = FormStartPosition.CenterParent;
5.36 +
5.37 + //DlgBox.ShowDialog(fontDialog);
5.38 +
5.39 + //if (fontDialog.ShowDialog(this) != DialogResult.Cancel)
5.40 + if (DlgBox.ShowDialog(fontDialog) != DialogResult.Cancel)
5.41 + {
5.42 +
5.43 + MsgBox.Show("MessageBox MsgBox", "MsgBox caption");
5.44 +
5.45 + //MessageBox.Show("Ok");
5.46 + //textBox1.Font = fontDlg.Font;
5.47 + //label1.Font = fontDlg.Font;
5.48 + //textBox1.BackColor = fontDlg.Color;
5.49 + //label1.ForeColor = fontDlg.Color;
5.50 + }
5.51 + }
5.52 +
5.53 + private void buttonCapture_Click(object sender, EventArgs e)
5.54 + {
5.55 + System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
5.56 + tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
5.57 + bmp.Save("c:\\capture.png");
5.58 + }
5.59 + }
5.60 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/MainForm.resx Sat Jun 14 12:51:25 2014 +0200
6.3 @@ -0,0 +1,126 @@
6.4 +<?xml version="1.0" encoding="utf-8"?>
6.5 +<root>
6.6 + <!--
6.7 + Microsoft ResX Schema
6.8 +
6.9 + Version 2.0
6.10 +
6.11 + The primary goals of this format is to allow a simple XML format
6.12 + that is mostly human readable. The generation and parsing of the
6.13 + various data types are done through the TypeConverter classes
6.14 + associated with the data types.
6.15 +
6.16 + Example:
6.17 +
6.18 + ... ado.net/XML headers & schema ...
6.19 + <resheader name="resmimetype">text/microsoft-resx</resheader>
6.20 + <resheader name="version">2.0</resheader>
6.21 + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
6.22 + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
6.23 + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
6.24 + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
6.25 + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
6.26 + <value>[base64 mime encoded serialized .NET Framework object]</value>
6.27 + </data>
6.28 + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
6.29 + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
6.30 + <comment>This is a comment</comment>
6.31 + </data>
6.32 +
6.33 + There are any number of "resheader" rows that contain simple
6.34 + name/value pairs.
6.35 +
6.36 + Each data row contains a name, and value. The row also contains a
6.37 + type or mimetype. Type corresponds to a .NET class that support
6.38 + text/value conversion through the TypeConverter architecture.
6.39 + Classes that don't support this are serialized and stored with the
6.40 + mimetype set.
6.41 +
6.42 + The mimetype is used for serialized objects, and tells the
6.43 + ResXResourceReader how to depersist the object. This is currently not
6.44 + extensible. For a given mimetype the value must be set accordingly:
6.45 +
6.46 + Note - application/x-microsoft.net.object.binary.base64 is the format
6.47 + that the ResXResourceWriter will generate, however the reader can
6.48 + read any of the formats listed below.
6.49 +
6.50 + mimetype: application/x-microsoft.net.object.binary.base64
6.51 + value : The object must be serialized with
6.52 + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
6.53 + : and then encoded with base64 encoding.
6.54 +
6.55 + mimetype: application/x-microsoft.net.object.soap.base64
6.56 + value : The object must be serialized with
6.57 + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
6.58 + : and then encoded with base64 encoding.
6.59 +
6.60 + mimetype: application/x-microsoft.net.object.bytearray.base64
6.61 + value : The object must be serialized into a byte array
6.62 + : using a System.ComponentModel.TypeConverter
6.63 + : and then encoded with base64 encoding.
6.64 + -->
6.65 + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
6.66 + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
6.67 + <xsd:element name="root" msdata:IsDataSet="true">
6.68 + <xsd:complexType>
6.69 + <xsd:choice maxOccurs="unbounded">
6.70 + <xsd:element name="metadata">
6.71 + <xsd:complexType>
6.72 + <xsd:sequence>
6.73 + <xsd:element name="value" type="xsd:string" minOccurs="0" />
6.74 + </xsd:sequence>
6.75 + <xsd:attribute name="name" use="required" type="xsd:string" />
6.76 + <xsd:attribute name="type" type="xsd:string" />
6.77 + <xsd:attribute name="mimetype" type="xsd:string" />
6.78 + <xsd:attribute ref="xml:space" />
6.79 + </xsd:complexType>
6.80 + </xsd:element>
6.81 + <xsd:element name="assembly">
6.82 + <xsd:complexType>
6.83 + <xsd:attribute name="alias" type="xsd:string" />
6.84 + <xsd:attribute name="name" type="xsd:string" />
6.85 + </xsd:complexType>
6.86 + </xsd:element>
6.87 + <xsd:element name="data">
6.88 + <xsd:complexType>
6.89 + <xsd:sequence>
6.90 + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
6.91 + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
6.92 + </xsd:sequence>
6.93 + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
6.94 + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
6.95 + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
6.96 + <xsd:attribute ref="xml:space" />
6.97 + </xsd:complexType>
6.98 + </xsd:element>
6.99 + <xsd:element name="resheader">
6.100 + <xsd:complexType>
6.101 + <xsd:sequence>
6.102 + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
6.103 + </xsd:sequence>
6.104 + <xsd:attribute name="name" type="xsd:string" use="required" />
6.105 + </xsd:complexType>
6.106 + </xsd:element>
6.107 + </xsd:choice>
6.108 + </xsd:complexType>
6.109 + </xsd:element>
6.110 + </xsd:schema>
6.111 + <resheader name="resmimetype">
6.112 + <value>text/microsoft-resx</value>
6.113 + </resheader>
6.114 + <resheader name="version">
6.115 + <value>2.0</value>
6.116 + </resheader>
6.117 + <resheader name="reader">
6.118 + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
6.119 + </resheader>
6.120 + <resheader name="writer">
6.121 + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
6.122 + </resheader>
6.123 + <metadata name="fontDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
6.124 + <value>17, 17</value>
6.125 + </metadata>
6.126 + <metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
6.127 + <value>126, 17</value>
6.128 + </metadata>
6.129 +</root>
6.130 \ No newline at end of file
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/MarqueeLabel.cs Sat Jun 14 12:51:25 2014 +0200
7.3 @@ -0,0 +1,110 @@
7.4 +using System;
7.5 +using System.Collections.Generic;
7.6 +using System.ComponentModel;
7.7 +using System.Diagnostics;
7.8 +using System.Linq;
7.9 +using System.Text;
7.10 +using System.Threading.Tasks;
7.11 +//using System.Timers;
7.12 +using System.Windows.Forms;
7.13 +using System.Drawing;
7.14 +
7.15 +namespace SharpDisplayManager
7.16 +{
7.17 + class MarqueeLabel : Label
7.18 + {
7.19 + private int CurrentPosition { get; set; }
7.20 + private Timer Timer { get; set; }
7.21 +
7.22 +
7.23 + [Category("Behavior")]
7.24 + [Description("How fast is our text scrolling, in pixels per second.")]
7.25 + [DefaultValue(32)]
7.26 + [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
7.27 + public int PixelsPerSecond { get; set; }
7.28 +
7.29 + private DateTime LastTickTime { get; set; }
7.30 + private double PixelsLeft { get; set; }
7.31 + //DateTime a = new DateTime(2010, 05, 12, 13, 15, 00);
7.32 +//DateTime b = new DateTime(2010, 05, 12, 13, 45, 00);
7.33 +//Console.WriteLine(b.Subtract(a).TotalMinutes);
7.34 +
7.35 + public MarqueeLabel()
7.36 + {
7.37 + UseCompatibleTextRendering = true;
7.38 + Timer = new Timer();
7.39 + Timer.Interval = 10;
7.40 + Timer.Tick += new EventHandler(Timer_Tick);
7.41 + Timer.Start();
7.42 + //PixelsPerSecond = 32;
7.43 + LastTickTime = DateTime.Now;
7.44 + PixelsLeft = 0;
7.45 + }
7.46 +
7.47 + void Timer_Tick(object sender, EventArgs e)
7.48 + {
7.49 + while (CurrentPosition > Width)
7.50 + {
7.51 + CurrentPosition = -Width;
7.52 + }
7.53 +
7.54 + DateTime NewTickTime=DateTime.Now;
7.55 + PixelsLeft += NewTickTime.Subtract(LastTickTime).TotalSeconds * PixelsPerSecond;
7.56 + LastTickTime = NewTickTime;
7.57 + //offset += PixelsLeft;
7.58 +
7.59 + //Keep track of our pixels left over
7.60 + //PixelsLeft = offset - Math.Truncate(offset);
7.61 + double offset = Math.Truncate(PixelsLeft);
7.62 + PixelsLeft -= offset;
7.63 +
7.64 + CurrentPosition += Convert.ToInt32(offset);
7.65 +
7.66 + /*
7.67 + if (offset > 1.0)
7.68 + {
7.69 + BackColor = Color.Red;
7.70 + }
7.71 + else if (offset==1.0)
7.72 + {
7.73 + if (BackColor != Color.White)
7.74 + {
7.75 + BackColor = Color.White;
7.76 + }
7.77 +
7.78 + }
7.79 + else
7.80 + {
7.81 + //Too slow
7.82 + //BackColor = Color.Green;
7.83 + }*/
7.84 +
7.85 + //Only redraw if something has changed
7.86 + if (offset != 0)
7.87 + {
7.88 + Invalidate();
7.89 + }
7.90 +
7.91 +
7.92 +
7.93 + }
7.94 +
7.95 + protected override void OnPaint(PaintEventArgs e)
7.96 + {
7.97 + //Disable anti-aliasing
7.98 + e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
7.99 + e.Graphics.TranslateTransform((float)CurrentPosition, 0);
7.100 + base.OnPaint(e);
7.101 + }
7.102 +
7.103 + protected override void Dispose(bool disposing)
7.104 + {
7.105 + if (disposing)
7.106 + {
7.107 + if (Timer != null)
7.108 + Timer.Dispose();
7.109 + }
7.110 + Timer = null;
7.111 + }
7.112 + }
7.113 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/Program.cs Sat Jun 14 12:51:25 2014 +0200
8.3 @@ -0,0 +1,22 @@
8.4 +using System;
8.5 +using System.Collections.Generic;
8.6 +using System.Linq;
8.7 +using System.Threading.Tasks;
8.8 +using System.Windows.Forms;
8.9 +
8.10 +namespace SharpDisplayManager
8.11 +{
8.12 + static class Program
8.13 + {
8.14 + /// <summary>
8.15 + /// The main entry point for the application.
8.16 + /// </summary>
8.17 + [STAThread]
8.18 + static void Main()
8.19 + {
8.20 + Application.EnableVisualStyles();
8.21 + Application.SetCompatibleTextRenderingDefault(false);
8.22 + Application.Run(new MainForm());
8.23 + }
8.24 + }
8.25 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/Properties/AssemblyInfo.cs Sat Jun 14 12:51:25 2014 +0200
9.3 @@ -0,0 +1,36 @@
9.4 +using System.Reflection;
9.5 +using System.Runtime.CompilerServices;
9.6 +using System.Runtime.InteropServices;
9.7 +
9.8 +// General Information about an assembly is controlled through the following
9.9 +// set of attributes. Change these attribute values to modify the information
9.10 +// associated with an assembly.
9.11 +[assembly: AssemblyTitle("SharpDisplayManager")]
9.12 +[assembly: AssemblyDescription("")]
9.13 +[assembly: AssemblyConfiguration("")]
9.14 +[assembly: AssemblyCompany("")]
9.15 +[assembly: AssemblyProduct("SharpDisplayManager")]
9.16 +[assembly: AssemblyCopyright("Copyright © 2014")]
9.17 +[assembly: AssemblyTrademark("")]
9.18 +[assembly: AssemblyCulture("")]
9.19 +
9.20 +// Setting ComVisible to false makes the types in this assembly not visible
9.21 +// to COM components. If you need to access a type in this assembly from
9.22 +// COM, set the ComVisible attribute to true on that type.
9.23 +[assembly: ComVisible(false)]
9.24 +
9.25 +// The following GUID is for the ID of the typelib if this project is exposed to COM
9.26 +[assembly: Guid("5da0f26b-76a6-41e8-832c-5b593b3a75b0")]
9.27 +
9.28 +// Version information for an assembly consists of the following four values:
9.29 +//
9.30 +// Major Version
9.31 +// Minor Version
9.32 +// Build Number
9.33 +// Revision
9.34 +//
9.35 +// You can specify all the values or you can default the Build and Revision Numbers
9.36 +// by using the '*' as shown below:
9.37 +// [assembly: AssemblyVersion("1.0.*")]
9.38 +[assembly: AssemblyVersion("1.0.0.0")]
9.39 +[assembly: AssemblyFileVersion("1.0.0.0")]
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/Properties/Resources.Designer.cs Sat Jun 14 12:51:25 2014 +0200
10.3 @@ -0,0 +1,71 @@
10.4 +//------------------------------------------------------------------------------
10.5 +// <auto-generated>
10.6 +// This code was generated by a tool.
10.7 +// Runtime Version:4.0.30319.18063
10.8 +//
10.9 +// Changes to this file may cause incorrect behavior and will be lost if
10.10 +// the code is regenerated.
10.11 +// </auto-generated>
10.12 +//------------------------------------------------------------------------------
10.13 +
10.14 +namespace SharpDisplayManager.Properties
10.15 +{
10.16 +
10.17 +
10.18 + /// <summary>
10.19 + /// A strongly-typed resource class, for looking up localized strings, etc.
10.20 + /// </summary>
10.21 + // This class was auto-generated by the StronglyTypedResourceBuilder
10.22 + // class via a tool like ResGen or Visual Studio.
10.23 + // To add or remove a member, edit your .ResX file then rerun ResGen
10.24 + // with the /str option, or rebuild your VS project.
10.25 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
10.26 + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
10.27 + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
10.28 + internal class Resources
10.29 + {
10.30 +
10.31 + private static global::System.Resources.ResourceManager resourceMan;
10.32 +
10.33 + private static global::System.Globalization.CultureInfo resourceCulture;
10.34 +
10.35 + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
10.36 + internal Resources()
10.37 + {
10.38 + }
10.39 +
10.40 + /// <summary>
10.41 + /// Returns the cached ResourceManager instance used by this class.
10.42 + /// </summary>
10.43 + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
10.44 + internal static global::System.Resources.ResourceManager ResourceManager
10.45 + {
10.46 + get
10.47 + {
10.48 + if ((resourceMan == null))
10.49 + {
10.50 + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SharpDisplayManager.Properties.Resources", typeof(Resources).Assembly);
10.51 + resourceMan = temp;
10.52 + }
10.53 + return resourceMan;
10.54 + }
10.55 + }
10.56 +
10.57 + /// <summary>
10.58 + /// Overrides the current thread's CurrentUICulture property for all
10.59 + /// resource lookups using this strongly typed resource class.
10.60 + /// </summary>
10.61 + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
10.62 + internal static global::System.Globalization.CultureInfo Culture
10.63 + {
10.64 + get
10.65 + {
10.66 + return resourceCulture;
10.67 + }
10.68 + set
10.69 + {
10.70 + resourceCulture = value;
10.71 + }
10.72 + }
10.73 + }
10.74 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/Properties/Resources.resx Sat Jun 14 12:51:25 2014 +0200
11.3 @@ -0,0 +1,117 @@
11.4 +<?xml version="1.0" encoding="utf-8"?>
11.5 +<root>
11.6 + <!--
11.7 + Microsoft ResX Schema
11.8 +
11.9 + Version 2.0
11.10 +
11.11 + The primary goals of this format is to allow a simple XML format
11.12 + that is mostly human readable. The generation and parsing of the
11.13 + various data types are done through the TypeConverter classes
11.14 + associated with the data types.
11.15 +
11.16 + Example:
11.17 +
11.18 + ... ado.net/XML headers & schema ...
11.19 + <resheader name="resmimetype">text/microsoft-resx</resheader>
11.20 + <resheader name="version">2.0</resheader>
11.21 + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
11.22 + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
11.23 + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
11.24 + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
11.25 + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
11.26 + <value>[base64 mime encoded serialized .NET Framework object]</value>
11.27 + </data>
11.28 + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
11.29 + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
11.30 + <comment>This is a comment</comment>
11.31 + </data>
11.32 +
11.33 + There are any number of "resheader" rows that contain simple
11.34 + name/value pairs.
11.35 +
11.36 + Each data row contains a name, and value. The row also contains a
11.37 + type or mimetype. Type corresponds to a .NET class that support
11.38 + text/value conversion through the TypeConverter architecture.
11.39 + Classes that don't support this are serialized and stored with the
11.40 + mimetype set.
11.41 +
11.42 + The mimetype is used for serialized objects, and tells the
11.43 + ResXResourceReader how to depersist the object. This is currently not
11.44 + extensible. For a given mimetype the value must be set accordingly:
11.45 +
11.46 + Note - application/x-microsoft.net.object.binary.base64 is the format
11.47 + that the ResXResourceWriter will generate, however the reader can
11.48 + read any of the formats listed below.
11.49 +
11.50 + mimetype: application/x-microsoft.net.object.binary.base64
11.51 + value : The object must be serialized with
11.52 + : System.Serialization.Formatters.Binary.BinaryFormatter
11.53 + : and then encoded with base64 encoding.
11.54 +
11.55 + mimetype: application/x-microsoft.net.object.soap.base64
11.56 + value : The object must be serialized with
11.57 + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
11.58 + : and then encoded with base64 encoding.
11.59 +
11.60 + mimetype: application/x-microsoft.net.object.bytearray.base64
11.61 + value : The object must be serialized into a byte array
11.62 + : using a System.ComponentModel.TypeConverter
11.63 + : and then encoded with base64 encoding.
11.64 + -->
11.65 + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
11.66 + <xsd:element name="root" msdata:IsDataSet="true">
11.67 + <xsd:complexType>
11.68 + <xsd:choice maxOccurs="unbounded">
11.69 + <xsd:element name="metadata">
11.70 + <xsd:complexType>
11.71 + <xsd:sequence>
11.72 + <xsd:element name="value" type="xsd:string" minOccurs="0" />
11.73 + </xsd:sequence>
11.74 + <xsd:attribute name="name" type="xsd:string" />
11.75 + <xsd:attribute name="type" type="xsd:string" />
11.76 + <xsd:attribute name="mimetype" type="xsd:string" />
11.77 + </xsd:complexType>
11.78 + </xsd:element>
11.79 + <xsd:element name="assembly">
11.80 + <xsd:complexType>
11.81 + <xsd:attribute name="alias" type="xsd:string" />
11.82 + <xsd:attribute name="name" type="xsd:string" />
11.83 + </xsd:complexType>
11.84 + </xsd:element>
11.85 + <xsd:element name="data">
11.86 + <xsd:complexType>
11.87 + <xsd:sequence>
11.88 + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
11.89 + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
11.90 + </xsd:sequence>
11.91 + <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
11.92 + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
11.93 + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
11.94 + </xsd:complexType>
11.95 + </xsd:element>
11.96 + <xsd:element name="resheader">
11.97 + <xsd:complexType>
11.98 + <xsd:sequence>
11.99 + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
11.100 + </xsd:sequence>
11.101 + <xsd:attribute name="name" type="xsd:string" use="required" />
11.102 + </xsd:complexType>
11.103 + </xsd:element>
11.104 + </xsd:choice>
11.105 + </xsd:complexType>
11.106 + </xsd:element>
11.107 + </xsd:schema>
11.108 + <resheader name="resmimetype">
11.109 + <value>text/microsoft-resx</value>
11.110 + </resheader>
11.111 + <resheader name="version">
11.112 + <value>2.0</value>
11.113 + </resheader>
11.114 + <resheader name="reader">
11.115 + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
11.116 + </resheader>
11.117 + <resheader name="writer">
11.118 + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
11.119 + </resheader>
11.120 +</root>
11.121 \ No newline at end of file
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/Properties/Settings.Designer.cs Sat Jun 14 12:51:25 2014 +0200
12.3 @@ -0,0 +1,30 @@
12.4 +//------------------------------------------------------------------------------
12.5 +// <auto-generated>
12.6 +// This code was generated by a tool.
12.7 +// Runtime Version:4.0.30319.18063
12.8 +//
12.9 +// Changes to this file may cause incorrect behavior and will be lost if
12.10 +// the code is regenerated.
12.11 +// </auto-generated>
12.12 +//------------------------------------------------------------------------------
12.13 +
12.14 +namespace SharpDisplayManager.Properties
12.15 +{
12.16 +
12.17 +
12.18 + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
12.19 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
12.20 + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
12.21 + {
12.22 +
12.23 + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
12.24 +
12.25 + public static Settings Default
12.26 + {
12.27 + get
12.28 + {
12.29 + return defaultInstance;
12.30 + }
12.31 + }
12.32 + }
12.33 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/Properties/Settings.settings Sat Jun 14 12:51:25 2014 +0200
13.3 @@ -0,0 +1,7 @@
13.4 +<?xml version='1.0' encoding='utf-8'?>
13.5 +<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
13.6 + <Profiles>
13.7 + <Profile Name="(Default)" />
13.8 + </Profiles>
13.9 + <Settings />
13.10 +</SettingsFile>
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/SharpDisplayManager.csproj Sat Jun 14 12:51:25 2014 +0200
14.3 @@ -0,0 +1,98 @@
14.4 +<?xml version="1.0" encoding="utf-8"?>
14.5 +<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
14.6 + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
14.7 + <PropertyGroup>
14.8 + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
14.9 + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
14.10 + <ProjectGuid>{1DA8C1B3-18C5-4E74-BE4E-0B0E15FBAF49}</ProjectGuid>
14.11 + <OutputType>WinExe</OutputType>
14.12 + <AppDesignerFolder>Properties</AppDesignerFolder>
14.13 + <RootNamespace>SharpDisplayManager</RootNamespace>
14.14 + <AssemblyName>SharpDisplayManager</AssemblyName>
14.15 + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
14.16 + <FileAlignment>512</FileAlignment>
14.17 + </PropertyGroup>
14.18 + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
14.19 + <PlatformTarget>AnyCPU</PlatformTarget>
14.20 + <DebugSymbols>true</DebugSymbols>
14.21 + <DebugType>full</DebugType>
14.22 + <Optimize>false</Optimize>
14.23 + <OutputPath>bin\Debug\</OutputPath>
14.24 + <DefineConstants>DEBUG;TRACE</DefineConstants>
14.25 + <ErrorReport>prompt</ErrorReport>
14.26 + <WarningLevel>4</WarningLevel>
14.27 + </PropertyGroup>
14.28 + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
14.29 + <PlatformTarget>AnyCPU</PlatformTarget>
14.30 + <DebugType>pdbonly</DebugType>
14.31 + <Optimize>true</Optimize>
14.32 + <OutputPath>bin\Release\</OutputPath>
14.33 + <DefineConstants>TRACE</DefineConstants>
14.34 + <ErrorReport>prompt</ErrorReport>
14.35 + <WarningLevel>4</WarningLevel>
14.36 + </PropertyGroup>
14.37 + <ItemGroup>
14.38 + <Reference Include="Microsoft.VisualBasic" />
14.39 + <Reference Include="Microsoft.VisualBasic.PowerPacks.Vs, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
14.40 + <Reference Include="System" />
14.41 + <Reference Include="System.Core" />
14.42 + <Reference Include="System.Xml.Linq" />
14.43 + <Reference Include="System.Data.DataSetExtensions" />
14.44 + <Reference Include="Microsoft.CSharp" />
14.45 + <Reference Include="System.Data" />
14.46 + <Reference Include="System.Deployment" />
14.47 + <Reference Include="System.Drawing" />
14.48 + <Reference Include="System.Windows.Forms" />
14.49 + <Reference Include="System.Xml" />
14.50 + </ItemGroup>
14.51 + <ItemGroup>
14.52 + <Compile Include="CbtHook.cs" />
14.53 + <Compile Include="DialogBox.cs" />
14.54 + <Compile Include="MainForm.cs">
14.55 + <SubType>Form</SubType>
14.56 + </Compile>
14.57 + <Compile Include="MainForm.Designer.cs">
14.58 + <DependentUpon>MainForm.cs</DependentUpon>
14.59 + </Compile>
14.60 + <Compile Include="MarqueeLabel.cs">
14.61 + <SubType>Component</SubType>
14.62 + </Compile>
14.63 + <Compile Include="Program.cs" />
14.64 + <Compile Include="Properties\AssemblyInfo.cs" />
14.65 + <Compile Include="Win32API.cs" />
14.66 + <Compile Include="WindowsHook.cs" />
14.67 + <Compile Include="WndProcRetHook.cs" />
14.68 + <EmbeddedResource Include="MainForm.resx">
14.69 + <DependentUpon>MainForm.cs</DependentUpon>
14.70 + </EmbeddedResource>
14.71 + <EmbeddedResource Include="Properties\Resources.resx">
14.72 + <Generator>ResXFileCodeGenerator</Generator>
14.73 + <LastGenOutput>Resources.Designer.cs</LastGenOutput>
14.74 + <SubType>Designer</SubType>
14.75 + </EmbeddedResource>
14.76 + <Compile Include="Properties\Resources.Designer.cs">
14.77 + <AutoGen>True</AutoGen>
14.78 + <DependentUpon>Resources.resx</DependentUpon>
14.79 + </Compile>
14.80 + <None Include="Properties\Settings.settings">
14.81 + <Generator>SettingsSingleFileGenerator</Generator>
14.82 + <LastGenOutput>Settings.Designer.cs</LastGenOutput>
14.83 + </None>
14.84 + <Compile Include="Properties\Settings.Designer.cs">
14.85 + <AutoGen>True</AutoGen>
14.86 + <DependentUpon>Settings.settings</DependentUpon>
14.87 + <DesignTimeSharedInput>True</DesignTimeSharedInput>
14.88 + </Compile>
14.89 + </ItemGroup>
14.90 + <ItemGroup>
14.91 + <None Include="App.config" />
14.92 + </ItemGroup>
14.93 + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
14.94 + <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
14.95 + Other similar extension points exist, see Microsoft.Common.targets.
14.96 + <Target Name="BeforeBuild">
14.97 + </Target>
14.98 + <Target Name="AfterBuild">
14.99 + </Target>
14.100 + -->
14.101 +</Project>
14.102 \ No newline at end of file
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
15.2 +++ b/SharpDisplayManager.sln Sat Jun 14 12:51:25 2014 +0200
15.3 @@ -0,0 +1,20 @@
15.4 +
15.5 +Microsoft Visual Studio Solution File, Format Version 12.00
15.6 +# Visual Studio 2012
15.7 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpDisplayManager", "SharpDisplayManager.csproj", "{1DA8C1B3-18C5-4E74-BE4E-0B0E15FBAF49}"
15.8 +EndProject
15.9 +Global
15.10 + GlobalSection(SolutionConfigurationPlatforms) = preSolution
15.11 + Debug|Any CPU = Debug|Any CPU
15.12 + Release|Any CPU = Release|Any CPU
15.13 + EndGlobalSection
15.14 + GlobalSection(ProjectConfigurationPlatforms) = postSolution
15.15 + {1DA8C1B3-18C5-4E74-BE4E-0B0E15FBAF49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15.16 + {1DA8C1B3-18C5-4E74-BE4E-0B0E15FBAF49}.Debug|Any CPU.Build.0 = Debug|Any CPU
15.17 + {1DA8C1B3-18C5-4E74-BE4E-0B0E15FBAF49}.Release|Any CPU.ActiveCfg = Release|Any CPU
15.18 + {1DA8C1B3-18C5-4E74-BE4E-0B0E15FBAF49}.Release|Any CPU.Build.0 = Release|Any CPU
15.19 + EndGlobalSection
15.20 + GlobalSection(SolutionProperties) = preSolution
15.21 + HideSolutionNode = FALSE
15.22 + EndGlobalSection
15.23 +EndGlobal
16.1 Binary file SharpDisplayManager.v11.suo has changed
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/Win32API.cs Sat Jun 14 12:51:25 2014 +0200
17.3 @@ -0,0 +1,100 @@
17.4 +//=============================================================================
17.5 +// COPYRIGHT: Prosoft-Lanz
17.6 +//=============================================================================
17.7 +//
17.8 +// $Workfile: Win32API.cs $
17.9 +//
17.10 +// PROJECT : CodeProject Components
17.11 +// VERSION : 1.00
17.12 +// CREATION : 19.02.2003
17.13 +// AUTHOR : JCL
17.14 +//
17.15 +// DETAILS : This class implement Win32 API calls
17.16 +// and the contants used for these calls.
17.17 +//
17.18 +//-----------------------------------------------------------------------------
17.19 +using System;
17.20 +using System.Text;
17.21 +using System.Drawing;
17.22 +using System.Windows.Forms;
17.23 +using System.Runtime.InteropServices;
17.24 +
17.25 +namespace CodeProject.Win32API
17.26 +{
17.27 + ///////////////////////////////////////////////////////////////////////
17.28 + #region Generic declarations
17.29 +
17.30 + /// <summary>
17.31 + /// Rectangle parameters exposed as a structure.
17.32 + /// </summary>
17.33 + public struct RECT
17.34 + {
17.35 + /// <summary>
17.36 + /// Rectangle members.
17.37 + /// </summary>
17.38 + public int left, top, right, bottom;
17.39 + }
17.40 +
17.41 + #endregion
17.42 +
17.43 + ///////////////////////////////////////////////////////////////////////
17.44 + #region Util class
17.45 +
17.46 + /// <summary>
17.47 + /// Utility functions.
17.48 + /// </summary>
17.49 + public sealed class API
17.50 + {
17.51 + private API() {} // To remove the constructor from the documentation!
17.52 +
17.53 + /// <summary>
17.54 + /// Get true multiscreen size.
17.55 + /// </summary>
17.56 + public static Rectangle TrueScreenRect
17.57 + {
17.58 + get
17.59 + {
17.60 + // get the biggest screen area
17.61 + Rectangle rectScreen = Screen.PrimaryScreen.WorkingArea;
17.62 + int left = rectScreen.Left;
17.63 + int top = rectScreen.Top;
17.64 + int right = rectScreen.Right;
17.65 + int bottom = rectScreen.Bottom;
17.66 + foreach (Screen screen in Screen.AllScreens)
17.67 + {
17.68 + left = Math.Min(left, screen.WorkingArea.Left);
17.69 + right = Math.Max(right, screen.WorkingArea.Right);
17.70 + top = Math.Min(top, screen.WorkingArea.Top);
17.71 + bottom = Math.Max(bottom, screen.WorkingArea.Bottom);
17.72 + }
17.73 + return new Rectangle(left, top, right-left, bottom-top);
17.74 + }
17.75 + }
17.76 + }
17.77 +
17.78 + #endregion
17.79 +
17.80 + ///////////////////////////////////////////////////////////////////////
17.81 + #region USER32 class
17.82 +
17.83 + /// <summary>
17.84 + /// Class to expose USER32 API functions.
17.85 + /// </summary>
17.86 + public sealed class USER32
17.87 + {
17.88 + private USER32() {} // To remove the constructor from the documentation!
17.89 +
17.90 + [DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
17.91 + internal static extern int GetWindowRect(IntPtr hWnd, ref RECT rect);
17.92 +
17.93 + [DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
17.94 + internal static extern int MoveWindow(IntPtr hWnd, int x, int y, int w, int h, int repaint);
17.95 +
17.96 + [DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
17.97 + internal static extern IntPtr GetActiveWindow();
17.98 +
17.99 + [DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
17.100 + internal static extern int GetClassName(IntPtr hwnd, StringBuilder lpClassName, int nMaxCount);
17.101 + }
17.102 + #endregion
17.103 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
18.2 +++ b/WindowsHook.cs Sat Jun 14 12:51:25 2014 +0200
18.3 @@ -0,0 +1,186 @@
18.4 +//=============================================================================
18.5 +// COPYRIGHT: Prosoft-Lanz
18.6 +//=============================================================================
18.7 +//
18.8 +// $Workfile: WindowsHook.cs $
18.9 +//
18.10 +// PROJECT : CodeProject Components
18.11 +// VERSION : 1.00
18.12 +// CREATION : 19.02.2003
18.13 +// AUTHOR : JCL
18.14 +//
18.15 +// DETAILS : This class implement the Windows hook mechanism.
18.16 +// From MSDN, Dino Esposito.
18.17 +//
18.18 +//-----------------------------------------------------------------------------
18.19 +using System;
18.20 +using System.Runtime.InteropServices;
18.21 +
18.22 +namespace CodeProject.Win32API.Hook
18.23 +{
18.24 + ///////////////////////////////////////////////////////////////////////
18.25 + #region Class HookEventArgs
18.26 +
18.27 + /// Class used for hook event arguments.
18.28 + public class HookEventArgs : EventArgs
18.29 + {
18.30 + /// Event code parameter.
18.31 + public int code;
18.32 + /// wParam parameter.
18.33 + public IntPtr wParam;
18.34 + /// lParam parameter.
18.35 + public IntPtr lParam;
18.36 +
18.37 + internal HookEventArgs(int code, IntPtr wParam, IntPtr lParam)
18.38 + {
18.39 + this.code = code;
18.40 + this.wParam = wParam;
18.41 + this.lParam = lParam;
18.42 + }
18.43 + }
18.44 +
18.45 + #endregion
18.46 +
18.47 + ///////////////////////////////////////////////////////////////////////
18.48 + #region Enum HookType
18.49 +
18.50 + /// Hook Types.
18.51 + public enum HookType : int
18.52 + {
18.53 + /// <value>0</value>
18.54 + WH_JOURNALRECORD = 0,
18.55 + /// <value>1</value>
18.56 + WH_JOURNALPLAYBACK = 1,
18.57 + /// <value>2</value>
18.58 + WH_KEYBOARD = 2,
18.59 + /// <value>3</value>
18.60 + WH_GETMESSAGE = 3,
18.61 + /// <value>4</value>
18.62 + WH_CALLWNDPROC = 4,
18.63 + /// <value>5</value>
18.64 + WH_CBT = 5,
18.65 + /// <value>6</value>
18.66 + WH_SYSMSGFILTER = 6,
18.67 + /// <value>7</value>
18.68 + WH_MOUSE = 7,
18.69 + /// <value>8</value>
18.70 + WH_HARDWARE = 8,
18.71 + /// <value>9</value>
18.72 + WH_DEBUG = 9,
18.73 + /// <value>10</value>
18.74 + WH_SHELL = 10,
18.75 + /// <value>11</value>
18.76 + WH_FOREGROUNDIDLE = 11,
18.77 + /// <value>12</value>
18.78 + WH_CALLWNDPROCRET = 12,
18.79 + /// <value>13</value>
18.80 + WH_KEYBOARD_LL = 13,
18.81 + /// <value>14</value>
18.82 + WH_MOUSE_LL = 14
18.83 + }
18.84 + #endregion
18.85 +
18.86 + ///////////////////////////////////////////////////////////////////////
18.87 + #region Class WindowsHook
18.88 +
18.89 + /// <summary>
18.90 + /// Class to expose the windows hook mechanism.
18.91 + /// </summary>
18.92 + public class WindowsHook
18.93 + {
18.94 + /// <summary>
18.95 + /// Hook delegate method.
18.96 + /// </summary>
18.97 + public delegate int HookProc(int code, IntPtr wParam, IntPtr lParam);
18.98 +
18.99 + // internal properties
18.100 + internal IntPtr hHook = IntPtr.Zero;
18.101 + internal HookProc filterFunc = null;
18.102 + internal HookType hookType;
18.103 +
18.104 + /// <summary>
18.105 + /// Hook delegate method.
18.106 + /// </summary>
18.107 + public delegate void HookEventHandler(object sender, HookEventArgs e);
18.108 +
18.109 + /// <summary>
18.110 + /// Hook invoke event.
18.111 + /// </summary>
18.112 + public event HookEventHandler HookInvoke;
18.113 +
18.114 + internal void OnHookInvoke(HookEventArgs e)
18.115 + {
18.116 + if (HookInvoke != null)
18.117 + HookInvoke(this, e);
18.118 + }
18.119 +
18.120 + /// <summary>
18.121 + /// Construct a HookType hook.
18.122 + /// </summary>
18.123 + /// <param name="hook">Hook type.</param>
18.124 + public WindowsHook(HookType hook)
18.125 + {
18.126 + hookType = hook;
18.127 + filterFunc = new HookProc(this.CoreHookProc);
18.128 + }
18.129 + /// <summary>
18.130 + /// Construct a HookType hook giving a hook filter delegate method.
18.131 + /// </summary>
18.132 + /// <param name="hook">Hook type</param>
18.133 + /// <param name="func">Hook filter event.</param>
18.134 + public WindowsHook(HookType hook, HookProc func)
18.135 + {
18.136 + hookType = hook;
18.137 + filterFunc = func;
18.138 + }
18.139 +
18.140 + // default hook filter function
18.141 + internal int CoreHookProc(int code, IntPtr wParam, IntPtr lParam)
18.142 + {
18.143 + if (code < 0)
18.144 + return CallNextHookEx(hHook, code, wParam, lParam);
18.145 +
18.146 + // let clients determine what to do
18.147 + HookEventArgs e = new HookEventArgs(code, wParam, lParam);
18.148 + OnHookInvoke(e);
18.149 +
18.150 + // yield to the next hook in the chain
18.151 + return CallNextHookEx(hHook, code, wParam, lParam);
18.152 + }
18.153 +
18.154 + /// <summary>
18.155 + /// Install the hook.
18.156 + /// </summary>
18.157 + public void Install()
18.158 + {
18.159 + hHook = SetWindowsHookEx(hookType, filterFunc, IntPtr.Zero, (int)AppDomain.GetCurrentThreadId());
18.160 + }
18.161 +
18.162 +
18.163 + /// <summary>
18.164 + /// Uninstall the hook.
18.165 + /// </summary>
18.166 + public void Uninstall()
18.167 + {
18.168 + if (hHook != IntPtr.Zero)
18.169 + {
18.170 + UnhookWindowsHookEx(hHook);
18.171 + hHook = IntPtr.Zero;
18.172 + }
18.173 + }
18.174 +
18.175 + #region Win32 Imports
18.176 +
18.177 + [DllImport("user32.dll")]
18.178 + internal static extern IntPtr SetWindowsHookEx(HookType code, HookProc func, IntPtr hInstance, int threadID);
18.179 +
18.180 + [DllImport("user32.dll")]
18.181 + internal static extern int UnhookWindowsHookEx(IntPtr hhook);
18.182 +
18.183 + [DllImport("user32.dll")]
18.184 + internal static extern int CallNextHookEx(IntPtr hhook, int code, IntPtr wParam, IntPtr lParam);
18.185 +
18.186 + #endregion
18.187 + }
18.188 + #endregion
18.189 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
19.2 +++ b/WndProcRetHook.cs Sat Jun 14 12:51:25 2014 +0200
19.3 @@ -0,0 +1,135 @@
19.4 +//=============================================================================
19.5 +// COPYRIGHT: Prosoft-Lanz
19.6 +//=============================================================================
19.7 +//
19.8 +// $Workfile: WndProcRetHook.cs $
19.9 +//
19.10 +// PROJECT : CodeProject Components
19.11 +// VERSION : 1.00
19.12 +// CREATION : 19.02.2003
19.13 +// AUTHOR : JCL
19.14 +//
19.15 +// DETAILS : This class implement the WH_CALLWNDPROCRET Windows hook mechanism.
19.16 +// From MSDN, Dino Esposito.
19.17 +//
19.18 +// WindowCreate, WindowDestroye and WindowActivate user events.
19.19 +//
19.20 +//-----------------------------------------------------------------------------
19.21 +using System;
19.22 +using System.Runtime.InteropServices;
19.23 +using System.Diagnostics;
19.24 +
19.25 +namespace CodeProject.Win32API.Hook
19.26 +{
19.27 + ///////////////////////////////////////////////////////////////////////
19.28 + #region Enum WndMessage
19.29 +
19.30 + /// <summary>
19.31 + /// windows message.
19.32 + /// </summary>
19.33 + public enum WndMessage : int
19.34 + {
19.35 + /// Sent to the dialog procedure immediately before the dialog is displayed.
19.36 + WM_INITDIALOG = 0x0110,
19.37 + /// Sent to the dialog procedure immediately before the dialog is displayed.
19.38 + WM_UNKNOWINIT = 0x0127
19.39 + }
19.40 + #endregion
19.41 +
19.42 + ///////////////////////////////////////////////////////////////////////
19.43 + #region Class WndProcRetEventArgs
19.44 +
19.45 + /// Class used for WH_CALLWNDPROCRET hook event arguments.
19.46 + public class WndProcRetEventArgs : EventArgs
19.47 + {
19.48 + /// wParam parameter.
19.49 + public IntPtr wParam;
19.50 + /// lParam parameter.
19.51 + public IntPtr lParam;
19.52 + /// CWPRETSTRUCT structure.
19.53 + public CwPRetStruct cw;
19.54 +
19.55 + internal WndProcRetEventArgs(IntPtr wParam, IntPtr lParam)
19.56 + {
19.57 + this.wParam = wParam;
19.58 + this.lParam = lParam;
19.59 + cw = new CwPRetStruct();
19.60 + Marshal.PtrToStructure(lParam, cw);
19.61 + }
19.62 + }
19.63 +
19.64 + /// <summary>
19.65 + /// CWPRETSTRUCT structure.
19.66 + /// </summary>
19.67 + [StructLayout(LayoutKind.Sequential)]
19.68 + public class CwPRetStruct
19.69 + {
19.70 + /// Return value.
19.71 + public int lResult;
19.72 + /// lParam parameter.
19.73 + public int lParam;
19.74 + /// wParam parameter.
19.75 + public int wParam;
19.76 + /// Specifies the message.
19.77 + public WndMessage message;
19.78 + /// Handle to the window that processed the message.
19.79 + public IntPtr hwnd;
19.80 + }
19.81 +
19.82 + #endregion
19.83 +
19.84 + ///////////////////////////////////////////////////////////////////////
19.85 + #region Class WndProcRetHook
19.86 +
19.87 + /// <summary>
19.88 + /// Class to expose the windows WH_CALLWNDPROCRET hook mechanism.
19.89 + /// </summary>
19.90 + public class WndProcRetHook : WindowsHook
19.91 + {
19.92 + /// <summary>
19.93 + /// WH_CALLWNDPROCRET hook delegate method.
19.94 + /// </summary>
19.95 + public delegate void WndProcEventHandler(object sender, WndProcRetEventArgs e);
19.96 +
19.97 + private IntPtr hWndHooked;
19.98 +
19.99 + /// <summary>
19.100 + /// Window procedure event.
19.101 + /// </summary>
19.102 + public event WndProcEventHandler WndProcRet;
19.103 +
19.104 + /// <summary>
19.105 + /// Construct a WH_CALLWNDPROCRET hook.
19.106 + /// </summary>
19.107 + /// <param name="hWndHooked">
19.108 + /// Handle of the window to be hooked. IntPtr.Zero to hook all window.
19.109 + /// </param>
19.110 + public WndProcRetHook(IntPtr hWndHooked) : base(HookType.WH_CALLWNDPROCRET)
19.111 + {
19.112 + this.hWndHooked = hWndHooked;
19.113 + this.HookInvoke += new HookEventHandler(WndProcRetHookInvoked);
19.114 + }
19.115 + /// <summary>
19.116 + /// Construct a WH_CALLWNDPROCRET hook giving a hook filter delegate method.
19.117 + /// </summary>
19.118 + /// <param name="hWndHooked">
19.119 + /// Handle of the window to be hooked. IntPtr.Zero to hook all window.
19.120 + /// </param>
19.121 + /// <param name="func">Hook filter event.</param>
19.122 + public WndProcRetHook(IntPtr hWndHooked, HookProc func) : base(HookType.WH_CALLWNDPROCRET, func)
19.123 + {
19.124 + this.hWndHooked = hWndHooked;
19.125 + this.HookInvoke += new HookEventHandler(WndProcRetHookInvoked);
19.126 + }
19.127 +
19.128 + // handles the hook event
19.129 + private void WndProcRetHookInvoked(object sender, HookEventArgs e)
19.130 + {
19.131 + WndProcRetEventArgs wpe = new WndProcRetEventArgs(e.wParam, e.lParam);
19.132 + if ((hWndHooked == IntPtr.Zero || wpe.cw.hwnd == hWndHooked) && WndProcRet != null)
19.133 + WndProcRet(this, wpe);
19.134 + return;
19.135 + }
19.136 + }
19.137 + #endregion
19.138 +}