C++ Builder 10 制作半透明程序窗口

cxxer 2019-03-24 10:37:34
C++ Builder 10 制作半透明程序窗口

#include <vcl.h>
#pragma hdrstop

#include "UnitEx5.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
long lRt = GetWindowLong(Handle, GWL_EXSTYLE);
lRt = lRt | WS_EX_LAYERED;
SetWindowLong(Handle, GWL_EXSTYLE, lRt);
SetLayeredWindowAttributes(Handle, clBlue, 200, LWA_ALPHA);
}



编译提示:[bcc32 Error] UnitEx5.cpp(22): E2015 Ambiguity between '__stdcall SetLayeredWindowAttributes(HWND__ *,unsigned long,unsigned char,unsigned long)' and 'Vcl::Forms::SetLayeredWindowAttributes'
Full parser context
UnitEx5.cpp(18): parsing: void _fastcall TForm1::FormCreate(System::TObject *)
...全文
301 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ooolinux 2019-03-26
  • 打赏
  • 举报
回复
如果是我,就不用纯API方式,直接用AlphaBlend了。
cxxer 2019-03-25
  • 打赏
  • 举报
回复
引用 3 楼 ooolinux 的回复:
你那函数有两个同名的,一个是全局的WinAPI,一楼已经说了,函数前加::调用全局的。一个是窗体成员函数,用this->来调用应该可以。


#include <vcl.h>
#pragma hdrstop

#include "UnitEx5.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
long lRt = GetWindowLong(Handle, GWL_EXSTYLE);
lRt = lRt | WS_EX_LAYERED;
SetWindowLong(Handle, GWL_EXSTYLE, lRt);
::SetLayeredWindowAttributes(Handle, clBlue, 200, LWA_ALPHA);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TrackBar1Change(TObject *Sender)
{
//this->AlphaBlend = true;
//this->AlphaBlendValue = TrackBar1->Position;
//this->Refresh();
::SetLayeredWindowAttributes(Handle, clBlue, TrackBar1->Position, LWA_ALPHA);
}
//---------------------------------------------------------------------------


运行程序后,点击TrackBar1,窗口会自动最小化到任务栏。
ooolinux 2019-03-25
  • 打赏
  • 举报
回复
你那函数有两个同名的,一个是全局的WinAPI,一楼已经说了,函数前加::调用全局的。一个是窗体成员函数,用this->来调用应该可以。
ooolinux 2019-03-25
  • 打赏
  • 举报
回复
窗体有个AlphaBlend和AlphaBlendValue属性,后者设为0~255之间的一个值来控制透明度就可以了。
taozc 2019-03-24
  • 打赏
  • 举报
回复
::SetLayeredWindowAttributes(Handle, clBlue, 200, LWA_ALPHA);

13,871

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