Write a screen capture program similar to QQ

xiaoxiao2021-03-06  14

I have been working for a long time last night, it is actually very bored.

Just make a program, realize the grip function like QQ

Using system.drawing; using system.collections; using system.bomponentmodel; using system.windows.forms; using system.Runtime.interopServices;

Namespace Howk.forms {///

/// CaptureForm's summary description. /// public class capTureform: system.windows.Forms.form {/// // // Required designer variable. /// private system.componentmodel.container components = null;

Point op; Rectangle area = Rectangle.Empty; private Image img; public CaptureForm () {this.SetStyle (ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true); InitializeComponent (); this.Bounds = System.Windows. Forms.screen.primaryScreen.bounds;

THIS.BACKGROUNDIMAGE = this.getdestopImage ();} public image image {get {returnimg;}}

///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) {components.dispose ();}} Base.Dispose

private Image GetDestopImage () {Rectangle area = System.Windows.Forms.Screen.PrimaryScreen.Bounds; Bitmap bm = new Bitmap (area.Width, area.Height); Graphics g = Graphics.FromImage (bm);

System.intptr P = g.GethDC (); INTPTR C = getDesktopWindow (); //gowk.common.api.sendMessage(C, Gowk.common.api.wm_print, pen ,new INTPTR (gowk.common.api.prf_client | GOWK.COMMON.API.PRF_NONCLIENT | GOWK.COMMON.API.PRF_CHILDREN | GOWK.COMMON.API.PRF_ERASEBKGND); System.intptr DDC = GetDC (C); GOWK.COMMON.API.bitblt (p, 0 ,0 , this.width, this.height, DDC, 0, 0, gow.common.api.srccopy; gow.common.api.releaseDC (C, DDC); G.ReleaseHDC (P); Return BM;} #region The code ///

///////////////////////////////////-designer supports - Do not use the code editor to modify the // / this method. /// private void initializecomponent () {/// CaptureForm // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (292, 273 ); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "CaptureForm"; this.Text = "CaptureForm"; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.Click = new System.EventHandler (this.CaptureForm_Click); this.DoubleClick = new System.EventHandler (this.CaptureForm_DoubleClick);} #endregion [DllImport ( "user32.dll", EntryPoint = "GetDC")] public static extern IntPtr GetDC (INTPTR PTR); [DLLIMPORT ("User32.dll", Charset = charset.auto)] public static extern INTPTR getDesktopWindow ();

private void CaptureForm_DoubleClick (object sender, System.EventArgs e) {Bitmap bm = new Bitmap (this.BackgroundImage); this.img = bm.Clone (this.area, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555); this.DialogResult = DialogResult.ok;}

INDEX = -1; protected override void onMousedown (MouseEventArgs e) {base.onmousedown (e); if (this.area == Rectangle.empty && E.Button == MouseButtons.Reft) {this.area.Location = New Point (EX, EY);} this.op = New Point (ex, EY); this.index = this.getSelectedHandle (New Point (EX, EY)); this.setCursor ();} private int GetSelectedHandle (Point P ) {INDEX = -1; for (int i = 1; i <9; i ) {if (getHandleRect (i) .contains (p)) {index = i; break;}} f (this.area.contains (p)) Index = 0; system.diagnostics.trace.writeline ()); system.diagnostics.trace.writeline ()); system.diagnostics.trace.writeline (Index.toString) (INDEX.TOSTRING ))); Return Index;} protected override void onmousemove (MouseEventargs e) {base.onmousemove (e); if (this.capture) {this.moveHandleto (New Point (EX, EY)); this.invalidate ();} Else {this.index = this.getSelectedHandle (New Point (EX, EY)); this.SetCursor ();}} private vid movehandleto (Point Point) {int = area.tic; int top = area.top; int right = area.right; int bottom = area.bottom

Switch (index) {cas 0: area.x = point.x-op.x; area.y = point.y-op.y; this.op = Point; return; case 1: left = point.x; top = POINT.Y; Break; Case 2: Top = Point.y; Break; Case 3: Right. = Point.x; Top = Point.y; Break; Case 4: Right = Point.x; Break; Case 5: Right = Point.x; Bottom = Point.y; Break; Case 6: Bottom = Point.y; Break; Case 7: Left = point.x; bottom = point.y; break; cas 8: left = point.x; Break;} this.op = point; area.x = left; area.width = right-left; area.height = bottom-top;} private void setcursor ()} pr= cursors.default ; If (index == 1 || index == 5) {cr = Cursors.sizenwse;} else if (index == 2 || index == 6) {cr = cursors.sizens;} else} == 3 || index == 7) {cr = Cursors.SizENESW;} else if (index == 4 || index == 8) {cr = cursors.sizewe;} else if (index == 0) {Cr = Cursors .Sizeall;} curso R.Current = Cr;}

Protected Override Void OnMouseUp (MouseEventArgs E) {Base.OnmouseUp (e); int = area.tic; int = area.top; int = area.right; int bottom = area.bottom; area.x = math. MIN (Left, Right); Area.y = Math.min (Top, Bottom); Area.Width = Math.Abs ​​(Left-Right); Area.Height = Math.Abs ​​(Top-Bottom); if (e. Button == mousebuttons.right) {if (this.area == Rectangle.empty) {this.dialogResult = DialogResult.cancel;} else {this.area = Rectangle.empty; this.invalidate ();}} this.index = this.getSelectedHandle (New Point (EX, EY)); this.setCursor ();} protected override void onpaint (Painteventargs E) {// base.onpaint (e); base.onpaint (e); E.Graphics. DrawRectangle (New Pen (this.ForeColor), this.area); for (int i = 1; i <9; i ) {E.Graphics.FillRectangle (New Solidbrush (Color.red), this.getHandlence (i)) }}} Private rectangle getHandleRect (int index) {Point Point = GetHandle (Index); Return New Rectangle (Point.x - 3, Point.y - 3, 7, 7) } Private point getHandle (int index) {Int x, y, xcenter, ycenter

Xcenter = area.x area.width / 2; ycenter = area.y area.Height / 2; x = area.x; y = area.y;

Switch (index) {casse 1: x = area.x; y = area.y; break; casse 2: x = xcenter; y = area.y; break; casse 3: x = area.right; y = area. Y; Break; Case 4: x = area.right; y = ycenter; break; casse 5: x = area.right; y = area.bottom; break; cas 6: x = xcenter; y = area.bottom; break Case 7: x = area.x; y = area.bottom; break; cas 8: x = area.x; y = ycenter; Break;} return new point (x, y);

} Private void CaptureForm_Click (Object Sender, System.EventArgs E) {}

}

转载请注明原文地址:https://www.9cbs.com/read-49161.html

New Post(0)