diff --git a/PreviewHandler.Designer.cs b/PreviewHandler.Designer.cs index 08da05b..1ba46a1 100644 --- a/PreviewHandler.Designer.cs +++ b/PreviewHandler.Designer.cs @@ -63,14 +63,15 @@ namespace PreviewToy this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); this.panel1 = new System.Windows.Forms.Panel(); this.panel2 = new System.Windows.Forms.Panel(); - this.zoom_anchor_lable = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.panel3 = new System.Windows.Forms.Panel(); + this.zoom_anchor_lable = new System.Windows.Forms.Label(); this.panel5 = new System.Windows.Forms.Panel(); this.previews_check_listbox = new System.Windows.Forms.CheckedListBox(); this.label1 = new System.Windows.Forms.Label(); this.panel4 = new System.Windows.Forms.Panel(); this.aero_status_label = new System.Windows.Forms.Label(); + this.option_track_client_windows = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.previewToyMainBindingSource)).BeginInit(); this.flowLayoutPanel1.SuspendLayout(); this.panel1.SuspendLayout(); @@ -85,7 +86,7 @@ namespace PreviewToy this.option_hide_active.AutoSize = true; this.option_hide_active.Checked = true; this.option_hide_active.CheckState = System.Windows.Forms.CheckState.Checked; - this.option_hide_active.Location = new System.Drawing.Point(3, 3); + this.option_hide_active.Location = new System.Drawing.Point(3, 26); this.option_hide_active.Name = "option_hide_active"; this.option_hide_active.Size = new System.Drawing.Size(184, 17); this.option_hide_active.TabIndex = 1; @@ -98,7 +99,7 @@ namespace PreviewToy this.option_hide_all_if_not_right_type.AutoSize = true; this.option_hide_all_if_not_right_type.Checked = true; this.option_hide_all_if_not_right_type.CheckState = System.Windows.Forms.CheckState.Checked; - this.option_hide_all_if_not_right_type.Location = new System.Drawing.Point(3, 49); + this.option_hide_all_if_not_right_type.Location = new System.Drawing.Point(3, 72); this.option_hide_all_if_not_right_type.Name = "option_hide_all_if_not_right_type"; this.option_hide_all_if_not_right_type.Size = new System.Drawing.Size(242, 17); this.option_hide_all_if_not_right_type.TabIndex = 2; @@ -111,7 +112,7 @@ namespace PreviewToy this.option_unique_layout.AutoSize = true; this.option_unique_layout.Checked = true; this.option_unique_layout.CheckState = System.Windows.Forms.CheckState.Checked; - this.option_unique_layout.Location = new System.Drawing.Point(3, 72); + this.option_unique_layout.Location = new System.Drawing.Point(3, 95); this.option_unique_layout.Name = "option_unique_layout"; this.option_unique_layout.Size = new System.Drawing.Size(185, 17); this.option_unique_layout.TabIndex = 3; @@ -138,7 +139,7 @@ namespace PreviewToy this.option_always_on_top.AutoSize = true; this.option_always_on_top.Checked = true; this.option_always_on_top.CheckState = System.Windows.Forms.CheckState.Checked; - this.option_always_on_top.Location = new System.Drawing.Point(3, 26); + this.option_always_on_top.Location = new System.Drawing.Point(3, 49); this.option_always_on_top.Name = "option_always_on_top"; this.option_always_on_top.RightToLeft = System.Windows.Forms.RightToLeft.No; this.option_always_on_top.Size = new System.Drawing.Size(137, 17); @@ -152,7 +153,7 @@ namespace PreviewToy this.option_show_thumbnail_frames.AutoSize = true; this.option_show_thumbnail_frames.Checked = true; this.option_show_thumbnail_frames.CheckState = System.Windows.Forms.CheckState.Checked; - this.option_show_thumbnail_frames.Location = new System.Drawing.Point(99, 195); + this.option_show_thumbnail_frames.Location = new System.Drawing.Point(99, 218); this.option_show_thumbnail_frames.Name = "option_show_thumbnail_frames"; this.option_show_thumbnail_frames.RightToLeft = System.Windows.Forms.RightToLeft.No; this.option_show_thumbnail_frames.Size = new System.Drawing.Size(127, 17); @@ -211,7 +212,7 @@ namespace PreviewToy this.option_show_overlay.AutoSize = true; this.option_show_overlay.Checked = true; this.option_show_overlay.CheckState = System.Windows.Forms.CheckState.Checked; - this.option_show_overlay.Location = new System.Drawing.Point(3, 195); + this.option_show_overlay.Location = new System.Drawing.Point(3, 218); this.option_show_overlay.Name = "option_show_overlay"; this.option_show_overlay.RightToLeft = System.Windows.Forms.RightToLeft.No; this.option_show_overlay.Size = new System.Drawing.Size(90, 17); @@ -329,6 +330,7 @@ namespace PreviewToy // // flowLayoutPanel1 // + this.flowLayoutPanel1.Controls.Add(this.option_track_client_windows); this.flowLayoutPanel1.Controls.Add(this.option_hide_active); this.flowLayoutPanel1.Controls.Add(this.option_always_on_top); this.flowLayoutPanel1.Controls.Add(this.option_hide_all_if_not_right_type); @@ -344,13 +346,14 @@ namespace PreviewToy this.flowLayoutPanel1.Name = "flowLayoutPanel1"; this.flowLayoutPanel1.Size = new System.Drawing.Size(252, 349); this.flowLayoutPanel1.TabIndex = 25; + this.flowLayoutPanel1.Paint += new System.Windows.Forms.PaintEventHandler(this.flowLayoutPanel1_Paint); // // panel1 // this.panel1.Controls.Add(this.option_sync_size); this.panel1.Controls.Add(this.option_sync_size_x); this.panel1.Controls.Add(this.option_sync_size_y); - this.panel1.Location = new System.Drawing.Point(3, 95); + this.panel1.Location = new System.Drawing.Point(3, 118); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(246, 26); this.panel1.TabIndex = 26; @@ -362,20 +365,11 @@ namespace PreviewToy this.panel2.Controls.Add(this.zoom_anchor_lable); this.panel2.Controls.Add(this.option_zoom_on_hover); this.panel2.Controls.Add(this.option_zoom_factor); - this.panel2.Location = new System.Drawing.Point(3, 127); + this.panel2.Location = new System.Drawing.Point(3, 150); this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(246, 62); this.panel2.TabIndex = 27; // - // zoom_anchor_lable - // - this.zoom_anchor_lable.AutoSize = true; - this.zoom_anchor_lable.Location = new System.Drawing.Point(134, 31); - this.zoom_anchor_lable.Name = "zoom_anchor_lable"; - this.zoom_anchor_lable.Size = new System.Drawing.Size(41, 13); - this.zoom_anchor_lable.TabIndex = 30; - this.zoom_anchor_lable.Text = "Anchor"; - // // label2 // this.label2.AutoSize = true; @@ -401,11 +395,20 @@ namespace PreviewToy this.panel3.Size = new System.Drawing.Size(60, 57); this.panel3.TabIndex = 28; // + // zoom_anchor_lable + // + this.zoom_anchor_lable.AutoSize = true; + this.zoom_anchor_lable.Location = new System.Drawing.Point(134, 31); + this.zoom_anchor_lable.Name = "zoom_anchor_lable"; + this.zoom_anchor_lable.Size = new System.Drawing.Size(41, 13); + this.zoom_anchor_lable.TabIndex = 30; + this.zoom_anchor_lable.Text = "Anchor"; + // // panel5 // this.panel5.Controls.Add(this.previews_check_listbox); this.panel5.Controls.Add(this.label1); - this.panel5.Location = new System.Drawing.Point(3, 218); + this.panel5.Location = new System.Drawing.Point(3, 241); this.panel5.Name = "panel5"; this.panel5.Size = new System.Drawing.Size(246, 100); this.panel5.TabIndex = 31; @@ -433,7 +436,7 @@ namespace PreviewToy // this.panel4.Controls.Add(this.aero_status_label); this.panel4.Controls.Add(this.forum_url); - this.panel4.Location = new System.Drawing.Point(3, 324); + this.panel4.Location = new System.Drawing.Point(3, 347); this.panel4.Name = "panel4"; this.panel4.Size = new System.Drawing.Size(246, 21); this.panel4.TabIndex = 30; @@ -447,6 +450,17 @@ namespace PreviewToy this.aero_status_label.TabIndex = 0; this.aero_status_label.Text = "label4"; // + // option_track_client_windows + // + this.option_track_client_windows.AutoSize = true; + this.option_track_client_windows.Location = new System.Drawing.Point(3, 3); + this.option_track_client_windows.Name = "option_track_client_windows"; + this.option_track_client_windows.Size = new System.Drawing.Size(127, 17); + this.option_track_client_windows.TabIndex = 32; + this.option_track_client_windows.Text = "Track client locations"; + this.option_track_client_windows.UseVisualStyleBackColor = true; + this.option_track_client_windows.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged); + // // PreviewToyHandler // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -514,6 +528,7 @@ namespace PreviewToy private Panel panel4; private Label aero_status_label; private Panel panel5; + private CheckBox option_track_client_windows; } diff --git a/PreviewHandler.cs b/PreviewHandler.cs index c7c2d59..c445a53 100644 --- a/PreviewHandler.cs +++ b/PreviewHandler.cs @@ -27,6 +27,7 @@ namespace PreviewToy private Dictionary> unique_layouts; private Dictionary flat_layout; + private Dictionary client_layout; private bool is_initialized; @@ -34,6 +35,20 @@ namespace PreviewToy Dictionary xml_bad_to_ok_chars; + [DllImport("user32.dll")] + private static extern int GetWindowRect(IntPtr hwnd, out RECT rect); + + [DllImport("user32.dll")] + public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); + + private struct RECT + { + public int Left; + public int Top; + public int Right; + public int Bottom; + } + public enum zoom_anchor_t { NW = 0, @@ -66,6 +81,7 @@ namespace PreviewToy unique_layouts = new Dictionary>(); flat_layout = new Dictionary(); + client_layout = new Dictionary(); ignoring_size_sync = new Stopwatch(); ignoring_size_sync.Start(); @@ -122,6 +138,8 @@ namespace PreviewToy option_show_overlay.Checked = Properties.Settings.Default.show_overlay; + option_track_client_windows.Checked = Properties.Settings.Default.track_client_positions; + // disable/enable zoom suboptions option_zoom_factor.Enabled = Properties.Settings.Default.zoom_on_hover; foreach (var kv in zoom_anchor_button_map) @@ -163,6 +181,25 @@ namespace PreviewToy previews_check_listbox.BeginUpdate(); previews_check_listbox.Items.Add(previews[process.MainWindowHandle]); previews_check_listbox.EndUpdate(); + + if (client_layout.ContainsKey(process.MainWindowTitle)) + { + int left = Math.Abs(client_layout[process.MainWindowTitle].Left); + int right = Math.Abs(client_layout[process.MainWindowTitle].Right); + int client_width = Math.Abs(left - right); + + int top = Math.Abs(client_layout[process.MainWindowTitle].Top); + int bottom = Math.Abs(client_layout[process.MainWindowTitle].Bottom); + int client_height = Math.Abs(top - bottom); + + MoveWindow( + process.MainWindowHandle, + client_layout[process.MainWindowTitle].Left, + client_layout[process.MainWindowTitle].Top, + client_width, + client_height, + true); + } } else if (previews.ContainsKey(process.MainWindowHandle)) //or update the preview titles @@ -256,6 +293,21 @@ namespace PreviewToy flat_layout[ParseXElement(el)] = new Point(Convert.ToInt32(el.Element("x").Value), Convert.ToInt32(el.Element("y").Value)); } } + + if (File.Exists("client_layout.xml")) + { + XElement rootElement = XElement.Load("client_layout.xml"); + foreach (var el in rootElement.Elements()) + { + RECT rect = new RECT(); + rect.Left = Convert.ToInt32(el.Element("x1").Value); + rect.Top = Convert.ToInt32(el.Element("y1").Value); + rect.Right = Convert.ToInt32(el.Element("x2").Value); + rect.Bottom = Convert.ToInt32(el.Element("y2").Value); + + client_layout[ParseXElement(el)] = rect; + } + } } private void store_layout() @@ -288,7 +340,7 @@ namespace PreviewToy XElement el2 = new XElement("flat_layout"); foreach (var clientKV in flat_layout) { - if (clientKV.Key == "" || clientKV.Key == "..." ) + if (clientKV.Key == "" || clientKV.Key == "...") { continue; } @@ -299,6 +351,23 @@ namespace PreviewToy } el2.Save("flat_layout.xml"); + + XElement el3 = new XElement("client_layout"); + foreach (var clientKV in client_layout) + { + if (clientKV.Key == "" || clientKV.Key == "...") + { + continue; + } + XElement layout = MakeXElement(clientKV.Key); + layout.Add(new XElement("x1", clientKV.Value.Left)); + layout.Add(new XElement("y1", clientKV.Value.Top)); + layout.Add(new XElement("x2", clientKV.Value.Right)); + layout.Add(new XElement("y2", clientKV.Value.Bottom)); + el3.Add(layout); + } + + el3.Save("client_layout.xml"); } private void handle_unique_layout(Preview preview, String last_known_active_window) @@ -326,8 +395,24 @@ namespace PreviewToy } + private void update_client_locations() + { + Process[] processes = Process.GetProcessesByName("ExeFile"); + List processHandles = new List(); + + foreach (Process process in processes) + { + RECT rect = new RECT(); + GetWindowRect(process.MainWindowHandle, out rect); + + client_layout[process.MainWindowTitle] = rect; + } + } + + public void preview_did_switch() { + update_client_locations(); store_layout(); //todo: check if it actually changed ... foreach (KeyValuePair entry in previews) { @@ -669,5 +754,15 @@ namespace PreviewToy refresh_thumbnails(); } + private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e) + { + + } + + private void checkBox1_CheckedChanged(object sender, EventArgs e) + { + + } + } } \ No newline at end of file diff --git a/PreviewHandler.resx b/PreviewHandler.resx index c73ced0..a26b34e 100644 --- a/PreviewHandler.resx +++ b/PreviewHandler.resx @@ -120,6 +120,9 @@ 17, 17 + + 182 + diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index 6436fde..bebc05b 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18047 +// Runtime Version:4.0.30319.0 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -12,7 +12,7 @@ namespace PreviewToy.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -190,5 +190,17 @@ namespace PreviewToy.Properties { this["zoom_anchor"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool track_client_positions { + get { + return ((bool)(this["track_client_positions"])); + } + set { + this["track_client_positions"] = value; + } + } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index 2d36137..085d139 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -44,5 +44,8 @@ 0 + + False + \ No newline at end of file diff --git a/app.config b/app.config index fa89957..5d2dec4 100644 --- a/app.config +++ b/app.config @@ -49,6 +49,9 @@ 0 + + False +