public static BitmapSource GetAppIcon(IntPtr hwnd) { IntPtr hIcon = WI.GetClassLongPtr(hwnd, WI.ICON_SMALL); try { if (hIcon == IntPtr.Zero) { hIcon = WI.SendMessage(hwnd, WindowMessage.GETICON, WI.ICON_SMALL2, 0); } if (hIcon == IntPtr.Zero) { hIcon = WI.SendMessage(hwnd, WindowMessage.GETICON, WI.ICON_BIG, 0); } if (hIcon == IntPtr.Zero) { hIcon = WI.GetClassLongPtr(hwnd, WI.GCL_HICON); } if (hIcon == IntPtr.Zero) { hIcon = WI.GetClassLongPtr(hwnd, WI.GCL_HICONSM); } } catch (Exception ex) { } if (hIcon == IntPtr.Zero) { return(null); } var bs = IconSource(hIcon); return(bs); }
public void Restore() { WindowInterop.SetForegroundWindow(Hwnd); if (IsMinimized) { WindowInterop.ShowWindow(Hwnd, WindowInterop.ShowStyle.Restore); } }
public void Minimize() { WindowInterop.ShowWindow(Hwnd, WindowInterop.ShowStyle.Minimize); if (IsActive) { WindowManager.Manager.ActiveWindow = IntPtr.Zero; } }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (disposedValue) { return; } WI.UnhookWindowsHookEx(HookHandle); disposedValue = true; }
public MouseManager() { using (var process = Process.GetCurrentProcess()) using (var module = process.MainModule) { HookCallback = HookProc; HookHandle = WI.SetWindowsHookEx(WI.HookType.WH_MOUSE_LL, HookCallback, ProcessInterop.GetModuleHandle(module.ModuleName), 0); } }
public IntPtr HookProc(int code, IntPtr wParam, IntPtr lParam) { if (code < 0) { return(WI.CallNextHookEx(HookHandle, code, wParam, lParam)); } var wm = (WindowMessage)wParam; var info = Marshal.PtrToStructure <WI.MSLLHOOKSTRUCT>(lParam); switch (wm) { case WindowMessage.MOUSEMOVE: if (MouseMoved != null) { MouseMoved(this, new MouseMoveEventArgs(info.pt)); } break; case WindowMessage.LBUTTONUP: if (MouseButtonUp != null) { MouseButtonUp(this, new MouseButtonEventArgs(MouseButton.Left, info.pt)); } break; case WindowMessage.LBUTTONDOWN: if (MouseButtonDown != null) { MouseButtonDown(this, new MouseButtonEventArgs(MouseButton.Left, info.pt)); } break; case WindowMessage.RBUTTONUP: if (MouseButtonUp != null) { MouseButtonUp(this, new MouseButtonEventArgs(MouseButton.Right, info.pt)); } break; case WindowMessage.RBUTTONDOWN: if (MouseButtonDown != null) { MouseButtonDown(this, new MouseButtonEventArgs(MouseButton.Right, info.pt)); } break; } return(WI.CallNextHookEx(HookHandle, code, wParam, lParam)); }
public void Close() { WindowInterop.SendMessage(Hwnd, WindowMessage.CLOSE, 0, 0); }