public static DialogResult Show(string msg, string title, MessageBoxButtons btns, MessageBoxIcon icon, MessageBoxDefaultButton defBtn, Font customTextFont) { // Create a callback delegate _hookProcDelegate = HookCallback; // Remember the title & message that we'll look for. // The hook sees *all* windows, so we need to make sure we operate on the right one. _msg = msg; _title = title; _customTextFont = customTextFont; // Set the hook. // Suppress "GetCurrentThreadId() is deprecated" warning. // It's documented that Thread.ManagedThreadId doesn't work with SetWindowsHookEx() #pragma warning disable 0618 _hHook = Win32.SetWindowsHookEx(Win32.WH_CBT, _hookProcDelegate, IntPtr.Zero, AppDomain.GetCurrentThreadId()); #pragma warning restore 0618 // Pop a standard MessageBox. The hook will center it. var rslt = MessageBox.Show(msg, title, btns, icon, defBtn); // Release hook, clean up (may have already occurred) Unhook(); return(rslt); }
public static DialogResult Show(string msg, string title, MessageBoxButtons btns, MessageBoxIcon icon) { // Create a callback delegate _hookProcDelegate = new Win32.WindowsHookProc(HookCallback); // Remember the title & message that we'll look for. // The hook sees *all* windows, so we need to make sure we operate on the right one. _msg = msg; _title = title; // Set the hook. // Suppress "GetCurrentThreadId() is deprecated" warning. // It's documented that Thread.ManagedThreadId doesn't work with SetWindowsHookEx() #pragma warning disable 0618 _hHook = Win32.SetWindowsHookEx(Win32.WH_CBT, _hookProcDelegate, IntPtr.Zero, AppDomain.GetCurrentThreadId()); #pragma warning restore 0618 // Pop a standard MessageBox. The hook will center it. DialogResult rslt = MessageBox.Show(msg, title, btns, icon); // Release hook, clean up (may have already occurred) Unhook(); return rslt; }
private static void Unhook() { Win32.UnhookWindowsHookEx(_hHook); _hHook = 0; _hookProcDelegate = null; _msg = null; _title = null; }
/// <summary> /// /// </summary> /// <param name="name"></param> public LowLevelMouseHook(string name) { _name = name; _hookID = IntPtr.Zero; _hookProc = HookCallback; _state = DoubleClickState.Empty; _strategy = MoveStrategy.Standard; }
public static DialogResult Show(string msg_, string title_, MessageBoxButtons btns, MessageBoxIcon icon) { hookProcDelegate = new Win32.WindowsHookProc(HookCallback); msg = msg_; title = title_; #pragma warning disable 0618 hHook = Win32.SetWindowsHookEx(Win32.WH_CBT, hookProcDelegate, IntPtr.Zero, AppDomain.GetCurrentThreadId()); #pragma warning restore 0618 DialogResult rslt = MessageBox.Show(msg_, title_, btns, icon); Unhook(); return rslt; }
private static void Unhook() { Win32.UnhookWindowsHookEx(hHook); hHook = 0; hookProcDelegate = null; msg = null; title = null; }