'窗体透明声明
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_COLORKEY = &H1
你程式里有段代码,请一定要用上面的宣告。 在 Startup() 里呼叫的 If GetDbSetting("TransWindowEffectOn", False) Then SetWindowTrans hWndAccessApp
'==========================================================================================================================
'-函数名称: SetWindowTrans
'-功能描述: 设置窗口透明
'-输入参数: hwnd 窗口句柄
' Color 要设为透明的颜色,Mode参数为1(或其它非0值)时有效
' Alpha 窗口透明度,Mode参数设0时有效
' Mode 透明模式
'-返回参数: 返回true表示函数调用成功,否则调用失败
'-使用示例: SetWindowTrans Me.hwnd
'-相关调用: apiGetWindowLong(), apiSetWindowLong(), apiSetLayeredWindowAttributes()
'-使用注意: 直接对MDI窗口中的非弹出式子窗口使用无效,将hwnd参数设为MDI父窗口的句柄时,效果作用于父窗口及其所有非弹
' 出式子窗口
'-兼 容 性: Windows 2000以上系统
'-参考资料:
'-作 者: 红尘如烟
'-创建日期; 2009-3-10
'==========================================================================================================================
Public Function SetWindowTrans(Hwnd As Long, Optional Color As Long = 0, Optional Alpha As Byte = 230, _
Optional Mode As conWindowTransMode = conTransModeAlpha) As Boolean
On Error GoTo Err_SetWindowTrans
Dim rtn As Long
rtn = GetWindowLong(Hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
Call SetWindowLong(Hwnd, GWL_EXSTYLE, rtn)
If Mode = conTransModeAlpha Then
Mode = LWA_ALPHA
Else
Mode = LWA_COLORKEY
End If
SetWindowTrans = CBool(SetLayeredWindowAttributes(Hwnd, Color, Alpha, Mode))
Exit_SetWindowTrans:
Exit Function
Err_SetWindowTrans:
MsgBox Err.Description, vbCritical, "Error of SetWindowTrans()"
Resume Exit_SetWindowTrans
End Function