我正在运行一个程序,使用Windows的SetLayeredWindowAttributes函数对标签,字体和图像产生一些ALPHA效果。它在Visual Studio 2013中完美运行,无需管理员权限即可运行。
我从VS2013运行DEBUG和RELEASE模式,我知道ADMIN没有设置,因为我正常调用VS并执行一些“拖放”操作(需要一个NORMAL特权而不是ADMIN)。
但是,如果我在SAME计算机的正常文件夹(C:\ ProgramFiles \ etc)中编译并运行该程序,该功能似乎没有执行 - 所有标签,图像等都会突然出现。
那么,这个函数是否需要ADMIN-PRIVILEDGE?
测试代码是:
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_ALPHA = &H2
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hWnd As Integer, _
ByVal nIndex As Integer) As Integer
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hWnd As Integer, _
ByVal nIndex As Integer, ByVal dwNewLong As Integer) _
As Integer
Private Declare Function SetLayeredWindowAttributes Lib _
"user32" (ByVal hWnd As Integer, ByVal crKey As Integer, _
ByVal bAlpha As Byte, ByVal dwFlags As Integer) As Integer
Public Function TransForm(ByVal fhWnd As Long, ByVal Alpha As Byte) As Boolean
'Set alpha between 0-255
' 0 = Invisible , 128 = 50% transparent , 255 = Opaque
SetWindowLong(fhWnd, GWL_EXSTYLE, WS_EX_LAYERED)
SetLayeredWindowAttributes(fhWnd, 0, Alpha, LWA_ALPHA)
LastAlpha = Alpha
TransForm = True
End Function
------ CODE -----
TransForm(lblBottomLeft.Handle.ToInt32, CByte(i))
TransForm(lblBottomRight.Handle.ToInt32, CByte(i))
For i = 255 To 0 Step -5
TransForm(Me.Handle.ToInt32, CByte(i))
sleep(10)
Next
TransForm(Me.Handle.ToInt32, 0)
感谢您的帮助。
更新 只是标签没有褪色,尽管它们在VS2013中消失。由于标签没有OPACITY属性,很明显它们不会褪色 - 至少在第一时刻。但是使用该API,他们就像表单一样淡出,但仅限于VS2013内。