示例#1
0
        /// <summary>
        /// If a Window is added or removed to the Watching collection
        /// </summary>
        /// <param name="mWindow">WindowHandle.Window to from a Process</param>
        /// <param name="bEnable">Enable or Disable the WindowHandle.Window</param>
        private void Events_WatchingWindows(WindowHandle.Window mWindow, bool bEnable)
        {
            try
            {
                if (bEnable)
                {
                    mWindow.WindowRefreshThread(true);

                    mWindow.WindowTitleChanged        += Window_WindowTitleChanged;
                    mWindow.WindowStyleChanged        += Window_WindowStyleChanged;
                    mWindow.WindowProcessExit         += Window_WindowProcessExit;
                    mWindow.WindowPositionSizeChanged += Window_WindowPositionSizeChanged;
                    mWindow.WindowExStyleChanged      += Window_WindowExStyleChanged;
                    mWindow.WindowDataTextChanged     += Window_WindowDataTextChanged;
                    mWindow.WindowBasicChanged        += Window_WindowBasicChanged;
                }
                else
                {
                    mWindow.WindowRefreshThread(false);

                    mWindow.WindowTitleChanged        -= Window_WindowTitleChanged;
                    mWindow.WindowStyleChanged        -= Window_WindowStyleChanged;
                    mWindow.WindowProcessExit         -= Window_WindowProcessExit;
                    mWindow.WindowPositionSizeChanged -= Window_WindowPositionSizeChanged;
                    mWindow.WindowExStyleChanged      -= Window_WindowExStyleChanged;
                    mWindow.WindowDataTextChanged     -= Window_WindowDataTextChanged;
                    mWindow.WindowBasicChanged        -= Window_WindowBasicChanged;
                }
            }
            catch (Exception ex)
            {
                Log.cLogger.Log(ex);
            }
        }
示例#2
0
        /// <summary>
        /// looks if a Process exist already which is in the Watcher Config and add it's Window for the Watcher
        /// </summary>
        private void WindowToWatch()
        {
            try
            {
                if (myGPrc != null)
                {
                    bool _bWinFound = false;

                    WindowHandle.Window[] _AWin = new WindowHandle.Window[myGPrc.HWND.LHWND.Count];
                    myGPrc.HWND.LHWND.CopyTo(_AWin);

                    for (int i = 0; i < _AWin.Length; i++)
                    {
                        _bWinFound = false;
                        if (myProcessToWatch.ContainsKey(_AWin[i].Processname))
                        {
                            foreach (AWC.WindowHandle.Window _WinIn in myWindowsForWatching)
                            {
                                if (_WinIn.Processname == _AWin[i].Processname)
                                {
                                    _bWinFound = true;
                                    break;
                                }
                            }
                            if (!_bWinFound)
                            {
                                //add Window to the Window for Watch
                                myWindowsForWatching.Add(_AWin[i]);
                                Events_WatchingWindows(_AWin[i], true);
                                Log.cLogger.Log(string.Format("Add Window from Process:{0} to Windows for Watching list", _AWin[i].Processname));
                            }
                        }
                    }
                    if (_AWin != null)
                    {
                        for (int i = 0; i < _AWin.Length; i++)
                        {
                            _AWin[i].Dispose();
                            _AWin[i] = null;
                        }
                        _AWin = null;
                    }
                }
            } catch (Exception ex)
            {
                Log.cLogger.Log(ex);
            }
        }
示例#3
0
        private void LoadWindow(IntPtr intHWnd)
        {
            try
            {
                if (intHWnd != IntPtr.Zero)
                {
                    if (myWindow != null)
                    {
                        myWindow.WindowRefreshThread(false);
                        myWindow = null;
                    }

                    AWC.WindowHandle.Window myHWND = HWND.HWNDList.FindHWNDByIntPTR(intHWnd);

                    if (myHWND != null)
                    {
                        myWindow = new WindowHandle.Window(myHWND.Process);
                        if (myWindow != null)
                        {
                            myWindow.WindowDataTextChanged += myWindow_WindowDataTextChanged;
                            myWindow.WindowRefreshThread(true);
                        }
                        else
                        {
                            Log.cLogger.Log(string.Format("Init Window failed with IntPtr:'{0}' Name:'{1}'", myHWND.Handle, myHWND.Title));
                        }
                    }
                    else
                    {
                        Log.cLogger.Log("Can't load new Window in WindowDataOutput because don't find process from handle(intptr)");
                    }
                }
                else
                {
                    Log.cLogger.Log("Can't load new Window in WindowDataOutput because handle(intptr) is Zero");
                }
            } catch (Exception ex)
            {
                Log.cLogger.Log(ex);
            }
        }
示例#4
0
文件: pEventArgs.cs 项目: Chtau/AWC
 public ProcessEventArgs(WindowHandle.Window myWin)
 {
     myWindow = myWin;
 }
