怎样实现透明窗口?类似360那个健康精灵那样的程序?
怎样实现透明窗口?类似360那个健康精灵那样的程序?
想做类似于360那个健康精灵的程序,该怎样实现窗口的透明? (bcb开发)
[解决办法]
SetWindowPos(Handle,HWND_TOPMOST,0,0,Screen-> Width,Screen-> Height,SWP_SHOWWINDOW);
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE)
[解决办法]
WS_EX_TRANSPARENT
[解决办法]
//忽略一切消息(WM_PAINT除外)
WS_EX_LAYERED); //层风格,有他才能支持半透明
SetLayeredWindowAttributes(Handle, Color, 100, LWA_ALPHA
[解决办法]
LWA_COLORKEY);
void __fastcall TForm1::FormCreate(TObject *Sender)
{
BorderStyle = bsNone;
Brush->Style = bsClear;
}
#ifndef Unit1H
#define Unit1H
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
class TForm1 : public TForm
{
__published:// IDE-managed Components
TButton *Button1;
TButton *Button2;
TPanel *Panel1;
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
private:// User declarations
void __fastcall DoVisible() ;
void __fastcall DoInvisible();
HRGN FullRgn,ClientRgn,CtlRgn;
// THandle FullRgn, ClientRgn, CtlRgn ;
// THandle CtlRgn ;
public:// User declarations
__fastcall TForm1(TComponent* Owner);
};
extern PACKAGE TForm1 *Form1;
#endif
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Application->Terminate();
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if ( Button1->Caption == "Show Form ")
{
DoVisible();
Button1->Caption = "Hide Form ";
}
else
{
DoInvisible();
Button1->Caption = "Show Form ";
}
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
DoInvisible();
}
void __fastcall TForm1::DoVisible()
{
//To restore complete visibility:
FullRgn = CreateRectRgn(0, 0, Width, Height);
CombineRgn(FullRgn, FullRgn, FullRgn, RGN_COPY);
SetWindowRgn(Handle, FullRgn, TRUE);
}
void __fastcall TForm1::DoInvisible()
{
TControl *AControl;
Integer A, Margin, X, Y, CtlX, CtlY ;
Margin = ( Width - ClientWidth ) / 2;//ksr
FullRgn = CreateRectRgn(0, 0, Width, Height);
X = Margin;
Y = Height - ClientHeight - Margin;
ClientRgn = CreateRectRgn( X, Y, X + ClientWidth, Y + ClientHeight );
CombineRgn( FullRgn, FullRgn, ClientRgn, RGN_DIFF );
for ( A = 0 ;A<= ControlCount - 1;A++ )
{
AControl = Controls[A];
if (( (dynamic_cast <TWinControl*> (AControl)) )
[解决办法]
(dynamic_cast <TGraphicControl*> (AControl)) )
{
if ( AControl->Visible)
{
CtlX = X + AControl->Left;
CtlY = Y + AControl->Top;
CtlRgn = CreateRectRgn( CtlX, CtlY, CtlX + AControl->Width, CtlY + AControl->Height );
CombineRgn( FullRgn, FullRgn, CtlRgn, RGN_OR );
}
}
}
SetWindowRgn(Handle, FullRgn, TRUE);
}
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
DeleteObject(ClientRgn);
DeleteObject(FullRgn);
DeleteObject(CtlRgn);
}