Set of a real-purpose Delphi screen copy

zhaozj2021-02-11  261

A real-purpose DELPHI screen copy design

Jia Xuejie, Jihe Lane, Ningbo City

---- Delphi of Borland Division (now renamed Inprise) is one of the most squares of Windows programming tools. Many people were developed for Delphi as a data library, and the practical Delphi can develop high-efficient Windows program in extremely fast speed.

---- Now we use Delphi to write a real-purpose screen copy program. Hey, the picture of the lower surface is the example after the program is running, it is not wrong!

---- Borland's genius designers encapsulated most of the graphic output features of Windows with Canvas objects, which allows us to deal with him with a more intuitive way and Windows, without having to care about a headache. Windows API function. A small section of the lower surface can be copied with an image of the entire screen.

VAR // variable declaration

Fullscreen: Tbitmap;

Fullscreencanvas: Tcanvas;

DC: HDC;

/ / -------------------------------------------------------------------------------------------- ----------------

DC: = getDC (0); // Take the DC of the screen, parameter 0 refers to the screen

Fullscreencanvas: = tcanvas.create; // Create a Canvas object

Fullscreencanvas.Handle: = DC; // Assign the DC of the screen to Handle

Fullscreen.canvas.copyRect

(RECT (0, 0, Screen.Width, Screen.height),

Fullscreencanvas,

RECT (0, 0, Screen.Width, Screen.Height));

/ / Copy the entire screen to Bitmap

Fullscreencanvas.Free; // Release Canvas object

ReleaseDC (0, DC); // Release DC

// Screen object is a screen object that Delphi pre-defined, and it is used directly.

---- Looked at the code, you will make a simple order of the existing Delphi write screen copy.

---- If you want to write a real-purpose screen copy, light is not enough, let's talk about the main programming:

---- 1. Reality of full screen copy

---- First hidden copy program, extend a schedule, use the above program, you can realize the copy of the screen.

---- 2. Realization of zone copybook

---- To implement the area copy to use a small skill, first call the full screen copy program to copy the entire screen, then display the copying image on the screen, then let the user choose the required area above, Finally, copy the area selected by the user.

---- Programming: ---- 1. First use Delphi3 to open a process.

---- 2. Place a TPANEL component on the Form, set align = altop, select the Tscrollbox on the ADDitional on the partial strip, put it on the Form, set align = alclient, and then place a TIMAGE object on Scrollbox.

---- 3. Place 4 buttons on the Panel, divide Full Screen, Regin, Save, Exit.

---- 4. Easy dry first, write down the code in the Click event of the EXIT button

Procedure TFORM1.EXITCLICK (Sender: TOBJECT);

Begin

CLOSE;

END;

---- 5. Connecting is a full screen copy, put a tetter TTIMER on the FROM, enabled is set to false, but the interval is set to 500, which is half a second. Double-click the Timer part, write the following code.

Procedure TFORM1.TIMER1TIMER (Sender: TOBJECT);

VAR

Fullscreen: Tbitmap;

Fullscreencanvas: Tcanvas;

DC: HDC;

Begin

Timer1.enabled: = false; // cancel the clock

Fullscreen: = tbitmap.create; // Create a Bitmap to store image

Fullscreen.width: = Screen.width;

Fullscreen.height: = screen.height;

DC: = getDC (0); // Take the DC of the screen, parameter 0 refers to the screen

Fullscreencanvas: = tcanvas.create; // Create a Canvas object

Fullscreencanvas.Handle: = DC;

Fullscreen.canvas.copyRect

(RECT (0, 0, Screen.width, Screen.height), Fullscreencanvas,

RECT (0, 0, Screen.Width, Screen.Height));

/ / Copy the entire screen to Bitmap

Fullscreencanvas.Free; // Release Canvas object

ReleaseDC (0, DC); // Release DC

// ******************************

Image1.picture.bitmap: = fullscreen; // Copy the image to the image object

Image1.width: = fullscreen.width;

Image1.height: = fullscreen.height;

Fullscreen.Free; // Release Bitmap

Form1.windowState: = WSNORMAL; // restored window status

Form1.show; // Display window

MessageBeep (1); // beep is called, the report image has been intercepted.

END;

---- 6. The code on the Fullscreen button is very simple.

Procedure TFORM1.FULLSCREENCLICK (Sender: TOBJECT); Begin

Form1.WindowState: = wsminimized; // Minimize program window

Form1.hide; // hide the program

Timer1.enabled: = true; // Open the moving

END;

---- 7. Copy to the image When you want to save it, the Save button has a place with Wu, and we write as follows.

Procedure TFORM1.SAVE1CLICK (Sender: TOBJECT);

Begin

if Savedialog1.execute THEN

Begin

Form1.Image1.picture.savetofile (Savedialog1.FileName)

END;

END;

---- 8. The lower surface is the realization of the zone copy. NEW is set to bsnone, which can be displayed as a full screen. Place a TIMAGE component, Align is set to AlClient, and put a TTIMER component, the program of the Timer part is very like it is, because it must first be implemented It is a copy of the full screen.

Procedure TFORM2.TIMER1TIMER (Sender: TOBJECT);

