Exemplo n.º 1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            _windowList = new List<IntPtr>();
            _windowNames = new List<string>();

            //SetStyle(ControlStyles.UserPaint, true);
            //SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);

            // Set up the glass effect using padding as the defining glass region
            if (Win32.DwmIsCompositionEnabled())
            {
                _glassMargins = new Margins();
                _glassMargins.Top = -1;
                _glassMargins.Left = -1;
                _glassMargins.Bottom = -1;
                _glassMargins.Right = -1;
                Win32.DwmExtendFrameIntoClientArea(this.Handle, ref _glassMargins);
            }

            Win32.EnumWindowsProc enumWindowsDelegate = new Win32.EnumWindowsProc(EnumWindows);
            Win32.EnumWindows(enumWindowsDelegate, new IntPtr());
            windowList.DataSource = _windowNames;
        }
Exemplo n.º 2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            _windowList  = new List <IntPtr>();
            _windowNames = new List <string>();

            //SetStyle(ControlStyles.UserPaint, true);
            //SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            //SetStyle(ControlStyles.SupportsTransparentBackColor, true);

            // Set up the glass effect using padding as the defining glass region
            if (Win32.DwmIsCompositionEnabled())
            {
                _glassMargins        = new Margins();
                _glassMargins.Top    = -1;
                _glassMargins.Left   = -1;
                _glassMargins.Bottom = -1;
                _glassMargins.Right  = -1;
                Win32.DwmExtendFrameIntoClientArea(this.Handle, ref _glassMargins);
            }

            Win32.EnumWindowsProc enumWindowsDelegate = new Win32.EnumWindowsProc(EnumWindows);
            Win32.EnumWindows(enumWindowsDelegate, new IntPtr());
            windowList.DataSource = _windowNames;
        }
