/// <summary> /// Initializes a new instance of the <see cref="Tray"/> class. /// </summary> /// <param name="window">TrayMessageWindow to use as a message handler.</param> public Tray(TrayMessageWindow window) { SetupMenu(false); messageWindow = window; notifyIcon = new NotifyIconCustom(messageWindow.GetHandle(), ProductConstants.DefaultSystemTrayTitle); // Setup hook delegate for outside clicks mouseHookDelegate = new MouseHookDelegate(MouseHookHandler); }
public bool HookMouse() { if (_mouseHook == IntPtr.Zero) { _mouseProc = new MouseHookDelegate(MouseHookProc); _mouseHook = SetWindowsHookExW(WH_MOUSE_LL, _mouseProc, GetModuleHandleW(IntPtr.Zero), 0); } return(_mouseHook != IntPtr.Zero); }
///<summary> ///インスタンスを作成する。 ///</summary> public MouseHook() { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { throw new PlatformNotSupportedException("Windows 98/Meではサポートされていません。"); } this.hookDelegate = new MouseHookDelegate(CallNextHook); IntPtr module = Marshal.GetHINSTANCE(typeof(MouseHook).Assembly.GetModules()[0]); hook = SetWindowsHookEx(MouseLowLevelHook, hookDelegate, module, 0); }
public MouseHook() { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { throw new PlatformNotSupportedException("Windows 98/Meではサポートされていません。"); } this.hookDelegate = new MouseHookDelegate(CallNextHook); IntPtr module = Marshal.GetHINSTANCE(typeof(MouseHook).Assembly.GetModules()[0]); hook = NativeMethod.SetWindowsHookEx(GlobalHookTypes.Mouse_Global, hookDelegate, module, 0); // hook = NativeMethod.SetWindowsHookEx(GlobalHookTypes.Mouse_Global, hookDelegate, IntPtr.Zero, (uint)NativeMethod.GetCurrentThreadId()); //NativeMethod.GetCurrentThreadId() }
///<summary> ///インスタンスを作成する。 ///</summary> ///<exception cref="Win32Exception">フックに失敗しました。原因の詳細はエラーコードを参照してください。</exception> public MouseHook() { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { throw new PlatformNotSupportedException("Windows 98/Meではサポートされていません。"); } MouseHookDelegate handler = new MouseHookDelegate(CallNextHook); this.hookDelegate = GCHandle.Alloc(handler); //IntPtr module = Marshal.GetHINSTANCE(typeof(MouseHook).Assembly.GetModules()[0]); // ここを消すかコメントアウト this.hook = SetWindowsHookEx(MouseLowLevelHook, handler, module, 0); if (hook == IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error()); } }
/// <summary> /// インスタンスを作成する。 /// </summary> /// <exception cref="Win32Exception">フックに失敗しました。原因の詳細はエラーコードを参照してください。</exception> public GlobalMouseHook() { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { throw new PlatformNotSupportedException("Windows 98/Meではサポートされていません。"); } MouseHookDelegate handler = CallNextHook; _hookDelegate = GCHandle.Alloc(handler); var module = Marshal.GetHINSTANCE(Assembly.GetEntryAssembly().GetModules()[0]); _hook = SetWindowsHookEx(MouseLowLevelHook, handler, module, 0); if (_hook == IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error()); } }
private static extern IntPtr SetWindowsHookEx(int hookType, MouseHookDelegate hookDelegate, IntPtr hInstance, uint threadId);
private static extern IntPtr SetWindowsHookExW(Int32 idHook, MouseHookDelegate HookProc, IntPtr hInstance, Int32 wParam);
///<summary> ///インスタンスを作成する。 ///</summary> ///<exception cref="Win32Exception">フックに失敗しました。原因の詳細はエラーコードを参照してください。</exception> public MouseHook() { if (Environment.OSVersion.Platform != PlatformID.Win32NT) throw new PlatformNotSupportedException("Windows 98/Meではサポートされていません。"); MouseHookDelegate handler = new MouseHookDelegate(CallNextHook); this.hookDelegate = GCHandle.Alloc(handler); //IntPtr module = Marshal.GetHINSTANCE(typeof(MouseHook).Assembly.GetModules()[0]); IntPtr module = Marshal.GetHINSTANCE(System.Reflection.Assembly.GetEntryAssembly().GetModules()[0]); this.hook = SetWindowsHookEx(MouseLowLevelHook, handler, module, 0); if (hook == IntPtr.Zero) throw new Win32Exception(Marshal.GetLastWin32Error()); }
///<summary> ///インスタンスを作成する。 ///</summary> public MouseHook() { if (Environment.OSVersion.Platform != PlatformID.Win32NT) throw new PlatformNotSupportedException("Windows 98/Meではサポートされていません。"); this.hookDelegate = new MouseHookDelegate(CallNextHook); IntPtr module = Marshal.GetHINSTANCE(typeof(MouseHook).Assembly.GetModules()[0]); hook = SetWindowsHookEx(MouseLowLevelHook, hookDelegate, module, 0); }
public static extern IntPtr SetWindowsHookEx(GlobalHookTypes hookType, MouseHookDelegate hookDelegate, IntPtr hInstance, uint threadId);
[DllImport("user32.dll")] private static extern IntPtr SetWindowsHookExW(Int32 idHook, MouseHookDelegate HookProc, IntPtr hInstance, Int32 wParam);