要使窗体透明,加上下面的代码就可以了!Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As LongPrivate Sub Form_Load() 'Me.Move 12000, 0 ', 12000, 9000 Dim sco_Bitmap As Long Me.AutoRedraw = True sco_Bitmap = CreateCompatibleBitmap(Me.hdc, 0, 0) SelectObject Me.hdc, sco_Bitmap Me.Refresh End Sub '================================================================= 只有unload 掉窗体后在改变label的值,然后再load 上窗体,才能正确刷新,不过肯定会整屏闪一次。
superruntimelibrary封装了。你可以到网上搜索。
如果用下面的代码,就不会发生上面说的问题了。 Option Explicit Public Const LWA_ALPHA = &H2 Public Const GWL_EXSTYLE = (-20) Public Const WS_EX_LAYERED = &H80000 Public Const WS_EX_TRANSPARENT As Long = &H20& Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As LongPublic 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 Public Const SWP_NOMOVE = &H2 Public Const SWP_NOSIZE = &H1 Public Const HWND_TOPMOST = -1 Public Function SetMouseIn(ByVal hwnd As Long, Optional TouMing As Long = 200, Optional Top As Boolean = True, Optional cMouse As Boolean = True) As Long Dim Ret As Long Ret = GetWindowLong(hwnd, GWL_EXSTYLE) Ret = Ret Or WS_EX_LAYERED If cMouse Then Ret = Ret Or WS_EX_TRANSPARENT SetWindowLong hwnd, GWL_EXSTYLE, Ret SetLayeredWindowAttributes hwnd, 0, TouMing, LWA_ALPHA If Top Then SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE End Function'Form Code Option ExplicitPrivate Sub Form_Load() SetMouseIn Me.hwnd, 30 End SubPrivate Sub Timer1_Timer() Label1.Caption = Label1.Caption & vbCrLf & "ABCDEK" End Sub
这么久了,没来看看,对不起! 如要完全透明字也清晰就只有楼上说的了。Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As LongPrivate Sub Form_Load() 'Me.Move 12000, 0 ', 12000, 9000 Dim sco_Bitmap As Long Me.AutoRedraw = True sco_Bitmap = CreateCompatibleBitmap(Me.hdc, 0, 0) SelectObject Me.hdc, sco_Bitmap Me.Refresh End Sub
能否发份实例代码给我
[email protected]
谢谢
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As LongPrivate Sub Form_Load()
'Me.Move 12000, 0 ', 12000, 9000
Dim sco_Bitmap As Long
Me.AutoRedraw = True
sco_Bitmap = CreateCompatibleBitmap(Me.hdc, 0, 0)
SelectObject Me.hdc, sco_Bitmap
Me.Refresh
End Sub
'=================================================================
只有unload 掉窗体后在改变label的值,然后再load 上窗体,才能正确刷新,不过肯定会整屏闪一次。
Option Explicit
Public Const LWA_ALPHA = &H2
Public Const GWL_EXSTYLE = (-20)
Public Const WS_EX_LAYERED = &H80000
Public Const WS_EX_TRANSPARENT As Long = &H20&
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As LongPublic 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
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const HWND_TOPMOST = -1
Public Function SetMouseIn(ByVal hwnd As Long, Optional TouMing As Long = 200, Optional Top As Boolean = True, Optional cMouse As Boolean = True) As Long
Dim Ret As Long
Ret = GetWindowLong(hwnd, GWL_EXSTYLE)
Ret = Ret Or WS_EX_LAYERED
If cMouse Then Ret = Ret Or WS_EX_TRANSPARENT
SetWindowLong hwnd, GWL_EXSTYLE, Ret
SetLayeredWindowAttributes hwnd, 0, TouMing, LWA_ALPHA
If Top Then SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Function'Form Code
Option ExplicitPrivate Sub Form_Load()
SetMouseIn Me.hwnd, 30
End SubPrivate Sub Timer1_Timer()
Label1.Caption = Label1.Caption & vbCrLf & "ABCDEK"
End Sub
你的代码是半透明窗体,当把值设置成0就看不清上面的字了,设置255就不透明了,而且设置的值越小在上面显示的label信息就越模糊,看不清阿,能让值设置到0后显示字的状态还不变吗?如果能这样就大功告成了。
如要完全透明字也清晰就只有楼上说的了。Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As LongPrivate Sub Form_Load()
'Me.Move 12000, 0 ', 12000, 9000
Dim sco_Bitmap As Long
Me.AutoRedraw = True
sco_Bitmap = CreateCompatibleBitmap(Me.hdc, 0, 0)
SelectObject Me.hdc, sco_Bitmap
Me.Refresh
End Sub