读书人

怎么实现透明窗口?类似360那个健康精

发布时间: 2013-01-05 15:20:40 作者: rapoo

怎样实现透明窗口?类似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);



[解决办法]
有难度啊
[解决办法]
没试验图片,这样行不

C/C++ code
void __fastcall TForm1::FormCreate(TObject *Sender)
{
BorderStyle = bsNone;
Brush->Style = bsClear;
}


[解决办法]
看考此贴
http://topic.csdn.net/t/20021217/13/1269057.html
[解决办法]
引用:
看考此贴
http://topic.csdn.net/t/20021217/13/1269057.html


To ksrsoft (共产党的天下)
楼上的大牛能不能帮忙把帖子里的delphi代码转为CB的代码?
小弟想转为CB代码自己调试一下,可是不懂delphi,希望大牛帮忙。
[解决办法]
用第一种方法不行吗

void __fastcall TForm1::FormCreate(TObject *Sender)
{
BorderStyle = bsNone;
Brush->Style = bsClear;
}


[解决办法]
第二种改的cb
头文件

#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


cpp文件

#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);
}

读书人网 >C++ Builder

热点推荐