From caeae8c96661da2fd69d8cb9a00dd2939d8e3063 Mon Sep 17 00:00:00 2001 From: Alex-TIMEHACK Date: Tue, 29 Aug 2017 18:43:33 +0100 Subject: Resize system! --- Histacom2.Engine/Histacom2.Engine.csproj | 9 ++ .../Template/ResizeOverlay.Designer.cs | 78 +++++++++++++ Histacom2.Engine/Template/ResizeOverlay.cs | 35 ++++++ Histacom2.Engine/Template/ResizeOverlay.resx | 123 +++++++++++++++++++++ Histacom2.Engine/Template/WinClassic.Designer.cs | 8 ++ Histacom2.Engine/Template/WinClassic.cs | 94 +++++++++------- Histacom2.Engine/Template/WinClassic.resx | 48 ++++---- 7 files changed, 331 insertions(+), 64 deletions(-) create mode 100644 Histacom2.Engine/Template/ResizeOverlay.Designer.cs create mode 100644 Histacom2.Engine/Template/ResizeOverlay.cs create mode 100644 Histacom2.Engine/Template/ResizeOverlay.resx (limited to 'Histacom2.Engine') diff --git a/Histacom2.Engine/Histacom2.Engine.csproj b/Histacom2.Engine/Histacom2.Engine.csproj index 37c4489..361672e 100644 --- a/Histacom2.Engine/Histacom2.Engine.csproj +++ b/Histacom2.Engine/Histacom2.Engine.csproj @@ -54,6 +54,12 @@ + + Form + + + ResizeOverlay.cs + Form @@ -102,6 +108,9 @@ PublicResXFileCodeGenerator Resources.Designer.cs + + ResizeOverlay.cs + Win9XBSOD.cs diff --git a/Histacom2.Engine/Template/ResizeOverlay.Designer.cs b/Histacom2.Engine/Template/ResizeOverlay.Designer.cs new file mode 100644 index 0000000..8d76c26 --- /dev/null +++ b/Histacom2.Engine/Template/ResizeOverlay.Designer.cs @@ -0,0 +1,78 @@ +namespace Histacom2.Engine.Template +{ + partial class ResizeOverlay + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.outline = new System.Windows.Forms.PictureBox(); + this.tmrMove = new System.Windows.Forms.Timer(this.components); + ((System.ComponentModel.ISupportInitialize)(this.outline)).BeginInit(); + this.SuspendLayout(); + // + // outline + // + this.outline.BackColor = System.Drawing.Color.Transparent; + this.outline.Location = new System.Drawing.Point(194, 158); + this.outline.Name = "outline"; + this.outline.Size = new System.Drawing.Size(300, 158); + this.outline.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + this.outline.TabIndex = 0; + this.outline.TabStop = false; + this.outline.Paint += new System.Windows.Forms.PaintEventHandler(this.outline_Paint); + // + // tmrMove + // + this.tmrMove.Interval = 20; + this.tmrMove.Tick += new System.EventHandler(this.tmrMove_Tick); + // + // ResizeOverlay + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(1)))), ((int)(((byte)(0)))), ((int)(((byte)(1))))); + this.ClientSize = new System.Drawing.Size(800, 600); + this.Controls.Add(this.outline); + this.DoubleBuffered = true; + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "ResizeOverlay"; + this.Tag = "ignoreFormOnTaskbar"; + this.Text = "ResizeOverlay"; + this.TopMost = true; + this.TransparencyKey = System.Drawing.Color.FromArgb(((int)(((byte)(1)))), ((int)(((byte)(0)))), ((int)(((byte)(1))))); + this.WindowState = System.Windows.Forms.FormWindowState.Maximized; + ((System.ComponentModel.ISupportInitialize)(this.outline)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.PictureBox outline; + public System.Windows.Forms.Timer tmrMove; + } +} \ No newline at end of file diff --git a/Histacom2.Engine/Template/ResizeOverlay.cs b/Histacom2.Engine/Template/ResizeOverlay.cs new file mode 100644 index 0000000..ca8a5e4 --- /dev/null +++ b/Histacom2.Engine/Template/ResizeOverlay.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Histacom2.Engine.Template +{ + public partial class ResizeOverlay : Form + { + public Rectangle ToDraw = new Rectangle(); + + public ResizeOverlay() + { + InitializeComponent(); + } + + private void tmrMove_Tick(object sender, EventArgs e) + { + outline.Bounds = ToDraw; // Pens.Gray, ToDraw); + } + + private void outline_Paint(object sender, PaintEventArgs e) + { + e.Graphics.FillRectangle(Brushes.Gray, 0, 0, outline.Width, 4); // Top border + e.Graphics.FillRectangle(Brushes.Gray, 0, outline.Height - 4, outline.Width, 4); // Bottom border + e.Graphics.FillRectangle(Brushes.Gray, 0, 0, 4, outline.Height); // Left border + e.Graphics.FillRectangle(Brushes.Gray, outline.Width - 4, 0, 4, outline.Height); // Right border + } + } +} diff --git a/Histacom2.Engine/Template/ResizeOverlay.resx b/Histacom2.Engine/Template/ResizeOverlay.resx new file mode 100644 index 0000000..10340d0 --- /dev/null +++ b/Histacom2.Engine/Template/ResizeOverlay.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Histacom2.Engine/Template/WinClassic.Designer.cs b/Histacom2.Engine/Template/WinClassic.Designer.cs index 9092609..593cfd6 100644 --- a/Histacom2.Engine/Template/WinClassic.Designer.cs +++ b/Histacom2.Engine/Template/WinClassic.Designer.cs @@ -162,6 +162,7 @@ this.toprightcorner.TabIndex = 6; this.toprightcorner.MouseDown += new System.Windows.Forms.MouseEventHandler(this.border_MouseDown); this.toprightcorner.MouseMove += new System.Windows.Forms.MouseEventHandler(this.toprightcorner_MouseMove); + this.toprightcorner.MouseUp += new System.Windows.Forms.MouseEventHandler(this.border_MouseUp); // // bottomrightcorner // @@ -174,6 +175,7 @@ this.bottomrightcorner.TabIndex = 4; this.bottomrightcorner.MouseDown += new System.Windows.Forms.MouseEventHandler(this.border_MouseDown); this.bottomrightcorner.MouseMove += new System.Windows.Forms.MouseEventHandler(this.bottomrightcorner_MouseMove); + this.bottomrightcorner.MouseUp += new System.Windows.Forms.MouseEventHandler(this.border_MouseUp); // // bottomleftcorner // @@ -186,6 +188,7 @@ this.bottomleftcorner.TabIndex = 2; this.bottomleftcorner.MouseDown += new System.Windows.Forms.MouseEventHandler(this.border_MouseDown); this.bottomleftcorner.MouseMove += new System.Windows.Forms.MouseEventHandler(this.bottomleftcorner_MouseMove); + this.bottomleftcorner.MouseUp += new System.Windows.Forms.MouseEventHandler(this.border_MouseUp); // // topleftcorner // @@ -197,6 +200,7 @@ this.topleftcorner.TabIndex = 1; this.topleftcorner.MouseDown += new System.Windows.Forms.MouseEventHandler(this.border_MouseDown); this.topleftcorner.MouseMove += new System.Windows.Forms.MouseEventHandler(this.topleftcorner_MouseMove); + this.topleftcorner.MouseUp += new System.Windows.Forms.MouseEventHandler(this.border_MouseUp); // // left // @@ -209,6 +213,7 @@ this.left.TabIndex = 3; this.left.MouseDown += new System.Windows.Forms.MouseEventHandler(this.border_MouseDown); this.left.MouseMove += new System.Windows.Forms.MouseEventHandler(this.left_MouseMove); + this.left.MouseUp += new System.Windows.Forms.MouseEventHandler(this.border_MouseUp); // // bottom // @@ -222,6 +227,7 @@ this.bottom.TabIndex = 5; this.bottom.MouseDown += new System.Windows.Forms.MouseEventHandler(this.border_MouseDown); this.bottom.MouseMove += new System.Windows.Forms.MouseEventHandler(this.bottom_MouseMove); + this.bottom.MouseUp += new System.Windows.Forms.MouseEventHandler(this.border_MouseUp); // // right // @@ -234,6 +240,7 @@ this.right.TabIndex = 7; this.right.MouseDown += new System.Windows.Forms.MouseEventHandler(this.border_MouseDown); this.right.MouseMove += new System.Windows.Forms.MouseEventHandler(this.right_MouseMove); + this.right.MouseUp += new System.Windows.Forms.MouseEventHandler(this.border_MouseUp); // // top // @@ -247,6 +254,7 @@ this.top.TabIndex = 8; this.top.MouseDown += new System.Windows.Forms.MouseEventHandler(this.border_MouseDown); this.top.MouseMove += new System.Windows.Forms.MouseEventHandler(this.top_MouseMove); + this.top.MouseUp += new System.Windows.Forms.MouseEventHandler(this.border_MouseUp); // // WinClassic // diff --git a/Histacom2.Engine/Template/WinClassic.cs b/Histacom2.Engine/Template/WinClassic.cs index 67a0322..3133798 100644 --- a/Histacom2.Engine/Template/WinClassic.cs +++ b/Histacom2.Engine/Template/WinClassic.cs @@ -14,13 +14,13 @@ namespace Histacom2.Engine.Template } public Font fnt; + public ResizeOverlay resizer = new ResizeOverlay(); public bool resizable = true; public bool closeDisabled = false; public bool isActive = true; public bool Resizing = false; public Bitmap ResizingBmp = null; - public const int WM_NCLBUTTONDOWN = 0xA1; public const int WM_SYSCOMMAND = 0x0112; public const int HT_CAPTION = 0x2; @@ -74,8 +74,9 @@ namespace Histacom2.Engine.Template { if (e.Button == MouseButtons.Left) { - if (resizable) this.Size = new Size(MousePosition.X - this.Location.X, this.Size.Height); - this.Invalidate(); + var toDraw = resizer.ToDraw; + if (resizable) toDraw.Width = MousePosition.X - this.Location.X; + resizer.ToDraw = toDraw; } } @@ -83,9 +84,10 @@ namespace Histacom2.Engine.Template { if (e.Button == MouseButtons.Left) { - if (resizable) this.Width = ((this.Width + this.Location.X) - Cursor.Position.X); - if (resizable)this.Location = new Point(Cursor.Position.X, this.Location.Y); - this.Invalidate(); + var toDraw = resizer.ToDraw; + if (resizable) toDraw.Width = ((this.Width + this.Location.X) - Cursor.Position.X); + if (resizable) toDraw.X = Cursor.Position.X; + resizer.ToDraw = toDraw; } } @@ -93,8 +95,10 @@ namespace Histacom2.Engine.Template { if (e.Button == MouseButtons.Left) { - if (resizable) this.Size = new Size(this.Size.Width, MousePosition.Y - this.Location.Y); - this.Invalidate(); + var toDraw = resizer.ToDraw; + if (resizable) toDraw.Y = this.Location.Y; + if (resizable) toDraw.Height = ((toDraw.Height + toDraw.Top) + Cursor.Position.Y); + resizer.ToDraw = toDraw; } } @@ -102,8 +106,10 @@ namespace Histacom2.Engine.Template { if (e.Button == MouseButtons.Left) { - if (resizable) this.Size = new Size(MousePosition.X - this.Location.X, MousePosition.Y - this.Location.Y); - this.Invalidate(); + var toDraw = resizer.ToDraw; + if (resizable) toDraw.Width = MousePosition.X - this.Location.X; + if (resizable) toDraw.Height = MousePosition.Y - this.Location.Y; + resizer.ToDraw = toDraw; } } @@ -111,10 +117,11 @@ namespace Histacom2.Engine.Template { if (e.Button == MouseButtons.Left) { - if (resizable) this.Width = ((this.Width + this.Location.X) - Cursor.Position.X); - if (resizable) this.Height = (Cursor.Position.Y - this.Location.Y); - if (resizable) this.Location = new Point(Cursor.Position.X, this.Location.Y); - this.Invalidate(); + var toDraw = resizer.ToDraw; + if (resizable) toDraw.Width = ((toDraw.Width + toDraw.Location.X) - Cursor.Position.X); + if (resizable) toDraw.Height = Cursor.Position.Y - this.Location.Y; + if (resizable) toDraw.X = Cursor.Position.X; + resizer.ToDraw = toDraw; } } @@ -122,11 +129,12 @@ namespace Histacom2.Engine.Template { if (e.Button == MouseButtons.Left) { - if (resizable) this.Width = ((this.Width + this.Location.X) - Cursor.Position.X); - if (resizable) this.Location = new Point(Cursor.Position.X, this.Location.Y); - if (resizable) this.Height = ((this.Height + this.Location.Y) - Cursor.Position.Y); - if (resizable) this.Location = new Point(this.Location.X, Cursor.Position.Y); - this.Invalidate(); + var toDraw = resizer.ToDraw; + if (resizable) toDraw.Width = ((this.Width + this.Location.X) - Cursor.Position.X); + if (resizable) toDraw.X = Cursor.Position.X; + if (resizable) toDraw.Height = ((this.Height + this.Location.Y) - Cursor.Position.Y); + if (resizable) toDraw.Y = Cursor.Position.Y; + resizer.ToDraw = toDraw; } } @@ -134,9 +142,10 @@ namespace Histacom2.Engine.Template { if(e.Button == MouseButtons.Left) { - if(resizable) this.Height = ((this.Height + this.Location.Y) - Cursor.Position.Y); - if(resizable) this.Location = new Point(this.Location.X, Cursor.Position.Y); - this.Invalidate(); + var toDraw = resizer.ToDraw; + if (resizable) toDraw.Height = ((toDraw.Height + toDraw.Top) - Cursor.Position.Y); + if (resizable) toDraw.Y = Cursor.Position.Y; + resizer.ToDraw = toDraw; } } @@ -144,10 +153,12 @@ namespace Histacom2.Engine.Template { if (e.Button == MouseButtons.Left) { - if (resizable) this.Width = (Cursor.Position.X - this.Location.X); - if (resizable) this.Height = ((this.Location.Y - Cursor.Position.Y) + this.Height); - if (resizable) this.Location = new Point(this.Location.X, Cursor.Position.Y); - this.Update(); + var toDraw = resizer.ToDraw; + if (resizable) toDraw.Width = (Cursor.Position.X - toDraw.X); + if (resizable) toDraw.Height = ((toDraw.Height + toDraw.Top) - Cursor.Position.Y); + if (resizable) toDraw.X = Cursor.Position.X; + if (resizable) toDraw.Y = Cursor.Position.Y; + resizer.ToDraw = toDraw; } } @@ -160,6 +171,15 @@ namespace Histacom2.Engine.Template } } + private void border_MouseUp(object sender, MouseEventArgs e) + { + this.Bounds = resizer.ToDraw; + resizer.tmrMove.Stop(); + resizer.Close(); + + resizer = new ResizeOverlay(); + } + private void border_MouseDown(object sender, MouseEventArgs e) { var cursor = this.PointToClient(Cursor.Position); @@ -174,22 +194,16 @@ namespace Histacom2.Engine.Template else if (right.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF002, 0); else if (bottom.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF006, 0); - /* Now we need to fix this weird artificating! - To lempamo: This is probably the best way I can think of the fix this - I can take a picture of the window as it is and then just draw that - and once you mouseup I will go back to the actual form - I'll have a boolean called Resizing which tells the form on paint to just draw the overlay! - */ + // Now we need to fix this weird artificating! - var screen = Screen.PrimaryScreen; + resizer.tmrMove.Start(); + resizer.Show(); - using (var bitmap = new Bitmap(this.Bounds.Width, this.Bounds.Height)) - using (var graphics = Graphics.FromImage(bitmap)) - { - graphics.CopyFromScreen(new Point(this.Bounds.Left, this.Bounds.Top), new Point(0, 0), this.Bounds.Size); - Resizing = true; - ResizingBmp = bitmap; - } + resizer.ToDraw = this.Bounds; + + // However this defocuses the window which we don't want + + WinClassic_Activated(null, null); } public bool max = false; diff --git a/Histacom2.Engine/Template/WinClassic.resx b/Histacom2.Engine/Template/WinClassic.resx index 394031d..6876b17 100644 --- a/Histacom2.Engine/Template/WinClassic.resx +++ b/Histacom2.Engine/Template/WinClassic.resx @@ -118,30 +118,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAOCAIAAACpTQvdAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wwAADsMBx2+oZAAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMzQDW3oAAAA+SURBVChTY/hP - CmAAAiB1nzjQ0NCA0HDgwAEQBwcAygIBNTRAJNDAqAY0DbgAdg0EAUIDkEUkAGkgDTAwAACYPGiagsMD - PwAAAABJRU5ErkJggg== - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAOCAIAAACpTQvdAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wwAADsMBx2+oZAAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMzQDW3oAAAA5SURBVChTY/hP - CmAAAiB1nzjQ0NCA0HCACDCqASqGF2DRAOKjAog4BFBDA36A0ABkEQlAGkgDDAwAKPmlWmNluNoAAAAA - SUVORK5CYII= - - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAOCAIAAACpTQvdAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - wwAADsMBx2+oZAAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMzQDW3oAAABcSURBVChTrY/R - DcAgCERvdEbrJh2lPU+SYkINRt+PSN6J4FkBhMddw8y+wFUgCbQ70OtO7OQTJLgRa/L7JWmOt8RsB8mD - TQ5NkFbeQcLwauzMdkjZCLAq0gJrAC8niIXaIK89FAAAAABJRU5ErkJggg== - - iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO @@ -196,6 +172,30 @@ iVBORw0KGgoAAAANSUhEUgAAAAEAAAAECAIAAADAusJtAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO wwAADsMBx2+oZAAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMzQDW3oAAAAVSURBVBhXYzh8 /DTD////wfTh46cBUSgJ/bC/izUAAAAASUVORK5CYII= + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAOCAIAAACpTQvdAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMzQDW3oAAAA+SURBVChTY/hP + CmAAAiB1nzjQ0NCA0HDgwAEQBwcAygIBNTRAJNDAqAY0DbgAdg0EAUIDkEUkAGkgDTAwAACYPGiagsMD + PwAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAOCAIAAACpTQvdAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMzQDW3oAAAA5SURBVChTY/hP + CmAAAiB1nzjQ0NCA0HCACDCqASqGF2DRAOKjAog4BFBDA36A0ABkEQlAGkgDDAwAKPmlWmNluNoAAAAA + SUVORK5CYII= + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAOCAIAAACpTQvdAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMzQDW3oAAABcSURBVChTrY/R + DcAgCERvdEbrJh2lPU+SYkINRt+PSN6J4FkBhMddw8y+wFUgCbQ70OtO7OQTJLgRa/L7JWmOt8RsB8mD + TQ5NkFbeQcLwauzMdkjZCLAq0gJrAC8niIXaIK89FAAAAABJRU5ErkJggg== \ No newline at end of file -- cgit v1.2.3