# HG changeset patch # User sl # Date 1402743085 -7200 # Node ID f6eca6facd07724cc265b9337a303f8ab8fef54b First contrib. diff -r 000000000000 -r f6eca6facd07 App.config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/App.config Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff -r 000000000000 -r f6eca6facd07 CbtHook.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbtHook.cs Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,171 @@ +//============================================================================= +// COPYRIGHT: Prosoft-Lanz +//============================================================================= +// +// $Workfile: CbtHook.cs $ +// +// PROJECT : CodeProject Components +// VERSION : 1.00 +// CREATION : 19.02.2003 +// AUTHOR : JCL +// +// DETAILS : This class implement the WH_CBT Windows hook mechanism. +// From MSDN, Dino Esposito. +// WindowCreate, WindowDestroy and WindowActivate user events. +// +//----------------------------------------------------------------------------- +using System; +using System.Text; +using System.Runtime.InteropServices; + +namespace CodeProject.Win32API.Hook +{ + /////////////////////////////////////////////////////////////////////// + #region Enum CbtHookAction + + /// + /// CBT hook actions. + /// + internal enum CbtHookAction : int + { + HCBT_MOVESIZE = 0, + HCBT_MINMAX = 1, + HCBT_QS = 2, + HCBT_CREATEWND = 3, + HCBT_DESTROYWND = 4, + HCBT_ACTIVATE = 5, + HCBT_CLICKSKIPPED = 6, + HCBT_KEYSKIPPED = 7, + HCBT_SYSCOMMAND = 8, + HCBT_SETFOCUS = 9 + } + + #endregion + + /////////////////////////////////////////////////////////////////////// + #region Class CbtEventArgs + + /// + /// Class used for WH_CBT hook event arguments. + /// + public class CbtEventArgs : EventArgs + { + /// wParam parameter. + public IntPtr wParam; + /// lParam parameter. + public IntPtr lParam; + /// Window class name. + public string className; + /// True if it is a dialog window. + public bool IsDialog; + + internal CbtEventArgs(IntPtr wParam, IntPtr lParam) + { + // cache the parameters + this.wParam = wParam; + this.lParam = lParam; + + // cache the window's class name + StringBuilder sb = new StringBuilder(); + sb.Capacity = 256; + USER32.GetClassName(wParam, sb, 256); + className = sb.ToString(); + IsDialog = (className == "#32770"); + } + } + + #endregion + + /////////////////////////////////////////////////////////////////////// + #region Class CbtHook + + /// + /// Class to expose the windows WH_CBT hook mechanism. + /// + public class CbtHook : WindowsHook + { + /// + /// WH_CBT hook delegate method. + /// + public delegate void CbtEventHandler(object sender, CbtEventArgs e); + + /// + /// WH_CBT create event. + /// + public event CbtEventHandler WindowCreate; + /// + /// WH_CBT destroy event. + /// + public event CbtEventHandler WindowDestroye; + /// + /// WH_CBT activate event. + /// + public event CbtEventHandler WindowActivate; + + /// + /// Construct a WH_CBT hook. + /// + public CbtHook() : base(HookType.WH_CBT) + { + this.HookInvoke += new HookEventHandler(CbtHookInvoked); + } + /// + /// Construct a WH_CBT hook giving a hook filter delegate method. + /// + /// Hook filter event. + public CbtHook(HookProc func) : base(HookType.WH_CBT, func) + { + this.HookInvoke += new HookEventHandler(CbtHookInvoked); + } + + // handles the hook event + private void CbtHookInvoked(object sender, HookEventArgs e) + { + // handle hook events (only a few of available actions) + switch ((CbtHookAction)e.code) + { + case CbtHookAction.HCBT_CREATEWND: + HandleCreateWndEvent(e.wParam, e.lParam); + break; + case CbtHookAction.HCBT_DESTROYWND: + HandleDestroyWndEvent(e.wParam, e.lParam); + break; + case CbtHookAction.HCBT_ACTIVATE: + HandleActivateEvent(e.wParam, e.lParam); + break; + } + return; + } + + // handle the CREATEWND hook event + private void HandleCreateWndEvent(IntPtr wParam, IntPtr lParam) + { + if (WindowCreate != null) + { + CbtEventArgs e = new CbtEventArgs(wParam, lParam); + WindowCreate(this, e); + } + } + + // handle the DESTROYWND hook event + private void HandleDestroyWndEvent(IntPtr wParam, IntPtr lParam) + { + if (WindowDestroye != null) + { + CbtEventArgs e = new CbtEventArgs(wParam, lParam); + WindowDestroye(this, e); + } + } + + // handle the ACTIVATE hook event + private void HandleActivateEvent(IntPtr wParam, IntPtr lParam) + { + if (WindowActivate != null) + { + CbtEventArgs e = new CbtEventArgs(wParam, lParam); + WindowActivate(this, e); + } + } + } + #endregion +} diff -r 000000000000 -r f6eca6facd07 DialogBox.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DialogBox.cs Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,630 @@ +//============================================================================= +// COPYRIGHT: Prosoft-Lanz +//============================================================================= +// +// $Workfile: DialogBox.cs $ +// +// PROJECT : CodeProject Components +// VERSION : 1.00 +// CREATION : 19.02.2003 +// AUTHOR : JCL +// +// DETAILS : DialogBoxes centered into the parent owner. +// This class implement the following objects: +// +// DlgBox.ShowDialog(...) for CommonDialog and Form +// MsgBox.Show(...) for standard MessageBox +// AppBox.Show(...) for standard MessageBox with ProductName as caption +// ErrBox.Show(...) for standard error MessageBox +// +//----------------------------------------------------------------------------- +using System; +using System.Drawing; +using System.Windows.Forms; +using System.Runtime.InteropServices; +using System.Diagnostics; + +using CodeProject.Win32API; +using CodeProject.Win32API.Hook; + +namespace CodeProject.Dialog +{ + /////////////////////////////////////////////////////////////////////// + #region DlgBox + + /// + /// Class to display a CommonDialog or modal Form centered on the owner. + /// + /// + /// This example display the default print dialog box in the center of the parent. + /// + /// PrintDialog printDlg = new PrintDialog(); + /// if (DlgBox.ShowDialog(printDlg, parent) == DialogResult.OK) + /// printDocument.Print(); + /// + /// + public sealed class DlgBox + { + private DlgBox() {} // To remove the constructor from the documentation! + + /////////////////////////////////////////////////////////////////////// + // CommonDialog + + /// + /// Show a command dialog box at the center of the active window. + /// + public static DialogResult ShowDialog(CommonDialog dlg) + { + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero); + DialogResult dlgResult = dlg.ShowDialog(); + centerWindow.Dispose(); + return dlgResult; + } + + /// + /// Show a command dialog box at the center of the owner window. + /// + public static DialogResult ShowDialog(CommonDialog dlg, IWin32Window owner) + { + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle; + CenterWindow centerWindow = new CenterWindow(handle); + DialogResult dlgResult = dlg.ShowDialog(); + centerWindow.Dispose(); + return dlgResult; + } + + /////////////////////////////////////////////////////////////////////// + // Form + + /// + /// Show a form dialog box at the center of the active window. + /// + public static DialogResult ShowDialog(Form form) + { + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero); + DialogResult dlgResult = form.ShowDialog(); + centerWindow.Dispose(); + return dlgResult; + } + + /// + /// Show a form dialog box at the center of the owner window. + /// + public static DialogResult ShowDialog(Form form, IWin32Window owner) + { + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle; + CenterWindow centerWindow = new CenterWindow(handle); + DialogResult dlgResult = form.ShowDialog(); + centerWindow.Dispose(); + return dlgResult; + } + } + + #endregion + + /////////////////////////////////////////////////////////////////////// + #region MsgBox + + /// + /// Class to display a MessageBox centered on the owner. + /// + /// + /// Same methods as the standard MessageBox. + /// + /// + /// This example display a "Hello" message box centered on the owner. + /// + /// MsgBox.Show("Hello"); + /// + /// + public sealed class MsgBox + { + private MsgBox() {} // To remove the constructor from the documentation! + + /////////////////////////////////////////////////////////////////////// + // text + + /// + /// See MSDN MessageBox() method. + /// + public static DialogResult Show(string text) + { + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero); + string caption = Application.ProductName; + DialogResult dlgResult = MessageBox.Show(text, caption); + centerWindow.Dispose(); + return dlgResult; + } + + /// + /// See MSDN MessageBox() method. + /// + public static DialogResult Show(IWin32Window owner, string text) + { + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle; + CenterWindow centerWindow = new CenterWindow(handle); + string caption = Application.ProductName; + DialogResult dlgResult = MessageBox.Show(owner, text, caption); + centerWindow.Dispose(); + return dlgResult; + } + + /////////////////////////////////////////////////////////////////////// + // text, caption + + /// + /// See MSDN MessageBox() method. + /// + public static DialogResult Show(string text, string caption) + { + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero); + DialogResult dlgResult = MessageBox.Show(text, caption); + centerWindow.Dispose(); + return dlgResult; + } + + /// + /// See MSDN MessageBox() method. + /// + public static DialogResult Show(IWin32Window owner, string text, string caption) + { + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle; + CenterWindow centerWindow = new CenterWindow(handle); + DialogResult dlgResult = MessageBox.Show(owner, text, caption); + centerWindow.Dispose(); + return dlgResult; + } + + /////////////////////////////////////////////////////////////////////// + // text, caption, buttons + + /// + /// See MSDN MessageBox() method. + /// + public static DialogResult Show(string text, string caption, MessageBoxButtons buttons) + { + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero); + DialogResult dlgResult = MessageBox.Show(text, caption, buttons); + centerWindow.Dispose(); + return dlgResult; + } + + /// + /// See MSDN MessageBox() method. + /// + public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons) + { + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle; + CenterWindow centerWindow = new CenterWindow(handle); + DialogResult dlgResult = MessageBox.Show(owner, text, caption, buttons); + centerWindow.Dispose(); + return dlgResult; + } + + /////////////////////////////////////////////////////////////////////// + // text, caption, buttons, defaultButton + + /// + /// See MSDN MessageBox() method. + /// + public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) + { + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero); + DialogResult dlgResult = MessageBox.Show(text, caption, buttons, icon); + centerWindow.Dispose(); + return dlgResult; + } + + /// + /// See MSDN MessageBox() method. + /// + public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) + { + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle; + CenterWindow centerWindow = new CenterWindow(handle); + DialogResult dlgResult = MessageBox.Show(owner, text, caption, buttons, icon); + centerWindow.Dispose(); + return dlgResult; + } + + /////////////////////////////////////////////////////////////////////// + // text, caption, buttons, defaultButton, icon + + /// + /// See MSDN MessageBox() method. + /// + public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton) + { + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero); + DialogResult dlgResult = MessageBox.Show(text, caption, buttons, icon, defaultButton); + centerWindow.Dispose(); + return dlgResult; + } + + /// + /// See MSDN MessageBox() method. + /// + public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton) + { + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle; + CenterWindow centerWindow = new CenterWindow(handle); + DialogResult dlgResult = MessageBox.Show(owner, text, caption, buttons, icon, defaultButton); + centerWindow.Dispose(); + return dlgResult; + } + + /////////////////////////////////////////////////////////////////////// + // text, caption, buttons, defaultButton, icon, options + + /// + /// See MSDN MessageBox() method. + /// + public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options) + { + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero); + DialogResult dlgResult = MessageBox.Show(text, caption, buttons, icon, defaultButton, options); + centerWindow.Dispose(); + return dlgResult; + } + + /// + /// See MSDN MessageBox() method. + /// + public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options) + { + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle; + CenterWindow centerWindow = new CenterWindow(handle); + DialogResult dlgResult = MessageBox.Show(owner, text, caption, buttons, icon, defaultButton, options); + centerWindow.Dispose(); + return dlgResult; + } + } + + #endregion + + /////////////////////////////////////////////////////////////////////// + #region AppBox + + /// + /// Class to display a MessageBox centered on the owner. + /// The MessageBox caption is always Application.ProductName. + /// + /// + /// Same methods as the standard MessageBox without caption. + /// + /// + /// This example display an application message box centered on the owner. + /// + /// AppBox.Show("Hello"); + /// + /// + public sealed class AppBox + { + private AppBox() {} // To remove the constructor from the documentation! + + /////////////////////////////////////////////////////////////////////// + // text + + /// + /// See MSDN MessageBox() method. Caption is Application.ProductName. + /// + public static DialogResult Show(string text) + { + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero); + string caption = Application.ProductName; + DialogResult dlgResult = MessageBox.Show(text, caption); + centerWindow.Dispose(); + return dlgResult; + } + + /// + /// See MSDN MessageBox() method. Caption is Application.ProductName. + /// + public static DialogResult Show(IWin32Window owner, string text) + { + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle; + CenterWindow centerWindow = new CenterWindow(handle); + string caption = Application.ProductName; + DialogResult dlgResult = MessageBox.Show(owner, text, caption); + centerWindow.Dispose(); + return dlgResult; + } + + /////////////////////////////////////////////////////////////////////// + // text, buttons + + /// + /// See MSDN MessageBox() method. Caption is Application.ProductName. + /// + public static DialogResult Show(string text, MessageBoxButtons buttons) + { + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero); + string caption = Application.ProductName; + DialogResult dlgResult = MessageBox.Show(text, caption, buttons); + centerWindow.Dispose(); + return dlgResult; + } + + /// + /// See MSDN MessageBox() method. Caption is Application.ProductName. + /// + public static DialogResult Show(IWin32Window owner, string text, MessageBoxButtons buttons) + { + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle; + CenterWindow centerWindow = new CenterWindow(handle); + string caption = Application.ProductName; + DialogResult dlgResult = MessageBox.Show(owner, text, caption, buttons); + centerWindow.Dispose(); + return dlgResult; + } + + /////////////////////////////////////////////////////////////////////// + // text, buttons, defaultButton + + /// + /// See MSDN MessageBox() method. Caption is Application.ProductName. + /// + public static DialogResult Show(string text, MessageBoxButtons buttons, MessageBoxIcon icon) + { + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero); + string caption = Application.ProductName; + DialogResult dlgResult = MessageBox.Show(text, caption, buttons, icon); + centerWindow.Dispose(); + return dlgResult; + } + + /// + /// See MSDN MessageBox() method. Caption is Application.ProductName. + /// + public static DialogResult Show(IWin32Window owner, string text, MessageBoxButtons buttons, MessageBoxIcon icon) + { + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle; + CenterWindow centerWindow = new CenterWindow(handle); + string caption = Application.ProductName; + DialogResult dlgResult = MessageBox.Show(owner, text, caption, buttons, icon); + centerWindow.Dispose(); + return dlgResult; + } + + /////////////////////////////////////////////////////////////////////// + // text, buttons, defaultButton, icon + + /// + /// See MSDN MessageBox() method. Caption is Application.ProductName. + /// + public static DialogResult Show(string text, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton) + { + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero); + string caption = Application.ProductName; + DialogResult dlgResult = MessageBox.Show(text, caption, buttons, icon, defaultButton); + centerWindow.Dispose(); + return dlgResult; + } + + /// + /// See MSDN MessageBox() method. Caption is Application.ProductName. + /// + public static DialogResult Show(IWin32Window owner, string text, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton) + { + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle; + CenterWindow centerWindow = new CenterWindow(handle); + string caption = Application.ProductName; + DialogResult dlgResult = MessageBox.Show(owner, text, caption, buttons, icon, defaultButton); + centerWindow.Dispose(); + return dlgResult; + } + + /////////////////////////////////////////////////////////////////////// + // text, buttons, defaultButton, icon, options + + /// + /// See MSDN MessageBox() method. Caption is Application.ProductName. + /// + public static DialogResult Show(string text, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options) + { + CenterWindow centerWindow = new CenterWindow(IntPtr.Zero); + string caption = Application.ProductName; + DialogResult dlgResult = MessageBox.Show(text, caption, buttons, icon, defaultButton, options); + centerWindow.Dispose(); + return dlgResult; + } + + /// + /// See MSDN MessageBox() method. Caption is Application.ProductName. + /// + public static DialogResult Show(IWin32Window owner, string text, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options) + { + IntPtr handle = (owner == null) ? IntPtr.Zero: owner.Handle; + CenterWindow centerWindow = new CenterWindow(handle); + string caption = Application.ProductName; + DialogResult dlgResult = MessageBox.Show(owner, text, caption, buttons, icon, defaultButton, options); + centerWindow.Dispose(); + return dlgResult; + } + } + + #endregion + + /////////////////////////////////////////////////////////////////////// + #region ErrBox + + /// + /// Class to display application error MessageBox centered on the owner. + /// The caption of the MessageBox is Application.ProductName. + /// + /// + /// This example display an error message box centered on the owner. + /// + /// ErrBox.Show(ex); + /// + /// + public sealed class ErrBox + { + private ErrBox() {} // To remove the constructor from the documentation! + + /// + /// Show an error MessageBox with an icon error and an OK button. + /// + /// The error message. + /// The owner of the error MessageBox. + /// Dialog result of the MessageBox. + public static DialogResult Show(IWin32Window owner, string err) + { + string caption = Application.ProductName; + return MsgBox.Show(owner, err, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + /// + /// Show an error MessageBox with an icon error and an OK button. + /// + /// The error message. + /// Dialog result of the MessageBox. + public static DialogResult Show(string err) + { + string caption = Application.ProductName; + return MsgBox.Show(err, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + /// + /// Show an error MessageBox with exception message, an icon error and an OK button. + /// + /// Exception to be displayed. + /// Dialog result of the MessageBox. + public static DialogResult Show(Exception ex) + { + string err = ex.Message; + while (ex.InnerException != null) + { + ex = ex.InnerException; + err += Environment.NewLine; + err += ex.Message; + } + string caption = Application.ProductName; + return MsgBox.Show(err, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + /// + /// Show a specialized error MessageBox centered into the parent owner. + /// + /// Exception to be displayed. + /// true to display the full informations else false. + /// Dialog result of the MessageBox. + public static DialogResult Show(Exception ex, bool debugMode) + { + if (debugMode) + return Show(ex); + else + return Show(ex.Message); + } + } + + #endregion + + /////////////////////////////////////////////////////////////////////// + #region CenterWindow class + + internal sealed class CenterWindow + { + public IntPtr hOwner = IntPtr.Zero; + private Rectangle rect; + + public CbtHook cbtHook = null; + public WndProcRetHook wndProcRetHook = null; + + public CenterWindow(IntPtr hOwner) + { + this.hOwner = hOwner; + this.cbtHook = new CbtHook(); + cbtHook.WindowActivate += new CbtHook.CbtEventHandler(WndActivate); + cbtHook.Install(); + } + + public void Dispose() + { + if (wndProcRetHook != null) + { + wndProcRetHook.Uninstall(); + wndProcRetHook = null; + } + if (cbtHook != null) + { + cbtHook.Uninstall(); + cbtHook = null; + } + } + + public void WndActivate(object sender, CbtEventArgs e) + { + IntPtr hMsgBox = e.wParam; + + // try to find a howner for this message box + if (hOwner == IntPtr.Zero) + hOwner = USER32.GetActiveWindow(); + + // get the MessageBox window rect + RECT rectDlg = new RECT(); + USER32.GetWindowRect(hMsgBox, ref rectDlg); + + // get the owner window rect + RECT rectForm = new RECT(); + USER32.GetWindowRect(hOwner, ref rectForm); + + // get the biggest screen area + Rectangle rectScreen = API.TrueScreenRect; + + // if no parent window, center on the primary screen + if (rectForm.right == rectForm.left) + rectForm.right = rectForm.left = Screen.PrimaryScreen.WorkingArea.Width / 2; + if (rectForm.bottom == rectForm.top) + rectForm.bottom = rectForm.top = Screen.PrimaryScreen.WorkingArea.Height / 2; + + // center on parent + int dx = ((rectDlg.left + rectDlg.right) - (rectForm.left + rectForm.right)) / 2; + int dy = ((rectDlg.top + rectDlg.bottom) - (rectForm.top + rectForm.bottom)) / 2; + + rect = new Rectangle( + rectDlg.left - dx, + rectDlg.top - dy, + rectDlg.right - rectDlg.left, + rectDlg.bottom - rectDlg.top); + + // place in the screen + if (rect.Right > rectScreen.Right) rect.Offset(rectScreen.Right - rect.Right, 0); + if (rect.Bottom > rectScreen.Bottom) rect.Offset(0, rectScreen.Bottom - rect.Bottom); + if (rect.Left < rectScreen.Left) rect.Offset(rectScreen.Left - rect.Left, 0); + if (rect.Top < rectScreen.Top) rect.Offset(0, rectScreen.Top - rect.Top); + + if (e.IsDialog) + { + // do the job when the WM_INITDIALOG message returns + wndProcRetHook = new WndProcRetHook(hMsgBox); + wndProcRetHook.WndProcRet += new WndProcRetHook.WndProcEventHandler(WndProcRet); + wndProcRetHook.Install(); + } + else + USER32.MoveWindow(hMsgBox, rect.Left, rect.Top, rect.Width, rect.Height, 1); + + // uninstall this hook + WindowsHook wndHook = (WindowsHook)sender; + Debug.Assert(cbtHook == wndHook); + cbtHook.Uninstall(); + cbtHook = null; + } + + public void WndProcRet(object sender, WndProcRetEventArgs e) + { + if (e.cw.message == WndMessage.WM_INITDIALOG || + e.cw.message == WndMessage.WM_UNKNOWINIT) + { + USER32.MoveWindow(e.cw.hwnd, rect.Left, rect.Top, rect.Width, rect.Height, 1); + + // uninstall this hook + WindowsHook wndHook = (WindowsHook)sender; + Debug.Assert(wndProcRetHook == wndHook); + wndProcRetHook.Uninstall(); + wndProcRetHook = null; + } + } + } + #endregion +} diff -r 000000000000 -r f6eca6facd07 MainForm.Designer.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MainForm.Designer.cs Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,178 @@ +namespace SharpDisplayManager +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.tabControl = new System.Windows.Forms.TabControl(); + this.tabPageDisplay = new System.Windows.Forms.TabPage(); + this.buttonCapture = new System.Windows.Forms.Button(); + this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.marqueeLabel1 = new SharpDisplayManager.MarqueeLabel(); + this.marqueeLabel2 = new SharpDisplayManager.MarqueeLabel(); + this.buttonFont = new System.Windows.Forms.Button(); + this.tabPageTests = new System.Windows.Forms.TabPage(); + this.fontDialog = new System.Windows.Forms.FontDialog(); + this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); + this.tabControl.SuspendLayout(); + this.tabPageDisplay.SuspendLayout(); + this.tableLayoutPanel.SuspendLayout(); + this.SuspendLayout(); + // + // tabControl + // + this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tabControl.Controls.Add(this.tabPageDisplay); + this.tabControl.Controls.Add(this.tabPageTests); + this.tabControl.Location = new System.Drawing.Point(12, 12); + this.tabControl.Name = "tabControl"; + this.tabControl.SelectedIndex = 0; + this.tabControl.Size = new System.Drawing.Size(529, 362); + this.tabControl.TabIndex = 0; + // + // tabPageDisplay + // + this.tabPageDisplay.Controls.Add(this.buttonCapture); + this.tabPageDisplay.Controls.Add(this.tableLayoutPanel); + this.tabPageDisplay.Controls.Add(this.buttonFont); + this.tabPageDisplay.Location = new System.Drawing.Point(4, 22); + this.tabPageDisplay.Name = "tabPageDisplay"; + this.tabPageDisplay.Padding = new System.Windows.Forms.Padding(3); + this.tabPageDisplay.Size = new System.Drawing.Size(521, 336); + this.tabPageDisplay.TabIndex = 0; + this.tabPageDisplay.Text = "Display"; + this.tabPageDisplay.UseVisualStyleBackColor = true; + // + // buttonCapture + // + this.buttonCapture.Location = new System.Drawing.Point(6, 278); + this.buttonCapture.Name = "buttonCapture"; + this.buttonCapture.Size = new System.Drawing.Size(75, 23); + this.buttonCapture.TabIndex = 5; + this.buttonCapture.Text = "Capture"; + this.buttonCapture.UseVisualStyleBackColor = true; + this.buttonCapture.Click += new System.EventHandler(this.buttonCapture_Click); + // + // tableLayoutPanel + // + this.tableLayoutPanel.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single; + this.tableLayoutPanel.ColumnCount = 1; + this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel.Controls.Add(this.marqueeLabel1, 0, 0); + this.tableLayoutPanel.Controls.Add(this.marqueeLabel2, 0, 1); + this.tableLayoutPanel.Location = new System.Drawing.Point(215, 165); + this.tableLayoutPanel.Margin = new System.Windows.Forms.Padding(0); + this.tableLayoutPanel.Name = "tableLayoutPanel"; + this.tableLayoutPanel.RowCount = 2; + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel.Size = new System.Drawing.Size(256, 64); + this.tableLayoutPanel.TabIndex = 4; + // + // marqueeLabel1 + // + this.marqueeLabel1.BackColor = System.Drawing.Color.Transparent; + this.marqueeLabel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.marqueeLabel1.Location = new System.Drawing.Point(1, 1); + this.marqueeLabel1.Margin = new System.Windows.Forms.Padding(0); + this.marqueeLabel1.Name = "marqueeLabel1"; + this.marqueeLabel1.PixelsPerSecond = 128; + this.marqueeLabel1.Size = new System.Drawing.Size(254, 30); + this.marqueeLabel1.TabIndex = 2; + this.marqueeLabel1.Text = "ABCDEFGHIJKLMNOPQRST-0123456789"; + this.marqueeLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.marqueeLabel1.UseCompatibleTextRendering = true; + // + // marqueeLabel2 + // + this.marqueeLabel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.marqueeLabel2.Location = new System.Drawing.Point(1, 32); + this.marqueeLabel2.Margin = new System.Windows.Forms.Padding(0); + this.marqueeLabel2.Name = "marqueeLabel2"; + this.marqueeLabel2.PixelsPerSecond = 64; + this.marqueeLabel2.Size = new System.Drawing.Size(254, 31); + this.marqueeLabel2.TabIndex = 3; + this.marqueeLabel2.Text = "abcdefghijklmnopqrst-0123456789"; + this.marqueeLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.marqueeLabel2.UseCompatibleTextRendering = true; + // + // buttonFont + // + this.buttonFont.Location = new System.Drawing.Point(6, 307); + this.buttonFont.Name = "buttonFont"; + this.buttonFont.Size = new System.Drawing.Size(75, 23); + this.buttonFont.TabIndex = 0; + this.buttonFont.Text = "Select Font"; + this.buttonFont.UseVisualStyleBackColor = true; + this.buttonFont.Click += new System.EventHandler(this.buttonFont_Click); + // + // tabPageTests + // + this.tabPageTests.Location = new System.Drawing.Point(4, 22); + this.tabPageTests.Name = "tabPageTests"; + this.tabPageTests.Padding = new System.Windows.Forms.Padding(3); + this.tabPageTests.Size = new System.Drawing.Size(521, 336); + this.tabPageTests.TabIndex = 1; + this.tabPageTests.Text = "Test"; + this.tabPageTests.UseVisualStyleBackColor = true; + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(553, 386); + this.Controls.Add(this.tabControl); + this.Name = "MainForm"; + this.Text = "Sharp Display Manager"; + this.tabControl.ResumeLayout(false); + this.tabPageDisplay.ResumeLayout(false); + this.tableLayoutPanel.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TabControl tabControl; + private System.Windows.Forms.TabPage tabPageDisplay; + private System.Windows.Forms.TabPage tabPageTests; + private System.Windows.Forms.Button buttonFont; + private System.Windows.Forms.FontDialog fontDialog; + private System.ComponentModel.BackgroundWorker backgroundWorker1; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel; + private MarqueeLabel marqueeLabel1; + private MarqueeLabel marqueeLabel2; + private System.Windows.Forms.Button buttonCapture; + } +} + diff -r 000000000000 -r f6eca6facd07 MainForm.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MainForm.cs Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using CodeProject.Dialog; + +namespace SharpDisplayManager +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + } + + private void buttonFont_Click(object sender, EventArgs e) + { + //fontDialog.ShowColor = true; + //fontDialog.ShowApply = true; + fontDialog.ShowEffects = true; + //fontDialog.ShowHelp = true; + + //fontDlg.MaxSize = 40; + //fontDlg.MinSize = 22; + + //fontDialog.Parent = this; + //fontDialog.StartPosition = FormStartPosition.CenterParent; + + //DlgBox.ShowDialog(fontDialog); + + //if (fontDialog.ShowDialog(this) != DialogResult.Cancel) + if (DlgBox.ShowDialog(fontDialog) != DialogResult.Cancel) + { + + MsgBox.Show("MessageBox MsgBox", "MsgBox caption"); + + //MessageBox.Show("Ok"); + //textBox1.Font = fontDlg.Font; + //label1.Font = fontDlg.Font; + //textBox1.BackColor = fontDlg.Color; + //label1.ForeColor = fontDlg.Color; + } + } + + private void buttonCapture_Click(object sender, EventArgs e) + { + System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height); + tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle); + bmp.Save("c:\\capture.png"); + } + } +} diff -r 000000000000 -r f6eca6facd07 MainForm.resx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MainForm.resx Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 126, 17 + + \ No newline at end of file diff -r 000000000000 -r f6eca6facd07 MarqueeLabel.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MarqueeLabel.cs Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +//using System.Timers; +using System.Windows.Forms; +using System.Drawing; + +namespace SharpDisplayManager +{ + class MarqueeLabel : Label + { + private int CurrentPosition { get; set; } + private Timer Timer { get; set; } + + + [Category("Behavior")] + [Description("How fast is our text scrolling, in pixels per second.")] + [DefaultValue(32)] + [Browsable(true), EditorBrowsable(EditorBrowsableState.Always)] + public int PixelsPerSecond { get; set; } + + private DateTime LastTickTime { get; set; } + private double PixelsLeft { get; set; } + //DateTime a = new DateTime(2010, 05, 12, 13, 15, 00); +//DateTime b = new DateTime(2010, 05, 12, 13, 45, 00); +//Console.WriteLine(b.Subtract(a).TotalMinutes); + + public MarqueeLabel() + { + UseCompatibleTextRendering = true; + Timer = new Timer(); + Timer.Interval = 10; + Timer.Tick += new EventHandler(Timer_Tick); + Timer.Start(); + //PixelsPerSecond = 32; + LastTickTime = DateTime.Now; + PixelsLeft = 0; + } + + void Timer_Tick(object sender, EventArgs e) + { + while (CurrentPosition > Width) + { + CurrentPosition = -Width; + } + + DateTime NewTickTime=DateTime.Now; + PixelsLeft += NewTickTime.Subtract(LastTickTime).TotalSeconds * PixelsPerSecond; + LastTickTime = NewTickTime; + //offset += PixelsLeft; + + //Keep track of our pixels left over + //PixelsLeft = offset - Math.Truncate(offset); + double offset = Math.Truncate(PixelsLeft); + PixelsLeft -= offset; + + CurrentPosition += Convert.ToInt32(offset); + + /* + if (offset > 1.0) + { + BackColor = Color.Red; + } + else if (offset==1.0) + { + if (BackColor != Color.White) + { + BackColor = Color.White; + } + + } + else + { + //Too slow + //BackColor = Color.Green; + }*/ + + //Only redraw if something has changed + if (offset != 0) + { + Invalidate(); + } + + + + } + + protected override void OnPaint(PaintEventArgs e) + { + //Disable anti-aliasing + e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; + e.Graphics.TranslateTransform((float)CurrentPosition, 0); + base.OnPaint(e); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (Timer != null) + Timer.Dispose(); + } + Timer = null; + } + } +} diff -r 000000000000 -r f6eca6facd07 Program.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Program.cs Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SharpDisplayManager +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff -r 000000000000 -r f6eca6facd07 Properties/AssemblyInfo.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Properties/AssemblyInfo.cs Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SharpDisplayManager")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SharpDisplayManager")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("5da0f26b-76a6-41e8-832c-5b593b3a75b0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff -r 000000000000 -r f6eca6facd07 Properties/Resources.Designer.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Properties/Resources.Designer.cs Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18063 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SharpDisplayManager.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SharpDisplayManager.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff -r 000000000000 -r f6eca6facd07 Properties/Resources.resx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Properties/Resources.resx Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff -r 000000000000 -r f6eca6facd07 Properties/Settings.Designer.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Properties/Settings.Designer.cs Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18063 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SharpDisplayManager.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff -r 000000000000 -r f6eca6facd07 Properties/Settings.settings --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Properties/Settings.settings Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,7 @@ + + + + + + + diff -r 000000000000 -r f6eca6facd07 SharpDisplayManager.csproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SharpDisplayManager.csproj Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,98 @@ + + + + + Debug + AnyCPU + {1DA8C1B3-18C5-4E74-BE4E-0B0E15FBAF49} + WinExe + Properties + SharpDisplayManager + SharpDisplayManager + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + Form + + + MainForm.cs + + + Component + + + + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff -r 000000000000 -r f6eca6facd07 SharpDisplayManager.sln --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SharpDisplayManager.sln Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpDisplayManager", "SharpDisplayManager.csproj", "{1DA8C1B3-18C5-4E74-BE4E-0B0E15FBAF49}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1DA8C1B3-18C5-4E74-BE4E-0B0E15FBAF49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1DA8C1B3-18C5-4E74-BE4E-0B0E15FBAF49}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1DA8C1B3-18C5-4E74-BE4E-0B0E15FBAF49}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1DA8C1B3-18C5-4E74-BE4E-0B0E15FBAF49}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff -r 000000000000 -r f6eca6facd07 SharpDisplayManager.v11.suo Binary file SharpDisplayManager.v11.suo has changed diff -r 000000000000 -r f6eca6facd07 Win32API.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Win32API.cs Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,100 @@ +//============================================================================= +// COPYRIGHT: Prosoft-Lanz +//============================================================================= +// +// $Workfile: Win32API.cs $ +// +// PROJECT : CodeProject Components +// VERSION : 1.00 +// CREATION : 19.02.2003 +// AUTHOR : JCL +// +// DETAILS : This class implement Win32 API calls +// and the contants used for these calls. +// +//----------------------------------------------------------------------------- +using System; +using System.Text; +using System.Drawing; +using System.Windows.Forms; +using System.Runtime.InteropServices; + +namespace CodeProject.Win32API +{ + /////////////////////////////////////////////////////////////////////// + #region Generic declarations + + /// + /// Rectangle parameters exposed as a structure. + /// + public struct RECT + { + /// + /// Rectangle members. + /// + public int left, top, right, bottom; + } + + #endregion + + /////////////////////////////////////////////////////////////////////// + #region Util class + + /// + /// Utility functions. + /// + public sealed class API + { + private API() {} // To remove the constructor from the documentation! + + /// + /// Get true multiscreen size. + /// + public static Rectangle TrueScreenRect + { + get + { + // get the biggest screen area + Rectangle rectScreen = Screen.PrimaryScreen.WorkingArea; + int left = rectScreen.Left; + int top = rectScreen.Top; + int right = rectScreen.Right; + int bottom = rectScreen.Bottom; + foreach (Screen screen in Screen.AllScreens) + { + left = Math.Min(left, screen.WorkingArea.Left); + right = Math.Max(right, screen.WorkingArea.Right); + top = Math.Min(top, screen.WorkingArea.Top); + bottom = Math.Max(bottom, screen.WorkingArea.Bottom); + } + return new Rectangle(left, top, right-left, bottom-top); + } + } + } + + #endregion + + /////////////////////////////////////////////////////////////////////// + #region USER32 class + + /// + /// Class to expose USER32 API functions. + /// + public sealed class USER32 + { + private USER32() {} // To remove the constructor from the documentation! + + [DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] + internal static extern int GetWindowRect(IntPtr hWnd, ref RECT rect); + + [DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] + internal static extern int MoveWindow(IntPtr hWnd, int x, int y, int w, int h, int repaint); + + [DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] + internal static extern IntPtr GetActiveWindow(); + + [DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] + internal static extern int GetClassName(IntPtr hwnd, StringBuilder lpClassName, int nMaxCount); + } + #endregion +} diff -r 000000000000 -r f6eca6facd07 WindowsHook.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WindowsHook.cs Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,186 @@ +//============================================================================= +// COPYRIGHT: Prosoft-Lanz +//============================================================================= +// +// $Workfile: WindowsHook.cs $ +// +// PROJECT : CodeProject Components +// VERSION : 1.00 +// CREATION : 19.02.2003 +// AUTHOR : JCL +// +// DETAILS : This class implement the Windows hook mechanism. +// From MSDN, Dino Esposito. +// +//----------------------------------------------------------------------------- +using System; +using System.Runtime.InteropServices; + +namespace CodeProject.Win32API.Hook +{ + /////////////////////////////////////////////////////////////////////// + #region Class HookEventArgs + + /// Class used for hook event arguments. + public class HookEventArgs : EventArgs + { + /// Event code parameter. + public int code; + /// wParam parameter. + public IntPtr wParam; + /// lParam parameter. + public IntPtr lParam; + + internal HookEventArgs(int code, IntPtr wParam, IntPtr lParam) + { + this.code = code; + this.wParam = wParam; + this.lParam = lParam; + } + } + + #endregion + + /////////////////////////////////////////////////////////////////////// + #region Enum HookType + + /// Hook Types. + public enum HookType : int + { + /// 0 + WH_JOURNALRECORD = 0, + /// 1 + WH_JOURNALPLAYBACK = 1, + /// 2 + WH_KEYBOARD = 2, + /// 3 + WH_GETMESSAGE = 3, + /// 4 + WH_CALLWNDPROC = 4, + /// 5 + WH_CBT = 5, + /// 6 + WH_SYSMSGFILTER = 6, + /// 7 + WH_MOUSE = 7, + /// 8 + WH_HARDWARE = 8, + /// 9 + WH_DEBUG = 9, + /// 10 + WH_SHELL = 10, + /// 11 + WH_FOREGROUNDIDLE = 11, + /// 12 + WH_CALLWNDPROCRET = 12, + /// 13 + WH_KEYBOARD_LL = 13, + /// 14 + WH_MOUSE_LL = 14 + } + #endregion + + /////////////////////////////////////////////////////////////////////// + #region Class WindowsHook + + /// + /// Class to expose the windows hook mechanism. + /// + public class WindowsHook + { + /// + /// Hook delegate method. + /// + public delegate int HookProc(int code, IntPtr wParam, IntPtr lParam); + + // internal properties + internal IntPtr hHook = IntPtr.Zero; + internal HookProc filterFunc = null; + internal HookType hookType; + + /// + /// Hook delegate method. + /// + public delegate void HookEventHandler(object sender, HookEventArgs e); + + /// + /// Hook invoke event. + /// + public event HookEventHandler HookInvoke; + + internal void OnHookInvoke(HookEventArgs e) + { + if (HookInvoke != null) + HookInvoke(this, e); + } + + /// + /// Construct a HookType hook. + /// + /// Hook type. + public WindowsHook(HookType hook) + { + hookType = hook; + filterFunc = new HookProc(this.CoreHookProc); + } + /// + /// Construct a HookType hook giving a hook filter delegate method. + /// + /// Hook type + /// Hook filter event. + public WindowsHook(HookType hook, HookProc func) + { + hookType = hook; + filterFunc = func; + } + + // default hook filter function + internal int CoreHookProc(int code, IntPtr wParam, IntPtr lParam) + { + if (code < 0) + return CallNextHookEx(hHook, code, wParam, lParam); + + // let clients determine what to do + HookEventArgs e = new HookEventArgs(code, wParam, lParam); + OnHookInvoke(e); + + // yield to the next hook in the chain + return CallNextHookEx(hHook, code, wParam, lParam); + } + + /// + /// Install the hook. + /// + public void Install() + { + hHook = SetWindowsHookEx(hookType, filterFunc, IntPtr.Zero, (int)AppDomain.GetCurrentThreadId()); + } + + + /// + /// Uninstall the hook. + /// + public void Uninstall() + { + if (hHook != IntPtr.Zero) + { + UnhookWindowsHookEx(hHook); + hHook = IntPtr.Zero; + } + } + + #region Win32 Imports + + [DllImport("user32.dll")] + internal static extern IntPtr SetWindowsHookEx(HookType code, HookProc func, IntPtr hInstance, int threadID); + + [DllImport("user32.dll")] + internal static extern int UnhookWindowsHookEx(IntPtr hhook); + + [DllImport("user32.dll")] + internal static extern int CallNextHookEx(IntPtr hhook, int code, IntPtr wParam, IntPtr lParam); + + #endregion + } + #endregion +} diff -r 000000000000 -r f6eca6facd07 WndProcRetHook.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WndProcRetHook.cs Sat Jun 14 12:51:25 2014 +0200 @@ -0,0 +1,135 @@ +//============================================================================= +// COPYRIGHT: Prosoft-Lanz +//============================================================================= +// +// $Workfile: WndProcRetHook.cs $ +// +// PROJECT : CodeProject Components +// VERSION : 1.00 +// CREATION : 19.02.2003 +// AUTHOR : JCL +// +// DETAILS : This class implement the WH_CALLWNDPROCRET Windows hook mechanism. +// From MSDN, Dino Esposito. +// +// WindowCreate, WindowDestroye and WindowActivate user events. +// +//----------------------------------------------------------------------------- +using System; +using System.Runtime.InteropServices; +using System.Diagnostics; + +namespace CodeProject.Win32API.Hook +{ + /////////////////////////////////////////////////////////////////////// + #region Enum WndMessage + + /// + /// windows message. + /// + public enum WndMessage : int + { + /// Sent to the dialog procedure immediately before the dialog is displayed. + WM_INITDIALOG = 0x0110, + /// Sent to the dialog procedure immediately before the dialog is displayed. + WM_UNKNOWINIT = 0x0127 + } + #endregion + + /////////////////////////////////////////////////////////////////////// + #region Class WndProcRetEventArgs + + /// Class used for WH_CALLWNDPROCRET hook event arguments. + public class WndProcRetEventArgs : EventArgs + { + /// wParam parameter. + public IntPtr wParam; + /// lParam parameter. + public IntPtr lParam; + /// CWPRETSTRUCT structure. + public CwPRetStruct cw; + + internal WndProcRetEventArgs(IntPtr wParam, IntPtr lParam) + { + this.wParam = wParam; + this.lParam = lParam; + cw = new CwPRetStruct(); + Marshal.PtrToStructure(lParam, cw); + } + } + + /// + /// CWPRETSTRUCT structure. + /// + [StructLayout(LayoutKind.Sequential)] + public class CwPRetStruct + { + /// Return value. + public int lResult; + /// lParam parameter. + public int lParam; + /// wParam parameter. + public int wParam; + /// Specifies the message. + public WndMessage message; + /// Handle to the window that processed the message. + public IntPtr hwnd; + } + + #endregion + + /////////////////////////////////////////////////////////////////////// + #region Class WndProcRetHook + + /// + /// Class to expose the windows WH_CALLWNDPROCRET hook mechanism. + /// + public class WndProcRetHook : WindowsHook + { + /// + /// WH_CALLWNDPROCRET hook delegate method. + /// + public delegate void WndProcEventHandler(object sender, WndProcRetEventArgs e); + + private IntPtr hWndHooked; + + /// + /// Window procedure event. + /// + public event WndProcEventHandler WndProcRet; + + /// + /// Construct a WH_CALLWNDPROCRET hook. + /// + /// + /// Handle of the window to be hooked. IntPtr.Zero to hook all window. + /// + public WndProcRetHook(IntPtr hWndHooked) : base(HookType.WH_CALLWNDPROCRET) + { + this.hWndHooked = hWndHooked; + this.HookInvoke += new HookEventHandler(WndProcRetHookInvoked); + } + /// + /// Construct a WH_CALLWNDPROCRET hook giving a hook filter delegate method. + /// + /// + /// Handle of the window to be hooked. IntPtr.Zero to hook all window. + /// + /// Hook filter event. + public WndProcRetHook(IntPtr hWndHooked, HookProc func) : base(HookType.WH_CALLWNDPROCRET, func) + { + this.hWndHooked = hWndHooked; + this.HookInvoke += new HookEventHandler(WndProcRetHookInvoked); + } + + // handles the hook event + private void WndProcRetHookInvoked(object sender, HookEventArgs e) + { + WndProcRetEventArgs wpe = new WndProcRetEventArgs(e.wParam, e.lParam); + if ((hWndHooked == IntPtr.Zero || wpe.cw.hwnd == hWndHooked) && WndProcRet != null) + WndProcRet(this, wpe); + return; + } + } + #endregion +}