VAR

Fullscreen: Tbitmap;

Fullscreencanvas: Tcanvas;

DC: HDC;

Begin

Timer1.enabled: = FALSE;

Fullscreen: = Tbitmap.create;

Fullscreen.width: = Screen.width;

Fullscreen.height: = screen.height;

DC: = getdc (0);

Fullscreencanvas: = tcanvas.create;

Fullscreencanvas.Handle: = DC;

Fullscreen.canvas.copyRect (RECT)

(0, 0, Screen.width, Screen.height), Fullscreencanvas,

RECT (0, 0, Screen.Width, Screen.Height));

Fullscreencanvas.Free;

ReleaseDC (0, DC);

Image1.picture.bitmap: = FULLSCREEN

Image1.width: = fullscreen.width;

Image1.height: = fullscreen.height;

Fullscreen.Free;

Form2.windowState: = wsmaximized;

Form2.show;

MessageBeep (1);

FOLDX: = - 1;

Foldy: = - 1;

Image1.canvas.pen.mode: = PMNOT; // The pattern of the pen is reversible

Image1.canvas.pen.color: = CLBLACK; // pen is black

Image1.canvas.brush.style :=bsclear; // blank brush

Flag: = True;

END;

---- 9. The program of two events on the TIMAGE part needs to be written, one is onMousedown, the other is onmousemove.

---- 10. You can look back to see the idea of ​​the area. At this time, the screen that needs to be copied as a copy we have gotten, and it is displayed on the screen. Press the left mouse button is the origin of the area. Since then, move the mouse, will have A rectangle is between the origin and the mouse, which will change with the movement of the mouse, press the left button of the mouse again, and the area included in the rectangle is the image we have to get. ---- 11. It has two responses in MouseDown, see the following.

Procedure TFORM2.IMAGE1MOUSEDOWN

(Sender: TOBJECT; button: TMOUSEBUTTON;

Shift: TshiftState; x, y: integer;

VAR

Width, Height: Integer;

Newbitmap: tbitmap;

Begin

IF (trace = false) THEN / Trace indicates whether the mouse is tracked

Begin // Click the left mouse button for the first time and start tracking the mouse.

Flag: = false;

WITH image1.canvas do

Begin

Moveto (Foldx, 0);

LINETO (FOLDX, Screen.Height);

Moveto (0, Foldy);

LINETO (Screen.Width, Foldy);

END;

X1: = x;

Y1: = Y;

Oldx: = x;

Oldy: = Y;

TRACE: = true;

Image1.canvas.pen.mode: = PMNOT; // The pattern of the pen is reversible

// This will then draw a rectangle in the original, which is equivalent to the erase rectangle.

Image1.canvas.pen.color: = CLBLACK; // pen is black

Image1.canvas.brush.style :=bsclear; // blank brush

end

Else

Begin // Second click, indicating that it has been rectified,

/ / Copy it on the image component in Form1.

x2: = x;

Y2: = Y;

TRACE: = FALSE;

Image1.canvas.Rectangle (X1, Y1, OLDX, OLDY);

Width: = ABS (x2-x1);

HEIGHT: = ABS (Y2-Y1);

Form1.image1.width: = width;

Form1.image1.height: = height;

Newbitmap: = Tbitmap.create;

NEWBITMAP.WIDTH: = Width;

Newbitmap.height: = height;

Newbitmap.canvas.copyRect

(RECT (0, 0, Width, Height), Form2.Image1.canvas,

RECT (x1, y1, x2, y2)); // copy

Form1.Image1.picture.bitmap: = newbitmap; // Put it on the image on the form

Newbitmap.free;

Form2.hide;

Form1.show;

END;

END;

---- 12.MouseMove's processing is the rectangular rectangle and erase rectangles between origins and mouse.

Procedure TFORM2.Image1Mousemove

(Sender: Tobject; Shift: tshiftstate; x,

Y: integer; begin

if trace = TRUE THEN / / Is it tracking the mouse?

Begin // Yes, erase old rectangles and draw new rectangles

WITH image1.canvas do

Begin

Rectangle (X1, Y1, OLDX, OLDY);

Rectangle (X1, Y1, X, Y);

Oldx: = x;

Oldy: = Y;

END;

end

Else if flag = true dam Pictures on the location of the mouse

Begin

WITH image1.canvas do

Begin

Moveto (Foldx, 0); // Wipe old cross

LINETO (FOLDX, Screen.Height);

Moveto (0, Foldy);

LINETO (Screen.Width, Foldy);

Moveto (x, 0); // Draw a new cross

LINETO (X, Screen.height);

Moveto (0, y);

LINETO (Screen.Width, Y);

Foldx: = x;

Foldy: = Y;

END;

END;

END;

---- 13. Ok, let me return to the head to write the code of the Region button.

Procedure TFORM1.REGIONCLICK (Sender: TOBJECT);

Begin

Form1.hide;

Form2.hide;

Form2.timer1.enabled: = true;

END;

---- Well, I finally succeeded, hurry up, copy the bright screen! Delphi is not just a good data library development tool, and it is a good helper that writes Windows program. Let me not ban praise: great Delphi!

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

New Post(0)