Screen skill

xiaoxiao2021-03-06  119

Here is some of the skills of screening, which is the usual programming. Write here and hope to use it for everyone. In fact, its skills are not difficult. Just know a few API functions, plus some device descriptive tables, you can almost make very well gripping software. Less nonsense, now introduce: First, grabbing full screen: This is almost the easiest one in the screen, I believe many people will, but in order to tell the complete, here is listed here. Thought is simple, obtain the device descriptor table of the screen, assign a value to a Canvas handle, then the Canvas is equivalent to the screen's canvas. Then copy this canvas to a bitmap object, the code is as follows: Procedure getDesktopbim (fscreen: tbitmap); var fcanvas: tcanvas; dc: hdc; begin fcanvas: = tcanvas.create (); try fscreen.width: = Screen .width; fscreen.height: = screen.Height; // acquisition screen device descriptive table, 0 finger screen DC: = getdc (0); // Put the screen device description to the handle of the canvas, at which point the canvas represents the whole The screen has fcanvas.handle: = DC; // copy the entire screen to Bitmap, then release the canvas object and device description table, fscreen.canvas.copyRect (RECT (0, 0, Screen.Width, Screen.height ), Fcanvas, Rect (0, Screen.Width, Screen.Height); Finally Fcanvas.Free; ReleaseDC (0, DC); End; End; Second, local gripping: Sometimes do not need to capture the whole The screen, only one of them, how should you do it? Take a closer look at those grip software, when you grab the local screen, you look at your screen, even QQ friends come to the information, the avatar should not move, in fact, it will first grab the entire screen first, Place the true screen to let you operate on this grab. In general, there are several types of screens, which only explain three:

The first is a rectangle. This is of course the easiest, because the entire stationmap is in front of you, you only handle the mouse down, move, bounce the news, the whole process is like we do one The small drawing program draws a rectangle. Finally, copy the bitmap of this area to your grip window. The code is a bit messy, and it is not listed here. It should not be very difficult.

