vb窗体透明问题!
我让窗体透明了,但是我timer1中的print 在窗体上的文字就不显示了,有什么办法让窗体透明,还能显示print 的文字
追问:来自手机问问这是什么?貌似不能实现我的要求啊
我让窗体透明了,但是我timer1中的print 在窗体上的文字就不显示了,有什么办法让窗体透明,还能显示print 的文字
追问:来自手机问问这是什么?貌似不能实现我的要求啊
答案: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 SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_NCLBUTTONDOWN = &HA1
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
实施部分
Me.BackColor = &HFF0000
Dim rtn As Long
Image1.BorderStyle = 0
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd,&你的颜色号&, 0, LWA_COLORKEY
OK!!!
我的代码是最短的,步骤是最简单的,方法是最傻瓜化的,图片是没有要求的,如果你不说你不是Windows的,没有画图,那只好在用PS一类的工具喽!'>>必要的声明
'{
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
'//hwnd (窗口句柄)
'//nlndex (基于0的的偏移量) : 有效值的范围从0到窗口额外内存空间的字节数,减去4。
Public Const GWL_EXSTYLE = (-20) '//扩展窗口风格
Public Const WS_EX_LAYERED = &H80000 '//微软窗口扩展属性,在API层面实现窗口透明化
'}'{
Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
'//hwnd (窗口句柄)
'//crKey (掩码颜色) : 可以用RGB(r,g,b)来指定
'//bAlpha (不透明度) : 取值范围是[0,255],其中0代表全透明,255代表不透明
'//dwFlags (透明方式)
Public Const LWA_ALPHA = &H2 '//crKey参数无效,bAlpha参数有效
Public Const LWA_COLORKEY = &H1 '//窗体中的所有颜色为crKey的地方将变为透明,bAlpha参数无效
'//[特别说明] 窗体需要加入WS_EX_LAYERED扩展属性
'}'::::
'>>自定函数WindowTransparence来实现窗口透明会更方便
'{
Function WindowTransparence(ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
'//hwnd (窗口句柄)
'//crKey (掩码颜色) : 可以用RGB(r,g,b)来指定
'//bAlpha (不透明度) : 取值范围是[0,255],其中0代表全透明,255代表不透明
'//dwFlags (透明方式)
'//Public Const LWA_ALPHA = &H2 '//crKey参数无效,bAlpha参数有效
'//Public Const LWA_COLORKEY = &H1 '//窗体中的所有颜色为crKey的地方将变为透明,bAlpha参数无效
'//过程
Dim rtn As Long
rtn = GetWindowLong(hwnd, GWL_EXSTYLE) '//获取窗口表现属性
rtn = rtn Or WS_EX_LAYERED '//在原有属性上加入WS_EX_LAYERED扩展属性
SetWindowLong hwnd, GWL_EXSTYLE, rtn '//设置窗口表现属性
SetLayeredWindowAttributes hwnd, crKey, bAlpha, dwFlags '//透明化处理'//返回值
WindowTransparence = &H1
End Function
'}'::::
'//调用函数实现窗体透明
'//Call WindowTransparence(窗口句柄 As Long, 掩码颜色 As Long, 不透明度 As Long, 透明方式 As Long)
'//例如:Call WindowTransparence(me.hwnd, &H0, 220, Const LWA_ALPHA)
'::::
'>>希望能够帮助到你,不懂的地方可以向我提问。我很荣幸为你解答问题。
下面这段代码是用来以特殊字形透明地显示windows运行时间的代码的部分:
'先添加一个timer控件,命名为 timer1
Option Explicit
'以下函数是使窗口显示特殊字形的API函数
Private Declare Function BeginPath Lib "gdi32" _
(ByVal hdc As Long) _
As LongPrivate Declare Function SetBkMode Lib "gdi32" _
(ByVal hdc As Long, _
ByVal nBkMode As Long) _
As LongPrivate Declare Function TextOut Lib "gdi32" Alias "TextOutA" _
(ByVal hdc As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal lpString As String, _
ByVal nCount As Long) _
As LongPrivate Declare Function EndPath Lib "gdi32" _
(ByVal hdc As Long) _
As LongPrivate Declare Function PathToRegion Lib "gdi32" _
(ByVal hdc As Long) _
As LongPrivate Declare Function SetWindowRgn Lib "user32" _
(ByVal hWnd As Long, _
ByVal hRgn As Long, _
ByVal bRedraw As Boolean) _
As LongPrivate Declare Function SelectObject Lib "gdi32" _
(ByVal hdc As Long, _
ByVal hObject As Long) _
As Long
Private Declare Function CreateFont Lib "gdi32" _
Alias "CreateFontA" _
(B