示例#5
0
        /// <summary>
        /// handle/execute the Event for a Window
        /// </summary>
        /// <param name="win">the Window which raised the event</param>
        /// <param name="exConfig">the Parameter for the execution</param>
        protected virtual void OnLoadedEvent(WindowHandle.Window win, ExternalToolConfig exConfig)
        {
            try
            {
                if (win != null)
                {
                    Log.cLogger.Log(string.Format("Loaded event raised for Process:'{0}'", win.Processname));

                    switch (exConfig.ProcessEventExecuteTyp)
                    {
                    case ProcessEventExecuteTyp.Command:
                        Log.cLogger.Log(string.Format("Command execute event , Process:'{0}' ParamString:'{1}'", win.Processname, exConfig.ProcessStartParameter));
                        System.Diagnostics.Process.Start(exConfig.ProcessStartParameter);
                        break;

                    case ProcessEventExecuteTyp.Position:
                        string[] strPos = exConfig.ProcessStartParameter.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                        int      iXCor  = win.Rectangle.X;
                        int      iYCor  = win.Rectangle.Y;
                        if (strPos.Length > 0)
                        {
                            for (int i = 0; i < strPos.Length; i++)
                            {
                                if (strPos[i].StartsWith("X:"))
                                {
                                    iXCor = Convert.ToInt32(strPos[i].Replace("X:", "").Trim());
                                }
                                else if (strPos[i].StartsWith("Y:"))
                                {
                                    iYCor = Convert.ToInt32(strPos[i].Replace("Y:", "").Trim());
                                }
                                else
                                {
                                    Log.cLogger.Log(string.Format("Position execute event has a unkown parameter, Process:'{0}' ParamString:'{1}' Current Param:'{2}'", win.Processname, exConfig.ProcessStartParameter, strPos[i]));
                                }
                            }

                            Log.cLogger.Log(string.Format("Position execute event change Value (new X Cor:'{2}', new Y Cor:'{3}'), Process:'{0}' ParamString:'{1}'", win.Processname, exConfig.ProcessStartParameter, iXCor.ToString(), iYCor.ToString()));
                            win.SetSizeLocation(iXCor, iYCor, win.Rectangle.Width, win.Rectangle.Height);
                        }
                        else
                        {
                            Log.cLogger.Log(string.Format("Position execute event has no arguments, Process:'{0}' ParamString:'{1}'", win.Processname, exConfig.ProcessStartParameter));
                        }

                        break;

                    case ProcessEventExecuteTyp.Size:
                        string[] strSize = exConfig.ProcessStartParameter.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                        int      iWidth  = win.Rectangle.Width;
                        int      iHeight = win.Rectangle.Height;
                        if (strSize.Length > 0)
                        {
                            for (int i = 0; i < strSize.Length; i++)
                            {
                                if (strSize[i].StartsWith("H:"))
                                {
                                    iHeight = Convert.ToInt32(strSize[i].Replace("H:", "").Trim());
                                }
                                else if (strSize[i].StartsWith("W:"))
                                {
                                    iWidth = Convert.ToInt32(strSize[i].Replace("W:", "").Trim());
                                }
                                else
                                {
                                    Log.cLogger.Log(string.Format("Size execute event has a unkown parameter, Process:'{0}' ParamString:'{1}' Current Param:'{2}'", win.Processname, exConfig.ProcessStartParameter, strSize[i]));
                                }
                            }

                            Log.cLogger.Log(string.Format("Size execute event change Value (new Width:'{2}', new Height:'{3}'), Process:'{0}' ParamString:'{1}'", win.Processname, exConfig.ProcessStartParameter, iWidth.ToString(), iHeight.ToString()));
                            win.SetSizeLocation(win.Rectangle.X, win.Rectangle.Y, iWidth, iHeight);
                        }
                        else
                        {
                            Log.cLogger.Log(string.Format("Size execute event has no arguments, Process:'{0}' ParamString:'{1}'", win.Processname, exConfig.ProcessStartParameter));
                        }
                        break;

                    case ProcessEventExecuteTyp.Border:
                        int    iBorder  = Convert.ToInt32(exConfig.ProcessStartParameter);
                        IntPtr ipBorder = IntPtr.Zero;
                        switch (iBorder)
                        {
                        case 1:
                            ipBorder = (IntPtr)WindowHandle.Enums.WindowStyles.MAXIMIZEBOX;
                            break;

                        case 2:
                            ipBorder = (IntPtr)WindowHandle.Enums.WindowStyles.OVERLAPPEDWINDOW;
                            break;

                        case 3:
                            ipBorder = (IntPtr)WindowHandle.Enums.WindowStyles.SIZEFRAME;
                            break;

                        case 4:
                            ipBorder = (IntPtr)WindowHandle.Enums.WindowStyles.BORDER;
                            break;

                        default:
                            ipBorder = (IntPtr)WindowHandle.Enums.WindowStyles.MAXIMIZEBOX;
                            break;
                        }

                        Log.cLogger.Log(string.Format("Border execute event change Value (new Bordertyp:'{2}' Border IntPtr:'{3}'), Process:'{0}' ParamString:'{1}'", win.Processname, exConfig.ProcessStartParameter, iBorder.ToString(), ipBorder.ToString()));
                        win.SetBorderStyle(ipBorder);
                        break;

                    default:
                        Log.cLogger.Log(string.Format("Command execute event , Process:'{0}' ParamString:'{1}'", win.Processname, exConfig.ProcessStartParameter));
                        System.Diagnostics.Process.Start(exConfig.ProcessStartParameter);
                        break;
                    }
                }
                else
                {
                    Log.cLogger.Log("Loaded event can't raised Window data is null");
                }
            } catch (Exception ex)
            {
                Log.cLogger.Log(ex);
            }
        }