本文根据 CandyCat    收藏的 《编程实现窗体的半透明效果(作者:罗蔷)》一文修改而成,供BCB+Win2000使用。将控件安装即可使用 btw:分类里面,没有BCB,只好贴到delphi里面////////////////////////////////////////////////////////////////////////////////////////////////头文件://---------------------------------------------------------------------------#ifndef TransparentFormH
#define TransparentFormH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
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);
__published:
    __property int AlphaValue = {read = m_nAlphaValue, write = SetAlphaValue, default = 0};
};
//---------------------------------------------------------------------------
#endif
////////////////////////////////////////////////////////////////////////////////////////////////cpp文件: //---------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop#include "TransparentForm.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
// 
static inline void ValidCtrCheck(TTransparentForm *)
{
    new TTransparentForm(NULL);
}
//---------------------------------------------------------------------------
__fastcall TTransparentForm::TTransparentForm(TComponent* Owner)
    : TComponent(Owner)
{
    if (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::UpdateDisplay()
{
    if (ComponentState.Contains(csDesigning))
        return;
    SetLayeredWindowAttributes(m_hParentFormHandle, 0, m_nAlphaValue, 2);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////[email protected]
//http://www.shijun.com
//5/19/2001 

解决方案 »

  1.   

    { 几年没用BCB了,程序没测试的,我直接在网页打的,小问题应该可以搞定吧}unit TransparentFormHinterfaceuses
      SysUtils,Controls,Classes,Forms;
       TTransparentForm = class(TComponent)
       private
       protected
         m_nAlphaValue : Integer;
         m_hParentFormHandle : HWND;
         procedure SetAlphaValue(nAlpha : Integer);
         procedure UpdateDisplay;
       public
         procedure TTransparentForm(Owner : TComponent);
         constructor Create(AOwner: TComponent); override;
       published
         property AlphaValue : Integer read m_nAlphaValue write SetAlphaValue;
       end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('Easysoft',[TTransparentForm]);
    end;static inline void ValidCtrCheck(TTransparentForm *)
    {
        new TTransparentForm(NULL);
    }
    //---------------------------------------------------------------------------
    constructor TTransparentForm.Create(AOwner: TComponent);
    begin
      if (ComponentState in csDesigning) then Exit;
      m_nAlphaValue := 255;
      m_hParentFormHandle := TForm(AOwner).Handle;
      SetWindowLong(m_hParentFormHandle, GWL_EXSTYLE, GetWindowLong(m_hParentFormHandle, GWL_EXSTYLE) OR WS_EX_LAYERED);
    end;procedure TTransparentForm.SetAlphaValue(int nAlpha);
    begin
      if (nAlpha >= 0) and (nAlpha < 256) then
      begin
        m_nAlphaValue := nAlpha;
        UpdateDisplay;
      end;
    end;procedure TTransparentForm.UpdateDisplay;
    begin
      if not (ComponentState in csDesigning) then
         SetLayeredWindowAttributes(m_hParentFormHandle, 0, m_nAlphaValue, 2);
    end;end.
      

  2.   

    只是要实现半透明的话,不用那么麻烦的.
    2000下:
    SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(m_hParentFormHandle, GWL_EXSTYLE) OR WS_EX_LAYERED);
    SetLayeredWindowAttributes(Handle, 0, 180, 2); //180是透明程度,从0-255 最后一个参数还是用常量吧 好象是LWA_ALPHA