using System; using System.Drawing; using System.Windows.Forms; // The 'windowHandle' parameter will contain the window handle for the: // - Active window when run by hotkey // - Window Location target when run by a Window Location rule // - TitleBar Button owner when run by a TitleBar Button // - Jump List owner when run from a Taskbar Jump List // - Currently focused window if none of these match public static class DisplayFusionFunction { public static void Run(IntPtr windowHandle) { //get the width from the user using(WindowPercentInput dialog = new WindowPercentInput()) { if(dialog.ShowDialog() != DialogResult.OK) return; Rectangle monitorBounds = BFS.Monitor.GetMonitorBoundsByWindow(windowHandle); try { BFS.Window.SetSize(windowHandle, (int)(monitorBounds.Width * (Convert.ToInt32(dialog.WidthPercent) / 100m)), (int)(monitorBounds.Height * (Convert.ToInt32(dialog.HeightPercent) / 100m))); } catch { } } } private class WindowPercentInput : Form { private TextBox txtWidth = new TextBox(); private TextBox txtHeight = new TextBox(); internal string WidthPercent { get { return txtWidth.Text; } } internal string HeightPercent { get { return txtHeight.Text; } } internal WindowPercentInput() { Label label2 = new Label(); Label label1 = new Label(); Button btnOK = new Button(); Button btnCancel = new Button(); this.SuspendLayout(); this.txtWidth.Location = new Point(16, 48); this.txtWidth.Size = new Size(144, 20); this.txtWidth.TabIndex = 1; this.txtHeight.Location = new Point(176, 48); this.txtHeight.Size = new Size(144, 20); this.txtHeight.TabIndex = 3; label2.Location = new Point(160, 48); label2.Size = new Size(16, 23); label2.TabIndex = 2; label2.Text = "X"; label2.TextAlign = ContentAlignment.MiddleLeft; btnOK.Location = new Point(152, 80); btnOK.Size = new Size(80, 24); btnOK.TabIndex = 4; btnOK.Text = "OK"; btnCancel.Location = new Point(240, 80); btnCancel.Size = new Size(80, 24); btnCancel.TabIndex = 5; btnCancel.Text = "Cancel"; btnCancel.UseVisualStyleBackColor = true; label1.Location = new Point(16, 16); label1.Size = new Size(296, 23); label1.TabIndex = 0; label1.Text = "Enter the width and height in percent:"; label1.TextAlign = ContentAlignment.MiddleLeft; this.ClientSize = new System.Drawing.Size(337, 117); this.Controls.Add(this.txtHeight); this.Controls.Add(this.txtWidth); this.Controls.Add(label1); this.Controls.Add(btnCancel); this.Controls.Add(btnOK); this.Controls.Add(label2); this.MinimizeBox = false; this.MaximizeBox = false; this.ShowIcon = false; this.ShowInTaskbar = false; this.ResumeLayout(false); this.Text = "Set Window Size"; btnOK.Click += btnOK_Click; btnCancel.Click += btnCancel_Click; this.Load += OnLoad; this.AcceptButton = btnOK; this.CancelButton = btnCancel; } private void OnLoad(object sender, EventArgs e) { BFS.Window.Focus(this.Handle); BFS.Window.SetAlwaysOnTop(this.Handle, true); this.txtWidth.Focus(); } private void btnOK_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; this.Close(); } private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } } }