public CallWndProcHook(WindowsAPI.WindowProc wndProc) { this.m_wndProc = wndProc; this.m_hookProc = new WindowsAPI.HookProc(this.CallWndProc); if (m_wndProc != null) { m_hHook = WindowsAPI.SetWindowsHookEx(4, m_hookProc, IntPtr.Zero, WindowsAPI.GetCurrentThreadId()); } }
public override Window.WindowItemBase WindowFromPoint(Point location) { return(new WindowItem(WindowsAPI.WindowFromPoint(location))); }
/// <summary> /// Sends MouseEvent to the current Window/Child/Control /// </summary> /// <param name="mouseevent">MouseEvent to send (for now we take also on abstract layer the windows enum, this might be mapped for other OS.)</param> /// <param name="location"></param> public abstract void SendMouseEvent(WindowsAPI.MOUSEEVENTF mouseevent, Point? location = null);
public void EndUpdate() { WindowsAPI.SendMessage(Handle, (int)Msg.WM_SETREDRAW, 1, 0); }
public int GetRebarHeight() { int height = WindowsAPI.SendMessage(Handle, (int)RebarMessages.RB_GETBARHEIGHT, 0, 0) + 1; return(height); }
void StartPeekMessageLoop() { // Create an object for storing windows message information Win32.MSG msg = new Win32.MSG(); bool leaveMsg = false; // Process messages until exit condition recognised while (!exitLoop) { // Suspend thread until a windows message has arrived if (WindowsAPI.WaitMessage()) { // Take a peek at the message details without removing from queue while (!exitLoop && WindowsAPI.PeekMessage(ref msg, 0, 0, 0, (int)Win32.PeekMessageFlags.PM_NOREMOVE)) { //Console.WriteLine("Track {0} {1}", this.Handle, ((Msg)msg.message).ToString()); //Console.WriteLine("Message is for {0 }", msg.hwnd); // Mouse was pressed in a window of this application if ((msg.message == (int)Msg.WM_LBUTTONDOWN) || (msg.message == (int)Msg.WM_MBUTTONDOWN) || (msg.message == (int)Msg.WM_RBUTTONDOWN) || (msg.message == (int)Msg.WM_NCLBUTTONDOWN) || (msg.message == (int)Msg.WM_NCMBUTTONDOWN) || (msg.message == (int)Msg.WM_NCRBUTTONDOWN)) { // Is the mouse event for this popup window? if (msg.hwnd != this.Handle && !IsChild(msg.hwnd)) { // No, then we need to exit the popup menu tracking exitLoop = true; // DO NOT process the message, leave it on the queue // and let the real destination window handle it. leaveMsg = true; } } else { // Mouse move occured if (msg.message == (int)Msg.WM_MOUSEMOVE) { // Is the mouse event for this popup window? if ((msg.hwnd != this.Handle && !IsChild(msg.hwnd))) { // Eat the message to prevent the destination getting it Win32.MSG eat = new Win32.MSG(); WindowsAPI.GetMessage(ref eat, 0, 0, 0); // Do not attempt to pull a message off the queue as it has already // been eaten by us in the above code leaveMsg = true; } } } // Should the message we pulled from the queue? if (!leaveMsg) { if (WindowsAPI.GetMessage(ref msg, 0, 0, 0)) { WindowsAPI.TranslateMessage(ref msg); WindowsAPI.DispatchMessage(ref msg); } } else { leaveMsg = false; } } } } }
/// <summary> /// The main entry point for the MP2-ClientLauncher application. /// </summary> private static void Main(params string[] args) { Thread.CurrentThread.Name = "Main"; // Parse command line options var mpOptions = new CommandLineOptions(); var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Out); parser.ParseArgumentsStrict(args, mpOptions, () => Environment.Exit(1)); // Check if another instance is already running if (SingleInstanceHelper.IsAlreadyRunning(MUTEX_ID, out _mutex)) { _mutex = null; // Stop current instance Console.Out.WriteLine("Application already running."); Environment.Exit(2); } #if !DEBUG string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Team MediaPortal", "MP2-Client", "Log"); #endif //// todo: Make sure we're properly handling exceptions //DispatcherUnhandledException += OnUnhandledException; //AppDomain.CurrentDomain.UnhandledException += LauncherExceptionHandling.CurrentDomain_UnhandledException; // Start core services ILogger logger = null; try { // Check if user wants to override the default Application Data location. ApplicationCore.RegisterVitalCoreServices(true, mpOptions.DataDirectory); logger = ServiceRegistration.Get <ILogger>(); #if !DEBUG logPath = ServiceRegistration.Get <IPathManager>().GetPath("<LOG>"); #endif } catch (Exception e) { if (logger != null) { logger.Critical("Error starting application", e); } ApplicationCore.DisposeCoreServices(); throw; } // Start application logger.Info("Starting application"); try { if (TerminateProcess("ehtray")) { logger.Info("Terminating running instance(s) of ehtray.exe"); } IsAutoStartEnabled = !string.IsNullOrEmpty(WindowsAPI.GetAutostartApplicationPath(AUTOSTART_REGISTER_NAME, true)); if (!mpOptions.NoIcon) { InitTrayIcon(); } InitIpc(); InitMsgHandler(); Application.Run(); } catch (Exception e) { logger.Critical("Error executing application", e); } logger.Info("Exiting..."); CloseMsgHandler(); CloseIpc(); // Release mutex for single instance if (_mutex != null) { _mutex.ReleaseMutex(); } Application.Exit(); }
private static void SetHook() { hookId = WindowsAPI.SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelHookProc, IntPtr.Zero, 0); }
public IconView() { InitializeComponent(); WindowsAPI.SetWindowTheme(lvIcons.Handle, "explorer", 0); }
protected override void RegisterHook() { ScanDeadKeys(); proc = HookCallback; hookId = WindowsAPI.SetWindowsHookEx(WH_KEYBOARD_LL, proc, WindowsAPI.GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0); }
protected override void DeregisterHook() { WindowsAPI.UnhookWindowsHookEx(hookId); }
void UpdateSize() { Height = WindowsAPI.SendMessage(Handle, (int)RebarMessages.RB_GETBARHEIGHT, 0, 0) + 1; }
/// <summary> /// Broadcasts a <param name="messageId">message</param> through the system to inform an existing instance to show up. /// </summary> /// <param name="messageId">The id to a static windows message, which should be broadcasted.</param> public static void SwitchToCurrentInstance(uint messageId) { // Send our Win32 message to make the currently running instance // Jump on top of all the other windows WindowsAPI.PostMessage((IntPtr)WindowsAPI.HWND_BROADCAST, messageId, IntPtr.Zero, IntPtr.Zero); }
public MoreColumns() { InitializeComponent(); WindowsAPI.SetWindowTheme(lvColumns.Handle, "explorer", null); }
/// <summary> /// Single instance callback handler. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="SingleInstanceApplication.InstanceCallbackEventArgs"/> instance containing the event data.</param> private void SingleInstanceCallback(object sender, InstanceCallbackEventArgs args) { string StartUpLocation = KnownFolders.Libraries.ParsingName; RegistryKey rk = Registry.CurrentUser; RegistryKey rks = rk.OpenSubKey(@"Software\BExplorer", false); StartUpLocation = rks.GetValue(@"StartUpLoc", KnownFolders.Libraries.ParsingName).ToString(); if (args == null || Dispatcher == null) { return; } Action <bool> d = (bool x) => { var win = MainWindow as MainWindow; if (win == null) { return; } var hwnd = (HwndSource.FromVisual(win) as HwndSource).Handle; win.ApendArgs(args.CommandLineArgs); if (x) { ShellObject sho = null; if (args != null && args.CommandLineArgs != null) { if (args.CommandLineArgs.Length > 1 && args.CommandLineArgs[1] != null && args.CommandLineArgs[1] != "-minimized") { if (args.CommandLineArgs[1] != "t") { if (args.CommandLineArgs[1] == "nw") { MainWindow g = new MainWindow(); g.Show(); return; } else { win.Visibility = Visibility.Visible; if (win.WindowState == WindowState.Minimized) { WindowsAPI.ShowWindow(hwnd, (int)WindowsAPI.ShowCommands.SW_RESTORE); } String cmd = args.CommandLineArgs[1]; if (cmd.IndexOf("::") == 0) { sho = ShellObject.FromParsingName("shell:" + cmd); } else { sho = ShellObject.FromParsingName(args.CommandLineArgs[1].Replace("\"", "")); } } } else { win.Visibility = Visibility.Visible; if (win.WindowState == WindowState.Minimized) { WindowsAPI.ShowWindow(hwnd, (int)WindowsAPI.ShowCommands.SW_RESTORE); } sho = win.GetShellObjectFromLocation(StartUpLocation); } } else { win.Visibility = Visibility.Visible; if (win.WindowState == WindowState.Minimized) { WindowsAPI.ShowWindow(hwnd, (int)WindowsAPI.ShowCommands.SW_RESTORE); } sho = win.GetShellObjectFromLocation(StartUpLocation); } if (!isStartMinimized || win.tabControl1.Items.Count == 0) { sho.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly; sho.Thumbnail.CurrentSize = new Size(16, 16); ClosableTabItem newt = new ClosableTabItem(); newt.Header = sho.GetDisplayName(DisplayNameType.Default); newt.TabIcon = sho.Thumbnail.BitmapSource; newt.PreviewMouseMove += newt_PreviewMouseMove; newt.TabSelected += win.newt_TabSelected; newt.Path = sho; win.CloneTab(newt); } else { int RestoreTabs = (int)rks.GetValue(@"IsRestoreTabs", 1); if (RestoreTabs == 0) { win.tabControl1.Items.Clear(); sho.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly; sho.Thumbnail.CurrentSize = new Size(16, 16); ClosableTabItem newt = new ClosableTabItem(); newt.Header = sho.GetDisplayName(DisplayNameType.Default); newt.TabIcon = sho.Thumbnail.BitmapSource; newt.PreviewMouseMove += newt_PreviewMouseMove; newt.TabSelected += win.newt_TabSelected; newt.Path = sho; win.CloneTab(newt); } if (args.CommandLineArgs.Length > 1 && args.CommandLineArgs[1] != null) { String cmd = args.CommandLineArgs[1]; if (cmd.IndexOf("::") == 0) { sho = ShellObject.FromParsingName("shell:" + cmd); } else { sho = ShellObject.FromParsingName(args.CommandLineArgs[1].Replace("\"", "")); } sho.Thumbnail.FormatOption = ShellThumbnailFormatOption.IconOnly; sho.Thumbnail.CurrentSize = new Size(16, 16); ClosableTabItem newt = new ClosableTabItem(); newt.Header = sho.GetDisplayName(DisplayNameType.Default); newt.TabIcon = sho.Thumbnail.BitmapSource; newt.PreviewMouseMove += newt_PreviewMouseMove; newt.TabSelected += win.newt_TabSelected; newt.Path = sho; win.CloneTab(newt); } } rks.Close(); rk.Close(); win.Activate(); win.Topmost = true; // important win.Topmost = false; // important win.Focus(); // important } } }; Dispatcher.BeginInvoke(d, true); }
static private IntPtr GetGraphicsHDC(Graphics g) { IntPtr hdc = (g != null) ? g.GetHdc() : WindowsAPI.GetDC(IntPtr.Zero); return(hdc); }
/// <summary> /// 非置顶模式 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void untopmode(object sender, RoutedEventArgs e) { IntPtr intPtr = WindowsAPI.FindWindow(null, "夜神模拟器"); WindowsAPI.SetWindowPos(intPtr, 0, 0, 0, 0, 0, 1 | 2 | 0x20 | 0x4000 | 0x40); }
protected virtual void OnAccelChanged() { WindowsAPI.SendMessage(base.Handle, SpinControlMsg.UDM_SETACCEL, 1, ref m_stAccel); RaiseAccelChangedEvent(); }
void StartHook() { // Mouse hook WindowsAPI.HookProc mouseHookProc = new WindowsAPI.HookProc(MouseHook); mouseProcHandle = GCHandle.Alloc(mouseHookProc); mouseHookHandle = WindowsAPI.SetWindowsHookEx((int)WindowsHookCodes.WH_MOUSE, mouseHookProc, IntPtr.Zero, WindowsAPI.GetCurrentThreadId()); if (mouseHookHandle == IntPtr.Zero) { throw new SecurityException(); } }
protected virtual void OnBaseChanged() { WindowsAPI.SendMessage(base.Handle, (int)SpinControlMsg.UDM_SETBASE, m_iBase, 0); RaiseBaseChangedEvent(); }
public void BeginUpdate() { WindowsAPI.SendMessage(Handle, (int)Msg.WM_SETREDRAW, 0, 0); }
protected virtual void OnPosChanged() { WindowsAPI.SendMessage(base.Handle, (int)SpinControlMsg.UDM_SETPOS, 0, m_iPos); RaisePosChangedEvent(); }
internal void RemovePlaceHolder() { placeHolderAdded = false; REBARBANDINFO bandInfo = GetBandInfo(0, placeHolderToolBar); int result = WindowsAPI.SendMessage(Handle, (int)RebarMessages.RB_DELETEBAND, 0, 0); }
static HttpRangeChunk() { _userAgent = WindowsAPI.GetOsVersionString() + " HTTP/1.1 " + PRODUCT_VERSION; }
public void DrawBackground(Graphics g, Rectangle bounds, DrawItemState state, bool toplevel, bool hasicon, bool enabled) { bool selected = (state & DrawItemState.Selected) > 0; if (selected || ((state & DrawItemState.HotLight) > 0)) { if (toplevel && selected) { // draw toplevel, selected menuitem bounds.Inflate(-1, 0); g.FillRectangle(new SolidBrush(stripeColor), bounds); if (ColorUtil.UsingCustomColor) { GDIUtil.Draw3DRect(g, bounds, ColorUtil.VSNetBorderColor, ColorUtil.VSNetControlColor); } else { ControlPaint.DrawBorder3D(g, bounds.Left, bounds.Top, bounds.Width, bounds.Height, Border3DStyle.Flat, Border3DSide.Top | Border3DSide.Left | Border3DSide.Right); } } else { // draw menuitem hotlighted if (enabled) { g.FillRectangle(new SolidBrush(selectionColor), bounds); g.DrawRectangle(new Pen(borderColor), bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); } else { // Check if menu item was selected by using the mouse or the keyboard RECT rc = new RECT(); IntPtr parentHandle = Parent.Handle; uint index = (uint)Index; WindowsAPI.GetMenuItemRect(IntPtr.Zero, parentHandle, index, ref rc); Rectangle menuRect = new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); Point mp = Control.MousePosition; if (!menuRect.Contains(mp)) { // Menu was selected by using keyboard g.FillRectangle(new SolidBrush(bgColor), bounds); g.DrawRectangle(new Pen(borderColor), bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); } else { // Menu was selected by using mouse g.FillRectangle(new SolidBrush(stripeColor), bounds); bounds.X += STRIPE_WIDTH; bounds.Width -= STRIPE_WIDTH; g.FillRectangle(new SolidBrush(bgColor), bounds); } } } } else { if (!toplevel) { // draw menuitem, unselected g.FillRectangle(new SolidBrush(stripeColor), bounds); bounds.X += STRIPE_WIDTH; bounds.Width -= STRIPE_WIDTH; g.FillRectangle(new SolidBrush(bgColor), bounds); } else { // draw toplevel, unselected menuitem g.FillRectangle(SystemBrushes.Control, bounds); } } }
private void RefreshSystemTray() { IntPtr hShellTrayWnd = WindowsAPI.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", IntPtr.Zero); WindowsAPI.InvalidateRect(hShellTrayWnd, IntPtr.Zero, 1); }
public override void SendMouseEvent(WindowsAPI.MOUSEEVENTF mouseevent, System.Drawing.Point? location = null) { throw new NotImplementedException(); }
private void SetTimerSettings(ToolTipsDelays flag, int time) { WindowsAPI.SendMessage(m_tooltip.Handle, (int)ToolTipMsg.TTM_SETDELAYTIME, (int)flag, time); }
public override void SendMouseEvent(WindowsAPI.MOUSEEVENTF mouseevent, Point? location = null) { var click = new Point(); if(location.HasValue) { click = location.Value; } else { // if not specified find middlepoint of this window/control var size = this.Size; click.X = size.Width / 2; click.Y = size.Height / 2; } var lparam = new IntPtr(WindowsAPI.MakeInt((short)click.X, (short)click.Y)); WindowsAPI.PostMessage(this.Handle, (uint)mouseevent, new IntPtr(1), lparam); }
public override Window.WindowItemBase GetForeGroundWindow() { return(new WindowItem(WindowsAPI.GetForegroundWindow())); }