关于透明

weiyulin 2008-05-04 10:23:26
我只想让窗体透明 或半透明

其上的控件 不透明 但是 如label控件 能透明

怎么做 就好像QQMusic 的歌词显示窗口一样
...全文
93 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ziyuanxian 2008-11-28
  • 打赏
  • 举报
回复
不错,谢谢!
cbm6666 2008-05-05
  • 打赏
  • 举报
回复
这个代码在网上确实是难得一见的, 关键只是在于SetLayeredWindowAttributes参数的问题,然而一般书本上是不会提到的.

'【CBM666的透明窗体控件不透明】
'SetLayeredWindowAttributes hwnd, transcolor, 120, LWA_COLORKEY Or LWA_ALPHA '窗体透明,控件半透明
'添加Image1 装载背景为蓝色的图片

Option Explicit
'*****************************************透明窗体的API
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cX As Long, ByVal cY As Long, ByVal wFlags As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Const WS_EX_LAYERED = &H80000
Const GWL_EXSTYLE = (-20)
Const LWA_ALPHA = &H2
Const LWA_COLORKEY = &H1
'********************************************************************

Dim rtn&, transcolor&
Private Sub Form_Load()
transcolor = &HFF0000
Me.BorderStyle = 0: Me.Caption = "": Me.BackColor = transcolor
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, transcolor, 255, LWA_COLORKEY Or LWA_ALPHA '将扣去窗口中的蓝色背景
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set Form1 = Nothing
End
End Sub

Private Sub Image1_Click()
Unload Me
End Sub

weiyulin 2008-05-05
  • 打赏
  • 举报
回复
网上我没有找到 我要的只是 窗体透明 但上面的控件不透明

weiyulin 2008-05-05
  • 打赏
  • 举报
回复
谢谢你 cbm666

结贴
daisy8675 2008-05-04
  • 打赏
  • 举报
回复
从来不用qqmusic 抓个图上来
东方之珠 2008-05-04
  • 打赏
  • 举报
回复
窗体透明,网上例子很多啊。

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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