BCB form transparent control

zhaozj2021-02-08  225

This article

CandyCat collection of "Programming the form of a translucent effect (Author: Luo Qiang)," a text revisions for BCB Win2000 use.

Use the control to use

BTW: Inside, there is no BCB, have to stick to Delphi

head File:

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

#ifndef TransparentFormh

#define transparentformh

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

#include

#include

#include

#include

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

Class Package TTRANSPARENTFORM: PUBLIC TCOMPONENT

{

Private:

protected:

INT M_NALPHAVALUE;

HWND M_HParentFormHandle;

Void __fastcall setalphavalue (int nalpha);

Void __fastcall updatedisplay ();

PUBLIC:

__fastcall ttransparentform (Tcomponent * Owner);

__publish:

__Property int alphavalue = {read = m_nalphavalue, write = setalphavalue, default = 0};

}

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

#ENDIF

CPP file:

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

#include

#pragma HDRSTOP

#include "transparentform.h"

#pragma package (smart_init)

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

// ValidcTrcheck IS Used To Assure That The Components Created Do Not Have

// ann of Pure Virtual functions.

//

Static Inline Void ValidcTrcheck (TTRANSPARENTFORM *)

{

New TTRANSPARENTFORM (NULL);

}

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

__fastcall TTRANSPARENTFORM :: TTRANSPARENTFORM (Tcomponent * Owner)

: Tcomponent (Owner)

{

ComponentState.Contains (csdesigning))

Return; m_nalphavalue = 255;

m_hparentformhandle = ((TForm *) (OWNER)) -> Handle;

Setwindowlong (M_HParentFormHandle, GWL_EXSTYLE, GETWINDOWLONG (M_HParentFormHandle, GWL_EXSTYLE) | WS_EX_LAYERED);

}

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

Namespace Transparentform

{

Void __fastcall package register ()

{

TcomponentClass Classes [1] = {__ClassID (TTRANSPARENTFORM)}

Registercomponents ("EasySoft", Classes, 0);

}

}

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

Void __fastcall ttransparentform :: setalphavalue (int nalpha)

{

IF (nalpha> = 0 && nalpha <256)

{

m_nalphavalue = nalpha;

Updatedisplay ();

}

}

Void __fastcall ttransparentform :: updatedInsplay ()

{

ComponentState.Contains (csdesigning))

Return;

SetlayeredWindowAttributes (M_HParentFormHandle, 0, M_NALPHAVALUE, 2);

}

//wei@shijun.com

//http://www.shijun.com

// 5/19/2001

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

New Post(0)