Exemplo n.º 3
0
        public MainForm()
        {
            InitializeComponent();

            //WindowState = FormWindowState.Minimized;
            //ShowInTaskbar = false;

            EnumWindow = new Win32.EnumWindowsProc(OnEnumWindow);

            TrayIcon.ContextMenu = new ContextMenu(new MenuItem[] {
                new MenuItem("About", (s, e) => MessageBox.Show(
            @"We're gathered here tonight to have a fight but I say man that's not all right.
            Violence is not the solution it just adds to all this pollution.
            Lets talk about our problems one on one then we can have some fun.
            Well I'm David Wain and I'm here to say there's got to be a better way.
            Fighting's not good activity painting, drawing, and dancing yo.
            Now I'd like to introduce my friend Michael Show.
            AKKKAHAHAHAHA HA HAWAHAHABOOM! CHACKALACKABOOMCHACKALAKA BOOM SHAKALAKA
            BOOM SHAKALAKA GET UP!!! GET UP!!! GET UP!!! YEEEAAAAA!!!
            Yah! Now rap is in we hope you agree that the way to go is posativity our
            message is simple lets all get along that's why we call this rap the
            friendship song! the friendship song! the friendship song!", "Old Fashioned Fun" )),

                new MenuItem("Exit", (s, e) => Close())
            });

            TrayIcon.Icon = Properties.Resources.bike;
            TrayIcon.Visible = true;
        }
        public static List <IntPtr> GetWindowHandle(int processId)
        {
            ProcessWindowHandleObtainer obtainer = new ProcessWindowHandleObtainer();

            obtainer._processId = (uint)processId;
            Win32.EnumWindowsProc proc = new Win32.EnumWindowsProc(obtainer.EnumWindowsCallback);
            Win32.EnumWindows(proc, 0);
            return(obtainer._windowHandles);
        }
 /// <summary>
 /// 在WINDOWS任务管理器里隐藏一行 需要一直调用 会被任务管理器刷新出来
 /// </summary>
 /// <param name="p_Name">名称 如QQ.exe</param>
 public void HideTaskmgrListOfName(string p_Name)
 {
     System.Diagnostics.Process[] _ProcessList = System.Diagnostics.Process.GetProcessesByName("taskmgr");
     for (int i = 0; i != _ProcessList.Length; i++)
     {
         if (_ProcessList[i].MainWindowTitle.Contains("任务管理器"))
         {
             m_ProcessID = _ProcessList[i].Id;
             Win32.EnumWindowsProc _EunmControl = new Win32.EnumWindowsProc(NetEnumControl);
             Win32.EnumChildWindows(_ProcessList[i].MainWindowHandle, _EunmControl, 0);
         }
     }
 }
Exemplo n.º 6
0
    /// <summary>
    /// Initializes a new instance of the <see cref="WindowList"/> class.
    /// </summary>
    /// <param name="listClasses">if set to <c>true</c> [list classes].</param>
    public WindowList(bool listClasses)
    {
      _listClasses = listClasses;

      InitializeComponent();

      if (listClasses)
        Text = "Class List";
      else
        Text = "Window List";

      _ewp = AddWindow;

      PopulateList();
    }
        private IntPtr EnumWindowByName(Win32.EnumWindowsProc filter)
        {
            IntPtr WindowHwnd = IntPtr.Zero;

            Win32.EnumWindows(delegate(IntPtr hwnd, IntPtr lparam)
            {
                if (filter(hwnd, lparam))
                {
                    WindowHwnd = hwnd;
                    return(false);
                }
                return(true);
            }, IntPtr.Zero);
            return(WindowHwnd);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Forces the process into focus (once).
        /// </summary>
        /// <returns></returns>
        public bool Force()
        {
            Process process = Process.GetProcessById(_processId);

            if (process == null || process.HasExited)
            {
                throw new InvalidOperationException("Cannot force focus, process is not running");
            }

            //if (_forcerThread != null)
            //throw new InvalidOperationException("Cannot force focus, Forcer thread already running");

            _waitHandle = new AutoResetEvent(false);

            try
            {
                Win32.EnumWindowsProc ewc = CheckWindow;

                while (!process.HasExited)
                {
                    int focusedId = Win32.GetForegroundWindowPID();
                    if (focusedId != _processId)
                    {
                        _windowHandle = IntPtr.Zero;
                        Win32.EnumerateWindows(ewc, IntPtr.Zero);

                        bool waitResult = _waitHandle.WaitOne(5000, false);
                        if (waitResult && _windowHandle != IntPtr.Zero)
                        {
                            return(Win32.SetForegroundWindow(_windowHandle, true));
                        }
                    }

                    Thread.Sleep(5000);
                }
            }
            finally
            {
                _waitHandle.Close();
                _waitHandle = null;
            }

            return(false);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WindowList"/> class.
        /// </summary>
        /// <param name="listClasses">if set to <c>true</c> [list classes].</param>
        public WindowList(bool listClasses)
        {
            _listClasses = listClasses;

            InitializeComponent();

            if (listClasses)
            {
                Text = "Class List";
            }
            else
            {
                Text = "Window List";
            }

            _ewp = AddWindow;

            PopulateList();
        }
Exemplo n.º 10
0
        public void Refresh()
        {
            _oldWindows = new HashSet <IntPtr>();
            _oldWindows.UnionWith((from w in _windows select w.Hwnd).ToArray());
            _position = 0;

            Win32.EnumWindowsProc proc = new Win32.EnumWindowsProc(EnumWindowsCallback);
            IntPtr hDesktop            = IntPtr.Zero; // Current Desktop
            bool   success             = Win32.EnumDesktopWindows(hDesktop, proc, IntPtr.Zero);

            if (!success)
            {
                throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
            }

            foreach (var hwnd in _oldWindows)
            {
                _windows.RemoveAll(w => (w.Hwnd == hwnd));
            }
        }
Exemplo n.º 11
0
            public override IEnumerable <Tuple <IntPtr, object> > AllForms(IntPtr display, Xwt.Backends.IWindowFrameBackend window)
            {
                var found = new List <IntPtr>();

                Win32.EnumWindowsProc func = (hwnd, lparam) =>
                {
                    if ((Win32.GetWindowLongPtr(hwnd, -16) & 0x10000000L) != 0) // WS_STYLE&WS_VISIBLE
                    {
                        found.Add(hwnd);
                    }
                    return(true);
                };
                Win32.EnumWindows(func, IntPtr.Zero);

                if (Xwt.Toolkit.CurrentEngine.Type == ToolkitType.Wpf)
                {
                    return(found.Select(_h =>
                    {
                        var obj = Win32.swi_hwndsource.InvokeStatic("FromHwnd", _h);
                        obj = obj?.GetType().GetPropertyValue(obj, "RootVisual");
                        return new Tuple <IntPtr, object>(_h, obj ?? _h);
                    }));
                }
                else if (Xwt.Toolkit.CurrentEngine.Type == ToolkitType.Gtk)
                {
                    var d = CreateGtkLookup();

                    return(found.Select(_h =>
                    {
                        d.TryGetValue(_h, out object obj);
                        //   var obj = Win32.swi_hwndsource.InvokeStatic("FromHwnd", _h);
                        //    obj = obj?.GetType().GetPropertyValue(obj, "RootVisual");
                        return new Tuple <IntPtr, object>(_h, obj ?? _h);
                    }));
                }
                else
                {
                    return(found.Select(_h => new Tuple <IntPtr, object>(_h, _h)));
                }
            }
Exemplo n.º 12
0
        private void EnumWindows()
        {
            treeViewEx1.Nodes.Clear();

            StringBuilder caption   = new StringBuilder(260);
            StringBuilder className = new StringBuilder(260);

            IntPtr hwnd = Win32.GetDesktopWindow();

            Win32.GetClassName(hwnd, className, 260);
            Win32.GetWindowText(hwnd, caption, 260);

            TreeNode node = new TreeNode("Window " + ((Int32)hwnd).ToString("X8") + "~" + caption + "~" + className, 0, 0);

            node.Tag = (Int32)hwnd;
            treeViewEx1.Nodes.Add(node);

            Win32.EnumWindowsProc callback = new Win32.EnumWindowsProc(EnumWindowsProc);
            Win32.EnumWindows(callback, 0);

            treeViewEx1.Nodes[0].Expand();
        }
Exemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MenuForm"/> class.
        /// </summary>
        public MenuForm()
        {
            InitializeComponent();

            _ewp = AddTask;

            CreateMainImageList();

            _launch             = new ListViewItem(UITextLaunch, 0);
            _launch.ToolTipText = DescLaunch;
            _launch.Tag         = Menus.Launch;

            _taskSwitch             = new ListViewItem(UITextTasks, 1);
            _taskSwitch.ToolTipText = DescTasks;
            _taskSwitch.Tag         = Menus.Tasks;

            _macro             = new ListViewItem(UITextMacros, 2);
            _macro.ToolTipText = DescMacros;
            _macro.Tag         = Menus.Macros;

            _system             = new ListViewItem(UITextSystem, 3);
            _system.ToolTipText = DescSystem;
            _system.Tag         = Menus.System;
        }
Exemplo n.º 14
0
        private void ExecuteWindowMessage(SettingsKeyboardKeyAction action)
        {
            SettingsKeyboardKeyTypedActionWindowMessage windowMessage = action.WindowMessage;

            WriteStatusMessage("Sending window message: " + windowMessage.GetDetails());


            var processIds = new HashSet <uint>();

            if (!string.IsNullOrEmpty(windowMessage.ProcessName))
            {
                var processes = Process.GetProcessesByName(windowMessage.ProcessName);
                foreach (var p in processes)
                {
                    processIds.Add((uint)p.Id);
                }
            }

            var windowHandles = new List <IntPtr>();

            Win32.EnumWindowsProc proc = new Win32.EnumWindowsProc((IntPtr hwnd, int lParam) =>
            {
                if (processIds.Count > 0)
                {
                    uint pid;
                    Win32.GetWindowThreadProcessId(hwnd, out pid);
                    if (!processIds.Contains(pid))
                    {
                        return(true);
                    }
                }

                if (!string.IsNullOrEmpty(windowMessage.WindowClass))
                {
                    StringBuilder windowClass = new StringBuilder(Win32.GETWINDOWTEXT_MAXLENGTH);
                    Win32.GetClassName(hwnd, windowClass, windowClass.Capacity);
                    if (!windowMessage.WindowClass.Equals(windowClass.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        return(true);
                    }
                }

                if (!string.IsNullOrEmpty(windowMessage.WindowName))
                {
                    StringBuilder windowTitle = new StringBuilder(Win32.GETWINDOWTEXT_MAXLENGTH);
                    Win32.GetWindowText(hwnd, windowTitle, windowTitle.Capacity);
                    if (!windowMessage.WindowName.Equals(windowTitle.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        return(true);
                    }
                }

                windowHandles.Add(hwnd);
                return(true);
            });
            Win32.EnumWindows(proc, 0);

            if (windowHandles.Count == 0)
            {
                if (windowMessage.NotFoundAction != SettingsKeyboardKeyActionType.WindowMessage)
                {
                    ProcessAction(action, windowMessage.NotFoundAction);
                }
                return;
            }

            foreach (var hwnd in windowHandles)
            {
                System.Diagnostics.Debug.WriteLine("SendMessage(" +
                                                   "0x" + ((uint)hwnd.ToInt32()).ToString("x") +
                                                   ", 0x" + windowMessage.Message.ToString("x") +
                                                   ", 0x" + windowMessage.WParam.ToString("x") +
                                                   ", 0x" + windowMessage.LParam.ToString("x") + ")");
                var result = Win32.SendMessage(hwnd, windowMessage.Message, new IntPtr(windowMessage.WParam), new IntPtr(windowMessage.LParam));
                WriteStatusMessage("SendMessage result: 0x" + ((uint)result.ToInt32()).ToString("x"));
            }
        }
Exemplo n.º 15
0
 public static extern int EnumWindows(Win32.EnumWindowsProc ewp, IntPtr lParam);
Exemplo n.º 16
0
    /// <summary>
    /// Initializes a new instance of the <see cref="MenuForm"/> class.
    /// </summary>
    public MenuForm()
    {
      InitializeComponent();

      _ewp = AddTask;

      CreateMainImageList();

      _launch = new ListViewItem(UITextLaunch, 0);
      _launch.ToolTipText = DescLaunch;
      _launch.Tag = Menus.Launch;

      _taskSwitch = new ListViewItem(UITextTasks, 1);
      _taskSwitch.ToolTipText = DescTasks;
      _taskSwitch.Tag = Menus.Tasks;

      _macro = new ListViewItem(UITextMacros, 2);
      _macro.ToolTipText = DescMacros;
      _macro.Tag = Menus.Macros;

      _system = new ListViewItem(UITextSystem, 3);
      _system.ToolTipText = DescSystem;
      _system.Tag = Menus.System;
    }