コード例 #1
0
ファイル: WindowHandler.cs プロジェクト: bartsides/StayPut
 private static bool IsCorrectSetting(Process process, WindowSetting setting)
 {
     if (!process.ProcessName.Equals(setting.ProcessName))
     {
         return(false);
     }
     if (setting.WindowTitle != null && !setting.WindowTitle.Equals(GetWindowTitle(new HandleRef(process, process.MainWindowHandle))))
     {
         return(false);
     }
     return(true);
 }
コード例 #2
0
ファイル: WindowHandler.cs プロジェクト: bartsides/StayPut
        private static void GetCurrentWindowSettings()
        {
            List <WindowSetting> settings = new List <WindowSetting>();

            Process[] processes = Process.GetProcesses(".");
            foreach (var process in processes)
            {
                IntPtr handle = process.MainWindowHandle;
                if (handle != IntPtr.Zero)
                {
                    HandleRef handleRef = new HandleRef(process, handle);
                    RECT      rect;
                    if (!GetWindowRect(handleRef, out rect))
                    {
                        continue;
                    }

                    WindowSetting ws = new WindowSetting {
                        ProcessName = process.ProcessName,
                        WindowTitle = GetWindowTitle(handleRef),
                        X           = rect.Left,
                        Y           = rect.Top,
                        Width       = rect.Right - rect.Left,
                        Height      = rect.Bottom - rect.Top
                    };

                    Console.WriteLine(ws);

                    settings.Add(ws);
                }
            }

            string settingsString = string.Empty;

            foreach (WindowSetting setting in settings)
            {
                settingsString += setting.Serialize() + "," + Environment.NewLine;
            }

            Clipboard.SetText(settingsString);
        }