做一个窗体,用一个API使这个窗体半透明,然后用楼上的方法将相关的提示做数据表中,当光标放在相应的栏位时调用窗体.
使窗体透明的相关代码如下:
Option Compare Database
' AnimateWindow是一个窗口打开和关闭时产生动画效果的新函数,因为是一个新的函数, 所以在 API Viewer中是找不到的,必需自己定义:
' Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
'注释: 具体可以使用的常量及其用法
' Module代码如下
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public Const WS_EX_LAYERED = &H80000
Public Const GWL_EXSTYLE = (-20)
Public Const LWA_ALPHA = &H2 ' Const LWA_ALPHA=&H2 注释:表示把窗体设置成半透明样式
Public Const LWA_COLORKEY = &H1 'Const LWA_COLORKEY=&H1 注释:表示不显示窗体中的透明色
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
'调用方法x = setformcompatible(Me.hwnd, 100)
Public Function setformcompatible(ByVal 窗体句柄 As Long, ByVal 半透明程序0到255 As Long) As Boolean
Dim rtn As Long
rtn = GetWindowLong(窗体句柄, GWL_EXSTYLE) '注释:取的窗口原先的样式
rtn = rtn Or WS_EX_LAYERED '注释:使窗体添加上新的样式WS_EX_LAYERED
SetWindowLong 窗体句柄, GWL_EXSTYLE, rtn '注释:把新的样式赋给窗体
SetLayeredWindowAttributes 窗体句柄, 0, 半透明程序0到255, LWA_ALPHA
setformcompatible = True
'注释: 取值范围0 --255, 为0时就是一个全透明的窗体了
End Function
[此贴子已经被作者于2007-5-22 11:12:54编辑过]
|