Design of a practical Delphi screen copy program

zhaozj2021-02-08  238

Delphi, a Borland, which is renamed Inprise, is a Windows schedule.

One of the tools. Many people have a practical Delphi for Delphi.

High-efficiency Windows program can be issued at very fast speed.

Now we use Delphi to write a real-purpose screen copy program. Hey, the next picture

It is the example of copying the area screen copy after the program is running, it is still not wrong!

Borland's Day talents set up a large-scale figure of Windows with painting (tcanvas).

Exporting function, this makes us can communicate with him with more straightforward and Windows screen.

Don't care about the headache of Windows API functions. A small section of the next section can be implemented

Image of the screen copy.

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.

When you write a real-purpose screen copy, light is not enough, let's talk about it.

The next main programming:

1. Realt of full screen copy

First hide the copy program, extend a schedule, use the above program to act now

Copy.

2. Realization of zone copybook

To realize the zone to copy, you should use a small skill. First call the full screen copy to copy the entire screen.

Belle, then display the image of the copy of the copy on the screen, then allow the user to be on the top

Select the area you want to, and then copy the user-selected area to the area.

Program:

1. First open a process with Delphi3.

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, then place one on Scrollbox

TIMAGE object.

3. Place 4 buttons on the Panel, part to ful, 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 titter TTImer, enabled on the FROM.

False, INTERVAL is set to 500, which is only half a second. Double click on the Timer part, write as below

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 that is going to the FullScreen button is very simple.

Procedure TFORM1.FULLSCREENCLICK (Sender: TOBJECT);

Begin

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

Form1.hide; // Tibet the program Timer1.enabled: = true; // Open the moving

END;

7. Copy to the image, the Save button has a place, and we write

The next code.

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 a FORM, BorderStype is set to BSNON, which can be displayed enough

For full screen, put a TIMAGE part on the upper surface, Align is set to AlClient, and put a TTIMER in addition

The part of the component, the program of the Timer part is very similar, because it is a full screen copy because of its first.

shell.

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 DITMAP:

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

It is onmousemove.

10. You can look back in the distance of the area to see the area of ​​the area. This time you need to copy the screen of the zone. We have passed.

Get, also displayed on the screen, pressing the left button is the origin of the zone, this post-moving mouse, there will be a rectangular shape between the origin and the mouse, it will change with the mouse to change, then press the mouse again

The left button of the standard, the area included in the rectangle is the image I have to get.

11. All secondary responses are processed, see below.

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 to draw a rectangular shape and rubbed between the origin and the mouse.

In addition to rectification.

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;

Ok, I finally succeeded, hurry to run, copy the bright screen! Look at

Delphi is not just a good data library development tool, and it is an excellent writing of Windows.

The good helper of the program. Let me not ban praise: great Delphi!

Jia Xuejie, Jihe Lane, Ningbo City

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

New Post(0)