注册 登录
编程论坛 VFP论坛

API 能实现让VFP的工具栏背景透明吗

easyppt 发布于 2023-03-14 15:56, 866 次点击
想创建一个工具栏toobar类,让背景色透明,能实现吗,谢谢!

谢谢吹版,代码补充,就是类似下面的这段代码创建一个toolbar 工具栏:

Public MYTOOL
MYTOOL = Newobject('toolbar')
MYTOOL.Newobject('ct1','container')
MYTOOL.Newobject('bt1','commandbutton')
MYTOOL.ct1.Width = 200
MYTOOL.ct1.Height = 200
MYTOOL.bt1.Height = 200
MYTOOL.ct1.Visible = .T.
MYTOOL.bt1.Visible = .T.
MYTOOL.BackColor = Rgb(0,128,128)  && 故意调整颜色,为了调试 API 是否可以实现 背景色透明
MYTOOL.Caption = ''
MYTOOL.Show()

测试 文件
只有本站会员才能查看附件,请 登录


[此贴子已经被作者于2023-3-14 17:28编辑过]

6 回复
#2
吹水佬2023-03-14 16:00
要看具体情况
给个简单示例代码测试一下
#3
easyppt2023-03-14 16:51
代码已经在1楼补充!

下面的代码是网上找的,没成功

Declare Integer SetLayeredWindowAttributes In user32.Dll integer,integer,integer,integer
Declare Integer SetWindowLongA  In user32.Dll Long hwnd, Long nIndex, Long dwNewLong
declare SetWindowLong in user32.Dll integer,integer,integer
SetWindowLongA(this.HWnd,-20,786688)
SetWindowLong(this.HWnd,-20,0x80000)
SetLayeredWindowAttributes(this.HWnd,0,0,2)
SetLayeredWindowAttributes(this.HWnd,rgb(255,0,0),10,1)

[此贴子已经被作者于2023-3-14 16:57编辑过]

#4
吹水佬2023-03-14 17:15
this.HWnd 是工具栏窗口句柄
试试增加 GetWindowLong
DECLARE long GetWindowLong IN user32 long,long

在Activate事件
SetWindowLong(this.HWnd, -20, BITOR(GetWindowLong(this.HWnd, -20), 0x80000))

然后需要时再设置透明
LOCAL n透明度
n透明度 = 128    && 0--255
SetLayeredWindowAttributes(this.HWnd, this.BackColor, 0, 1)    && 透明背景颜色值有效,透明度无效。

SetLayeredWindowAttributes(this.HWnd, 0, n透明度, 2)    && 透明背景颜色值无效,透明度有效。

SetLayeredWindowAttributes(this.HWnd, this.BackColor, n透明度, 3)    && 透明背景颜色值有效,透明度有效。
#5
easyppt2023-03-14 17:29
吹版,还是不行,一楼 示例 已上传。
#6
吹水佬2023-03-14 18:02
试了一下,这toolbar是个子窗口,没有效果。
对顶层窗口就有效
#7
easyppt2023-03-14 20:21
好的,那就算了,谢谢吹版。
1