The second case is to draw the elliptical, draw an ellipse on the screen canvas, then copy this ellipse to the grip window. But the problem is how to copy the elliptical picture. In fact, it is still a rectangle, but when copying to the grip window, make some changes below the key code. It is some of the code in my previous program. It is not good to make a general code, so I have to The previous code pulled down, you should be able to understand: {This is the code that implements the chart, first drawing all painted in the grip form is white, white is 0, and use the screen bit chart window. The ellipse is size, draw a black ellipse to the canvas of the grip form, black is 1. Then call the API function bitblt to copy all the ellipse (rectangles) selected in the screen bitmap form to the gripping form, but its replication mode is srcpaint, ie the bitmap of the ellipse frame and the grip form canvas Computation, the bitmap of the elliptical frame is displayed only in the black area, the image of the black area, that is, the image of the elliptical portion is displayed, and the other parts have been dropped, so it is only the elliptical partial view, and the remaining White instead. This is the implementation of ellipse screening.} Form1.scrimage.canvas.pen.color: = CLWHITE; FORM1.Scrimage.canvas.brush.Style :=Bssolid; Form1.Scrimage.canvas.brush.color: = CLWHITE; FORM1. Scrimage.canvas.Rectangle (0, 0, Width, Height); Form1.Scrimage.canvas.pen.color: = CLBLACK; FORM1.SCRIMAGE.CANVAS.BRUSH.COLOR: = CLBLACK; FORM1.SCRIMAGE.cANVAS.ELLIPSE (0 , 0, Width, Image1.canvas.ellipse (ORGPOINT.X, ORGPOINT.Y, X, Y); Bitblt (Form1.Scrimage.canvas.Handle, 0, 0, Width, Height, Image1.canvas.Handle , ORGPOINT.X, ORGPOINT.Y, SRCPAINT;

The third is the screen of any shape, and in fact, the so-called any shape is not really arbitrary. It is a polygon, but it's a lot of things, you look like any one. When your mouse draws a line on the screen bitmap form, a polygon is formed, and then the outer frame of this polygon is calculated, that is, a rectangle with this polygon. Then use the techniques described above to implement a screen of any shape. With the explanation of the above ellipse, I think, I can do it yourself. In fact, because the code is somewhat chaos, it is not good to put it. Wait a minute, I will make a simple code, but it is very interesting to screen example. Please look down. three. Current work window Screen: When you want to capture the current activated window, what do you do, you can press Ctrl PrintScreensySRP. You can grab this port. But we have to implement, how to do it, it is actually very simple, it is the handle of this activity window, and then draw this window according to the device description table of this handle to the window. So what function is to be used to get the current work, mainly to use such an API: getForeGroup (), which returns the handle of the currently working window. Ok, now give the code: Procedure TForm1.GetActiveWndimg (B: Tbitmap); Var C: Tcanvas; H: HDC; R: TRECT; HAND: THANDLE; Begin C: = tcanvas.create; hand: = getForeGroup () ; If Hand = 0 THEN EXIT; H: = getWindowdc (HAND); // Try Try getWindowRect (Hand, R) of this window, and assign it to bitmap object B.Width: = R.right-r.lef; b.height: = r.bottom-r.top; c.handle: = h; b.canvas.copyRect (RECT (0, 0, b.width, b.height), C, RECT (0, 0, B.Width, B.Height); Finally C.free; ReleaseDC (Hand, H); End; End; A few ways of gripping screen, just a pilot Role, although there is no detailed code, I want to think about it, plus a help you should make a very good grip software. -------------------------------------------------- - As a final, I came up with a more interesting grip mode, that is, when your mouse pointer points to a place in the screen, press the set hotkey. You can catch the window indicating that the mouse (this window also includes controls such as buttons, etc.). This is really good, reality is not very difficult. There are two main problems, let an answer here, find the corresponding API, line: First, the hotkey problem, the API used is RegisterhotKey and UnregisterhotKey. Not intended to be explained here, you can see the API help yourself. When the hotkey is pressed, the WM_HOTKEY message will be triggered, and we grasp the window bitmap of the mouse position in this message handler. two. The window of the cursor position, first obtain the position of the cursor with getCursorpos, and then take the window handle of this location with WindowFromPoint. Have a handle, it's really good. The following is the program code:

Unit unit1;

Interface

Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, Buttons, ExtCtrls; Type

TForm1 = class (TForm) ScrollBox1: TScrollBox; Image1: TImage; procedure FormCreate (Sender: TObject); procedure FormClose (Sender: TObject; var Action: TCloseAction); private {Private declarations} public {Public declarations} hotkey: Integer; procedure HotkeyDown (VAR Msg: TMessage); Message WM_HOTKEY; Procedure getActiveWndimg; end;

Var Form1: TFORM1;

IMPLEMentation

{$ R * .dfm}

Procedure TFORM1.GETACTIVEWndimg; Var C: Tcanvas; B: Tbitmap; H: HDC; R: TRECT; HAND: THANDLE; P: TPOINT; begin B: = Tbitmap.create; C: = Tcanvas.create; getCursorpos (P); Hand: = WindowFromPoint (p); if Hand = 0 Then EXIT; H: = getWindowdc (HAND); try getWindower (Hand, R); B.Width: = r.right-r.left; b.Height: = r .Bottom-r.top; c.handle: = h; B.canvas.copyRect (Rect (0, 0, B.Width, B.height), C, RECT (0, 0, B. Width, B.Height )); Image1.picture.bitmap.assign (b); Finally C.Free; B.free; ReleaseDC (Hand, H); end;

Procedure TFORM1.HOTKEYDOWN (VAR MSG: TMESSAGE); Begin if (msg.lparamhi = vk_space) and (msg.lparamlo = mod_control) THEN getActiveWndimg;

Procedure TFORM1.FORMCREATE (Sender: Tobject); Begin Hotkey: = 0; if Not RegisterhotKey (HANDLE, HOTKEY, MOD_CONTROL, VK_SPACE) THOWMESSAGE ('can notreguse ";

Procedure TFORM1.FORMCLOSE (Sender: TpoBject; VAR Action: Tclosection); Begin UnregisterhotKey (Handle, Hotkey);

End.

There is no explanation above, I am sorry, but if I read the above text, I think it is not difficult to understand. Put your cursor on any window, press Ctrl Space, see if you grab this window? If you point the cursor to the control inside the window, press Ctrl Space, at this time It is this control. Is it very interesting? In fact, with a handle, it is really good to do a lot.

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

New Post(0)