BCB 窗體透明控制元件 (轉)

worldblog發表於2007-12-29
BCB 窗體透明控制元件 (轉)[@more@]本文根據 CandyCat   收藏的 《實現窗體的半透明效果(作者:羅薔)》一文修改而成,供BCB+使用。將即可使用   btw:分類裡面,沒有BCB,只好貼到裡面 //////////////////////////////////////////////////////////////////////////////////////////////// 頭: //--------------------------------------------------------------------------- #ifndef TransparentFormH
#define TransparentFormH
//---------------------------------------------------------------------------
#include
#include
#include
#include
//---------------------------------------------------------------------------
class PACKAGE TTransparentFo: 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
#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);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//5/19/2001 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-996103/,如需轉載,請註明出處,否則將追究法律責任。

相關文章