예제 #1
0
 public static WindowInfo GetWindowInfoFromProc(Process proc, IntPtr handle, ProcessOptions options = null, string winTitle = "")
 {
     if (proc != null)
     {
         var           dimensions = GetHandleDimensions(handle);
         StringBuilder sb         = new StringBuilder(1024);
         var           title      = string.IsNullOrWhiteSpace(winTitle) ? proc.MainWindowTitle : winTitle;
         WinAPIWrapper.GetClassName(proc.MainWindowHandle, sb, sb.Capacity);
         if (options == null)
         {
             return(new WindowInfo()
             {
                 Name = proc.ProcessName,
                 ModName = proc.MainModule.ModuleName,
                 WinClass = sb.ToString(),
                 Title = title,
                 FileName = proc.MainModule.FileName,
                 IndexNum = 0,
                 XValue = dimensions.Left,
                 YValue = dimensions.Top,
                 Width = dimensions.Right - dimensions.Left,
                 Height = dimensions.Bottom - dimensions.Top
             });
         }
         else
         {
             return(new WindowInfo()
             {
                 Name = proc.ProcessName,
                 ModName = proc.MainModule.ModuleName,
                 WinClass = sb.ToString(),
                 Title = options.IgnoreProcessTitle ? "*" : title,
                 FileName = proc.MainModule.FileName,
                 IndexNum = 0,
                 XValue = dimensions.Left,
                 YValue = dimensions.Top,
                 Width = dimensions.Right - dimensions.Left,
                 Height = dimensions.Bottom - dimensions.Top
             });
         }
     }
     else
     {
         return(new WindowInfo()
         {
             Name = "NULL",
             ModName = "NULL",
             Title = "NULL",
             FileName = "NULL",
             IndexNum = -1,
             XValue = -1,
             YValue = -1,
             Width = -1,
             Height = -1
         });
     }
 }
예제 #2
0
 public static DetailedProcess Create(Process process, IntPtr handle)
 {
     return(new DetailedProcess()
     {
         Handle = handle,
         Name = process.ProcessName,
         Title = WinAPIWrapper.GetWindowText(handle)
     });
 }
예제 #3
0
        public static WindowListItem Create(Process process, IntPtr handle)
        {
            var title = WinAPIWrapper.GetWindowText(handle);

            return(new WindowListItem()
            {
                Process = process,
                Handle = handle,
                Title = title,
                Display = $"{process.ProcessName} | {title}"
            });
        }
예제 #4
0
 public static WinAPIWrapper.RECT GetHandleDimensions(IntPtr handle)
 {
     WinAPIWrapper.RECT dimensions = new WinAPIWrapper.RECT();
     WinAPIWrapper.GetWindowRect(handle, ref dimensions);
     return(dimensions);
 }
예제 #5
0
 public static WinAPIWrapper.RECT GetProcessDimensions(Process proc)
 {
     WinAPIWrapper.RECT dimensions = new WinAPIWrapper.RECT();
     WinAPIWrapper.GetWindowRect(proc.MainWindowHandle, ref dimensions);
     return(dimensions);
 }
예제 #6
0
파일: Actions.cs 프로젝트: rwobig93/Panacea
        public static bool MoveProcessHandle(WindowItem selectedWindow, Process process = null)
        {
            bool moveAll     = false;
            bool windowMoved = false;

            try
            {
                /// Title is a wildcard, lets move ALL THE WINDOWS!!!
                if (selectedWindow.WindowInfo.Title == "*")
                {
                    moveAll = true;
                    uDebugLogAdd($"WindowInfo title for {selectedWindow.WindowInfo.Name} is {selectedWindow.WindowInfo.Title} so we will be MOVING ALL THE WINDOWS!!!!");
                }
                /// Title isn't a wildcard, lets only move the windows we want
                else
                {
                    uDebugLogAdd($"WindowInfo title for {selectedWindow.WindowInfo.Name} is {selectedWindow.WindowInfo.Title} so I can only move matching handles... :(");
                }

                List <DetailedProcess> foundList = new List <DetailedProcess>();
                if (process == null)
                {
                    foreach (var proc in Process.GetProcessesByName(selectedWindow.WindowInfo.Name))
                    {
                        foreach (var handle in WinAPIWrapper.EnumerateProcessWindowHandles(proc.Id))
                        {
                            try
                            {
                                var detProc = DetailedProcess.Create(proc, handle);
                                foundList.Add(detProc);
                                uDebugLogAdd($"Added to list | [{detProc.Handle}]{detProc.Name} :: {detProc.Title}");
                            }
                            catch (Exception ex)
                            {
                                uDebugLogAdd($"Unable to add handle to the list | [{handle}]{proc.ProcessName}: {ex.Message}");
                            }
                        }
                    }
                }
                else
                {
                    foreach (var handle in WinAPIWrapper.EnumerateProcessWindowHandles(process.Id))
                    {
                        try
                        {
                            var detProc = DetailedProcess.Create(process, handle);
                            foundList.Add(detProc);
                            uDebugLogAdd($"Added to list | [{detProc.Handle}]{detProc.Name} :: {detProc.Title}");
                        }
                        catch (Exception ex)
                        {
                            uDebugLogAdd($"Unable to add handle to the list | [{handle}]{process.ProcessName}: {ex.Message}");
                        }
                    }
                }
                if (moveAll)
                {
                    foreach (var detProc in foundList)
                    {
                        try
                        {
                            if (Toolbox.settings.ActiveWindowList.Find(x =>
                                                                       x.WindowInfo.Name == detProc.Name &&
                                                                       x.WindowInfo.Title == detProc.Title
                                                                       ) == null)
                            {
                                uDebugLogAdd($"Moving handle | [{detProc.Handle}]{detProc.Name} :: {detProc.Title}");
                                WinAPIWrapper.MoveWindow(detProc.Handle, selectedWindow.WindowInfo.XValue, selectedWindow.WindowInfo.YValue, selectedWindow.WindowInfo.Width, selectedWindow.WindowInfo.Height, true);
                                windowMoved = true;
                            }
                        }
                        catch (ArgumentException) { }
                        catch (Exception ex)
                        {
                            uDebugLogAdd($"Unable to move handle window | [{detProc.Handle}]{detProc.Name} {detProc.Title}: {ex.Message}");
                        }
                    }
                }
                else
                {
                    foreach (var detProc in foundList)
                    {
                        try
                        {
                            if (detProc.Name == selectedWindow.WindowInfo.Name &&
                                detProc.Title == selectedWindow.WindowInfo.Title)
                            {
                                uDebugLogAdd($"Matched window & title, moving: [{detProc.Handle}]{detProc.Name} | {detProc.Title}");
                                WinAPIWrapper.MoveWindow(detProc.Handle, selectedWindow.WindowInfo.XValue, selectedWindow.WindowInfo.YValue, selectedWindow.WindowInfo.Width, selectedWindow.WindowInfo.Height, true);
                                windowMoved = true;
                            }
                        }
                        catch (ArgumentException) { }
                        catch (Exception ex)
                        {
                            uDebugLogAdd($"Unable to move handle window | [{detProc.Handle}]{detProc.Name} {detProc.Title}: {ex.Message}");
                        }
                    }
                }
            }
            catch (ArgumentException) { }
            catch (Exception ex)
            {
                LogException(ex);
            }
            return(windowMoved);
        }