--- === Make a transparent window === ---

zhaozj2021-02-08  190

How to make a transparent window

2000-08-01 · - · 仙 时间

I don't know what the transparent window is used, but after all, as a skill, still take it out. The following example demonstrates how to display a transparent window. At the same time, it also introduces how to capture the screen. You must set the Form1's Border attribute to BSNONE C Builder, please refer to Delphi example

Delphi

Unit homepage_coolformation; interfaceuses

Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs

Extctrls, stdctrls, buttons;

TYPE TFORM1 = Class (TFORM)

Procedure FormPaint (Sender: TOBJECT);

Procedure FormShow (Sender: TOBJECT);

Procedure FormDestroy (Sender: TOBJECT);

Private {private declarations}

PUBLIC {public declarations}

HBMP: Integer;

END;

Var Form1: TFORM1;

IMPLEMentation

{$ R * .dfm}

Function CopyScreenTOBITMAP (RECT: TRECT): Integer;

VAR

HSCRDC, HMEMDC, HBitmap, Holdbitmap: Integer

NX, NY, NX2, NY2: Integer;

NWIDTH, NHEIGHT: Integer;

XSCRN, YSCRN: Integer;

Begin

IF (IsRectempty (Rect)) THEN

Begin

Result: = 0;

EXIT;

End; // Get the handle of the screen buffer.

// a Memory DC Compatible to Screen DC

HSCRDC: = Createdc ('Display', Pchar (0), PCHAR (0), PDEviceModea (0));

HMEMDC: = CreateCompatiPLEDC (HSCRDC);

// Get Points of Rectangle to grab

NX: = Rect.Left;

NY: = Rect.top;

NX2: = Rect.right;

NY2: = Rect.bottom;

// Get Screen Resolution

Xscrn: = getDeviceCaps (HSCRDC, Horzres);

YSCRN: = GetDeviceCaps (HSCRDC, Vertres);

// Make Sure Bitmap Rectangle Is Visible

IF (NX <0) THEN

Nx: = "0;"

IF (NY <0) THEN

NY: = "0;"

IF (nx2> xscrn) THEN

NX2: = xscrn;

IF (NY2> YSCRN) THEN

NY2: = YSCRN;

NWIDTH: = NX2 - NX;

NHEIGHT: = NY2 - NY;

// Create a Bitmap Compatible with the screen DC

Hbitmap: = CreateCompATIBLEBITMAP (HSCRDC, NWIDTH, NHEIGHT);

// Select New Bitmap Into Memory DC

Holdbitmap: = SelectObject (HMEMDC, HBitmap); // Bitblt Screen DC to Memory DC

Bitblt (HMEMDC, 0, 0, NWIDTH, NHEIGHT, HSCRDC, NX, NY, SRCCOPY);

// Select Old Bitmap Back Into Memory DC and Get Handle To

// Bitmap of the screen

Hbitmap: = SelectObject (HMEMDC, Holdbitmap);

// Clean Up

Deletedc (HSCRDC);

Deletedc (HMEMDC);

Result: = hbitmap;

END;

Procedure TFORM1.FORMSHOW (Sender: TOBJECT);

VAR

RECT: TRECT;

p: tpoint;

Begin

Rect: = ClientRect;

P: = Clientorigin;

Rect.Left: = p.x;

Rect.top:=p.y;

Rect.bottom: = Rect.bottom P.y;

Rect.right: = Rect.right p.x;

HBMP: = COPYSCREENTOBITMAP (RECT);

inherited;

END;

Procedure TFORM1.FORMPAINT (Sender: TOBJECT);

VAR

Bitmap: tbitmap;

RECT: TRECT;

Begin

Bitmap: = Tbitmap.create;

Bitmap.handle: = HBMP;

Rect: = ClientRect;

Canvas.draw (Rect.Left, Rect.top, Bitmap);

Bitmap.handle: = 0;

Bitmap.free;

END;

Procedure TFORM1.FORMDESTROY (Sender: TOBJECT);

Begin

DeleteObject (HBMP);

END;

End.

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

New Post(0)